Checking for Sequences With Random Characters (Receive Sequence Wildcards)

Top  Previous  Next

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

 

Docklight is ready to run a test as described in the previous use cases, e.g. testing a serial device or a protocol implementation.
The serial device (the temperature device in our example) is operating.

 

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

1.Create a new Receive Sequence. Enter a Name for the sequence.
2.Enter the fixed part of your expected answer in the Sequence section. For our example you would enter the following sequence in ASCII mode:

t | e | m | p | e | r | a | t | u | r | e | =

3.Open the popup / context menu using the right mouse button, and choose Wildcard '?' (matches one character) to insert the first wildcard at the cursor position. Add two '#' wildcards using the popup menu Wildcard '#' (matches zero or one character). The sequence now looks like this:

t | e | m | p | e | r | a | t | u | r | e | = | ? | # | #

4.Enter the fixed tail of our temperature string, which is a letter 'F' and the terminating <CR> character. You can use the default control character shortcut Ctrl+Enter to enter the <CR> / ASCII code 13. The sequence is now:

t | e | m | p | e | r | a | t | u | r | e | = | ? | # | # | F | r

5.Specify an Action to perform after a temperature reading has been detected.
6.Click OK to add the new sequence to the Receive Sequence list.

 

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 > play Start Communication.

 

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".