如何设置串口特殊字符

如何设置串口特殊字符

本文介绍了如何设置串口特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

  1. 在做这些字节是什么意思?
  2. 如何判断的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 - 由 <$ C $设置C> 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

这可能有助于你学习的的为好。它使用.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.

这篇关于如何设置串口特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:51