Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Michael Burr's description of the way break works is accurate. Often, "break" signals are sent for significantly longer than one character time.</p> <p>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.</p> <p>To send a break, typically you call <a href="http://msdn.microsoft.com/en-us/library/aa363433%28VS.85%29.aspx" rel="noreferrer">SetCommBreak</a>, wait an appropriate period (say, around 2 millseconds at 9600 baud) then call <a href="http://msdn.microsoft.com/en-us/library/aa363179%28VS.85%29.aspx" rel="noreferrer">ClearCommBreak</a>. During this time you can't be sending anything else, of course. </p> <p>So, assuming that the protocol requires 'break' at the start of the packet, I'd do this (sorry for pseudocode):-</p> <pre><code>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) } </code></pre> <p>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. <a href="http://msdn.microsoft.com/en-us/library/aa363479%28VS.85%29.aspx" rel="noreferrer">WaitCommEvent</a> is probably the key to handling incoming Breaks.</p> <pre><code>bool ReadCharOrBreak(char *ch); // return TRUE if break, FALSE if ch contains received char </code></pre> <p>We'll also assume fixed-length 100 byte packets with "break" sent before each packet.</p> <pre><code>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 &lt; 100) { buff[count++] = ch; if (count == 100) ProcessPacket(buff); } else Error("too many bytes rx'd without break") } } </code></pre> <p>WARNING - totally untested, but should give you the idea...</p> <p>For an example of a protocol using Break, check out the <a href="http://en.wikipedia.org/wiki/DMX512-A" rel="noreferrer">DMX-512 stage lighting protocol</a>.</p> <blockquote> <p>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.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload