|
Checking for Sequences With Random Characters (Receive Sequence Wildcards) |
|
|
Many serial devices support a set of commands to transmit measurement data and other related information. In common text-based protocols the response from the serial device consists of a fixed part (e.g. "temperature="), and a variable part, which is the actual value (e.g "65F"). To detect all these responses correctly in the serial data stream, you can define Receive Sequences containing wildcards.
Take, for example, the following situation: A serial device measures the temperature and periodically sends the actual reading. Docklight shows the following output: 10/30/2008 10:20:08.022 [RX] - temperature=82F<CR> 10/30/2008 10:22:10.558 [RX] - temperature=85F<CR> 10/30/2008 10:24:12.087 [RX] - temperature=93F<CR> 10/30/2008 10:26:14.891 [RX] - temperature=102F<CR> ...
Defining an individual Receive Sequence for every temperature value possible would not be a practical option. Instead you would define one Receive Sequence using wildcards. For example: t | e | m | p | e | r | a | t | u | r | e | = | ? | # | # | F | r ("r" is the terminating <CR> Carriage Return character)
This ReceiveSequence would trigger on any of the temperature strings listed above. It allows a 1-3 digit value for the temperature (i.e. from "0" to "999"). The following step-by-step example describes how to define the above sequence. See also the additional remarks at the end of this section for some extra information on '#' wildcards.
Preconditions
Using Receive Sequences with wildcards
A) Preparing the project Create a new Docklight project and set up all communication parameters.
B) Defining the Receive Sequences used
t | e | m | p | e | r | a | t | u | r | e | =
t | e | m | p | e | r | a | t | u | r | e | = | ? | # | #
t | e | m | p | e | r | a | t | u | r | e | = | ? | # | # | F | r
NOTE: To distinguish the wildcards '?' and '#' from the regular question mark or number sign characters (decimal code 63 / 35), the wildcards are shown on a different background color within the sequence editor.
C) Running the test Start Docklight by choosing Run >
Docklight will now detect any temperature reading and perform the specified action.
NOTE: The DL_OnReceive() event procedure allows further evaluation and processing of the actual measurement data received.
Additional notes on '#' wildcards
1. The '#' wildcard enables the user to check for variable-length sequences. However, an algorithm checking for any possible matching character combination would need to perform an increasing number of sequence comparisons with every additional "#" wildcard. This becomes obvious if you replace the '#'-based sequence by an equivalent set of sequences that only contain '?' wildcards (matches exactly one character). A check for "Hello#World#!" could be replaced by a check for "HelloWorld!" plus "Hello?World!" plus "HelloWorld?!" plus "Hello?World?!"
As can be seen, every "#" wildcard doubles the number of comparison operations required. Therefore, Docklight performs a simplified '#' check. The Receive Sequence "Hello#World!" will work for "HelloWorld!" or "HelloXWorld!", but will not trigger on "HelloWWorld!". The reason for this is that since the first 'W' is considered a part of "World", Docklight forwards its internal search cursor by one. The next character expected is an 'o', but the data stream says 'W' again, so the comparison algorithm stops here.
Keep this limitation in mind when defining Receive Sequences with '#' wildcards. If you need a Receive Sequence that triggers on "HelloWWorld!" as well, define an additional Receive Sequence using the '?' wildcard character: "Hello?World!"
2. '#' wildcards immediately before a '?' wildcard have no effect. The search cursor will always be forwarded to the '?' wildcard, since the '?' matches any arbitrary character. The receive sequence "Hello##?World" will behave like the receive sequence "Hello?World"
3. '#' wildcards at the beginning or at the end of an receive sequence have no effect. The receive sequence "###HelloWorld###" will behave like the receive sequence "HelloWorld".
|