在我不断追求与一些旧设备交互时,我发现供应商提供的软件将特殊字符设置为:
00 00 00 00 11 13
但是 .NET 的 SerialPort 类将它们设置为:
1A 00 00 1A 11 13
我想我有两个问题:
- 这些字节是什么意思?
- 如何告诉 SerialPort 使用一组特定的特殊字符?
我真正关心的是后者,但我怀疑了解前者会很有用。
更新:以下内容不起作用:
byte[] specialchars = {
0x00,
0x00,
0x00,
0x00,
0x11,
0x13
};
this.port.NewLine = System.Text.Encoding.ASCII.GetString(specialchars);
更新 2:根据要求,以下是 供应商提供的应用(经过过滤以删除数千个 IOCTL_SERIAL_GET_COMMSTATUS 条目)和 我尝试匹配第一次交换。
In my ongoing quest to interface with some legacy equipment, I've discovered that the vendor supplied software sets the special characters to:
00 00 00 00 11 13
But the SerialPort class of .NET set them to:
1A 00 00 1A 11 13
I suppose that I have two questions:
- What do these bytes mean?
- How can I tell SerialPort to use a specific set of special characters?
The latter is all I really care about, but I suspect the former is going to be useful to know.
Update: The following doesn't work:
byte[] specialchars = {
0x00,
0x00,
0x00,
0x00,
0x11,
0x13
};
this.port.NewLine = System.Text.Encoding.ASCII.GetString(specialchars);
Update 2: As requested, here are Portmon logs for the vendor supplied app (filtered to remove the many thousands of IOCTL_SERIAL_GET_COMMSTATUS entries) and for my attempt to match even the first exchange.
发布评论
评论(2)
NewLine
不是您正在寻找的内容。这是普通的旧“换行”序列,例如 CR LF 或单独的 LF。特殊字符的处理方式如下:
SerialPort.ParityReplace
研究 Win32 DCB 可能会对您有所帮助结构也是如此。 .NET 在内部使用它来设置串行端口的状态。
NewLine
is not what you are looking for. It's the plain old 'new line' sequence, e.g. CR LF or LF alone.The special characters are handled like this:
SerialPort.ParityReplace
It may be helpful for you to study the Win32 DCB structure as well. It's used by .NET internally to set the state of the serial port.
您可以在 c# 中向串行端口添加扩展:
http://social.msdn.microsoft.com/Forums/vstudio/en-us/89b88e89-5814-4819-8b50-7caa3faf5f54/xonxoff- value-in-net20-serialport-class?forum=csharpgeneral
对于您可以更改的其他字段:
代码:
You can add an extenstion to the serialPort in c# :
http://social.msdn.microsoft.com/Forums/vstudio/en-us/89b88e89-5814-4819-8b50-7caa3faf5f54/xonxoff-values-in-net20-serialport-class?forum=csharpgeneral
for the other fields you can change :
Code :