You are here: Information > Creating Custom Frame Recognizer

Creating Custom Frame Recognizer

The recognizer returns are 32-bit bit masks that represent which events to add and when and where to add them. We've created enumerations representing the most common returns we think will be needed, but you may need to create your own if an existing enumeration does not meet your needs. (Existing enumerations are listed in the chapter on writing Frame Recognizers.)

We've created some basic enumerations/macros so you don't need to know the exact format of the bit mask. This way if the format ever changes, your recognizer will still work.

To add framing events, use one or more of the following recognizer result enumerations:

ThisSideBefore(Recognizer Event)

ThisSideAfter(Recognizer Event)

OtherSide(Recognizer Event)

Possible Recognizer Events are:

StartOfFrame

EndOfFrame

BrokenFrame

You can specify more than one recognizer event per recognizer result by using the OR operator, with one exception. You cannot use both a BrokenFrame and EndOfFrame in the same recognizer return. A broken frame event means the frame didn't end when the recognizer expected it to. The broken frame is inserted to let the end-user know that something went wrong and end the current frame so the recognizer can start over with trying to find the beginning of the next frame.

For example, to insert a start of frame event before the current byte (the equivalent of the eInsertSofBefore enumeration), you would use the syntax:

iOutput = (eRecognizerResult)(ThisSideBefore(StartOfFrame));

To frame a single byte as one frame, you would use:

iOutput = (eRecognizerResult)(ThisSideBefore(StartOfFrame)|ThisSideAfter(EndOfFrame));

To end the current frame and begin a new one on the same side (the equivalent of eNewFrameEndThisSide), you would use:

iOutput = (eRecognizerResult)(ThisSideBefore(StartOfFrame|EndOfFrame));

How does the recognizer know that the end of frame event needs to be inserted in the buffer before the start of frame event? The recognizer events are added to the capture buffer in the following order:

ThisSideBefore

BrokenFrame OR EndOfFrame (these are mutually exclusive)

StartOfFrame

Data Event

ThisSideAfter

BrokenFrame OR EndOfFrame

StartOfFrame

OtherSide

BrokenFrame OR EndOfFrame

StartOfFrame