如何设置串口特殊字符?串口、如何设置、特殊字符

2023-09-04 11:53:59 作者:我的小狼狗

在我的不断探索一些传统设备的接口,我发现供应商提供的软件,设置了特殊字符:

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 

但SerialPort类的.NET将它们设置为:

But the SerialPort class of .NET set them to:

1A 00 00 1A 11 13 

我想,我有两个问题:

I suppose that I have two questions:

在做这些字节是什么意思? 如何判断的SerialPort使用一组特定的特殊字符?

后者是我真正关心的,但我怀疑前者将是需要了解的。

The latter is all I really care about, but I suspect the former is going to be useful to know.

更新:下面不工作:

byte[] specialchars = {
    0x00,
    0x00,
    0x00,
    0x00,
    0x11,
    0x13
};

this.port.NewLine = System.Text.Encoding.ASCII.GetString(specialchars);

更新2:按照要求,这里有Portmon日志的供应商提供的应用程序的(过滤以除去成千上万IOCTL_SERIAL_GET_COMMSTATUS条目)和我尝试以匹配甚至第一交换机。

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.

推荐答案

换行是不是你所期待的。这是普通的老新线的序列,例如CR LF或LF孤单。

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:

EOF - 设置为0x1A的,你不能在.NET更改 ERR - 由 SerialPort.ParityReplace BRK - 的不知道的 在EVT - 设置为0x1A的,你不能在.NET更改 XON - 设置为0x11,你不能在.NET中改变它,它甚至没有通常把SESN 在XOFF - 设置为0x13,你不能在.NET中改变它,它甚至没有通常把SESN EOF — set to 0x1a, you cannot change it in .NET ERR — set by SerialPort.ParityReplace BRK — don't know EVT — set to 0x1a, you cannot change it in .NET XON — set to 0x11, you cannot change it in .NET, and it doesn't even usually make sesn XOFF — set to 0x13, you cannot change it in .NET, and it doesn't even usually make sesn

这可能有助于你学习的 Win32的DCB结构的为好。它使用.NET内部设置串行端口的状态。

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.