RS 232中断信号 [英] RS 232 Break Signal

查看:229
本文介绍了RS 232中断信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RS232信号捕获设备.而且效果很好.

I got a RS232 signal capture device. and it working great.

我需要一些有助于理解数据的帮助.基本上,我们购买它是因为我们要处理的是80年代后期使用串行通信的机器控制器.尽管知道端口参数,但运气并不好.

I need some help making sense of the data. Basically we bought it because we are dealing a late 80's machine controller that uses serial communication. We had little luck despite knowing the port parameters.

从我转储的机器控制数据中,使用中断信号作为其协议的一部分.我在使用VB和MSComm复制它时遇到了麻烦.我知道切换中断信号并打开和关闭.但是我不确定我应该怎么做.我应该将其保留在发送的每个字节数据上.或发送一个字节的数据然后切换.

From the data I dumped machine control is using the break signal as part of it's protocol. I am having trouble duplicating it using VB and the MSComm. I know to toggle the break signal and on and off. But I am not sure what I am supposed to be doing with it. I am supposed to leave it on for each byte of data I send. Or send a byte of data and then toggle.

我也很困惑应该如何从控制器接收任何数据.我在中断打开时是否切换标志,然后在中断关闭时读取输入?

Also I am confused how I supposed to receive any data from the controller. Do I toggle a flag when the break is turned on and then when it turned off read the input?

推荐答案

Michael Burr对中断工作方式的描述是准确的.通常,中断"信号的发送时间明显长于一个字符时间.

Michael Burr's description of the way break works is accurate. Often, "break" signals are sent for significantly longer than one character time.

这些天,中断"在串行通信中很少使用,但是最常见的用法是作为提供数据包同步的廉价"方式.可能在数据包开始之前发送中断",以警告接收者新的数据包即将到来(并允许其重置缓冲区等)或在数据包的末尾发出信号,表示不再需要更多数据.这是一种元字符",它使您可以保留数据包内容的整个8位或7位值范围,而不必担心如何描述数据包的开始或结束.

These days, "Break" is infrequently used in serial comms, but the most common use is as a 'cheap' way of providing packet synchronization. "Break" may be sent before a packet starts, to alert the receiver that a new packet is on the way (and allow it to reset buffers, etc.) or at the end of a packet, to signal that no more data is expected. It's a kind of 'meta-character' in that it allows you to keep the full range of 8 or 7-bit values for packet contents, and not worry about how start or end of packet are delineated.

要发送中断,通常请致电 SetCommBreak ,等待适当的时间段(例如,在9600波特时约为2毫秒),然后调用

To send a break, typically you call SetCommBreak, wait an appropriate period (say, around 2 millseconds at 9600 baud) then call ClearCommBreak. During this time you can't be sending anything else, of course.

因此,假设协议要求在数据包的开始处设置中断",我会这样做(对不起,伪代码):-

So, assuming that the protocol requires 'break' at the start of the packet, I'd do this (sorry for pseudocode):-

procedure SendPacket(CommPort port, Packet packet)
{
    SetCommBreak(port)
    Sleep(2);  // 2 milliseconds - assuming 9600 baud. Pro-rata for others
    ClearCommBreak(port)

    foreach(char in packet)
        SendChar(port, char)
}

接收器的伪代码更加困难,因为您必须对传入的数据包格式和用于接收中断的API调用进行大量假设.这次我将用C编写,并假设存在一个虚函数. WaitCommEvent 可能是处理传入中断的关键

Pseudocode for a receiver is more difficult, because you have to make a load of assumptions about the incoming packet format and the API calls used to receive breaks. I'll write in C this time, and assume the existence of an imaginary function. WaitCommEvent is probably the key to handling incoming Breaks.

bool ReadCharOrBreak(char *ch); // return TRUE if break, FALSE if ch contains received char

我们还将假设定长的100字节数据包在每个数据包之前发送"break".

We'll also assume fixed-length 100 byte packets with "break" sent before each packet.

void ReadAndProcessPackets()
{
  char buff[100];
  int count;

  count = 0;

while (true)
{
  char ch;
  if (ReadcharOrBreak(ch))
    count = 0; // start of packet - reset count
  else 
  {
     if (count < 100)
     {
       buff[count++] = ch;
       if (count == 100)
         ProcessPacket(buff);
     }
     else 
       Error("too many bytes rx'd without break")
  } 
} 

警告-完全未经测试,但应该可以告诉您...

WARNING - totally untested, but should give you the idea...

有关使用Break协议的示例,请查看 DMX-512舞台照明协议.

For an example of a protocol using Break, check out the DMX-512 stage lighting protocol.

数据包的开始由 中断后跟一个标记"(a 逻辑一)称为标记后 中断"(MAB).中断信号表示 一个数据包,然后开始下一个数据包. 导致接收器启动 接待.分手后最多513 插槽已发送.

The start of a packet is signified by a Break followed by a "mark" (a logical one) known as the "Mark After Break" (MAB). The break signals end of one packet and the start of the next. It causes the receivers to start reception. After the break up to 513 slots are sent.

这篇关于RS 232中断信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆