You are here: Elements > Frame Recognizers > The Simplest Recognizer: Half Duplex

The Simplest Recognizer: Half Duplex

Here is a recognizer that is about as simple as can be. It serves for a half-duplex protocol on which frames alternate from one end and then the other. In other words, as the embedded comment indicates, the recognizer assumes that a frame ends and another begins when the direction of traffic changes. (This code is in the file DecoderScript Method Samples.mth file located in My Methods\Source. There are additional examples of simple frame recognizers in this file that demonstrate recognizers based on characters, control signals, simple timing and parity errors.)

RECOGNIZER __HalfDuplex__

// The HalfDuplex frame recognizer. This method assumes frame is // everything in a stream until a byte comes in from

// another stream.

int m_iCurrentStream;

@RESET

m_iCurrentStream = -1;

@EACH_BYTE

// If the last byte we looked at was in the same stream

// as this one.

if (m_iCurrentStream == iStream)

{

// Remain in the same stream

return eContinue;

}

else

{

//Switching streams

m_iCurrentStream = iStream;

// Start a new frame and end the previous

return eNewFrameEndOtherSide;

}

@END_RECOGNIZER

This recognizer has no parameters, and pays no attention to signal changes or even byte values; everything is keyed off iStream. Note that iStream will contain either 0 or 1 so it works to initialize m_iCurrentStream to ‐1.