Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C将ENQ、id、CR和LF发送到串行端口#_C#_Serial Port_Usb_Converter - Fatal编程技术网

C# 使用C将ENQ、id、CR和LF发送到串行端口#

C# 使用C将ENQ、id、CR和LF发送到串行端口#,c#,serial-port,usb,converter,C#,Serial Port,Usb,Converter,在我的应用程序中有USB/RS-485转换器。 在此转换器上连接id为30的设备。 制造商已通知我们需要以二进制代码访问设备。 如何使用C#将ENQ id CR和LF发送到此设备 先谢谢你, ocaccy使用()和5,30,13,10的字节数组 byte[] buf = new byte[] { 5, 30, 13, 10 }; sp.Write(buf, 0, buf.Length); 将()与字节数组5,30,13,10一起使用 byte[] buf = n

在我的应用程序中有USB/RS-485转换器。 在此转换器上连接id为30的设备。 制造商已通知我们需要以二进制代码访问设备。 如何使用C#将ENQ id CR和LF发送到此设备

先谢谢你, ocaccy

使用()和5,30,13,10的字节数组

byte[] buf = new byte[] {
    5,
    30,
    13,
    10
};
sp.Write(buf, 0, buf.Length);
将()与字节数组5,30,13,10一起使用

byte[] buf = new byte[] {
    5,
    30,
    13,
    10
};
sp.Write(buf, 0, buf.Length);

这些是ASCII码,默认的串行端口。编码是ASCIIEncoding。因此,如果您希望以这种方式发送字符串而不是字节,则不存在问题:

  port.Write(string.Format("\u0005{0}\r\n", id));

假设
id
也被编码为ASCII码,问题就不清楚了。

这些都是ASCII码,默认的串行端口。编码是AScienceODing。因此,如果您希望以这种方式发送字符串而不是字节,则不存在问题:

  port.Write(string.Format("\u0005{0}\r\n", id));
假设
id
也被编码为ASCII码,这个问题并不清楚。

谢谢。。 对我来说,没有身份证是完美的

_serialPort.Write("\u0005\r\n");
谢谢。。 对我来说,没有身份证是完美的

_serialPort.Write("\u0005\r\n");

谢谢你,汉斯。设备ID为30。port.Write(string.Format(“\u0005{0},30,\r\n”)\\这样可以吗?\\0x30?这就是id=0。你完全破坏了Format()调用。向您的主管询问一些基本的培训资源。设备似乎通过命令获得了一些信息:port.Write(string.Format(“\u0005{0}\r\n”,30));谢谢你,谢谢你,汉斯。设备ID为30。port.Write(string.Format(“\u0005{0},30,\r\n”)\\这样可以吗?\\0x30?这就是id=0。你完全破坏了Format()调用。向您的主管询问一些基本的培训资源。设备似乎通过命令获得了一些信息:port.Write(string.Format(“\u0005{0}\r\n”,30));谢谢,谢谢,我很快会把结果贴在这里,谢谢。我使用下面的Hans代码,因为这对我很有用。我感谢你的帮助。port.Write(string.Format(“\u0005{0}\r\n”,30));谢谢你,我很快会把结果贴在这里。谢谢你。我使用下面的Hans代码,因为这对我很有用。我感谢你的帮助。port.Write(string.Format(“\u0005{0}\r\n”,30));