129
Pattern Matching
A table is presented at the end of this section (page 136) showing the syntax of each command. The following text
should be read and understood before attempting to use any pattern matching within scripts.
Overview
Data from small weighing systems, barcode readers and other simple instruments are often output as a printable ASCII
string. Commonly it takes a very simple form of a value, followed by the units, then a carriage return/line feed sequence
e.g. 12.56g[cr][lf]. This type of output is often designed to be fed straight to a printer or remote proprietary equipment.
However, some systems make the data more secure by adding a known start byte and a terminator round the ASCII data
e.g. [stx]12.34kg[etx].
As there is always a need for local indication of process variables, a sub-set of the scripting commands have been
incorporated to allow a user to capture data of this nature and display the resultant value on the text display screen either
directly or using mapped variables and bar graphs.
Pattern matching falls into two distinct parts. Firstly the data has to be captured, and secondly it has to be processed into
an appropriate form. In order to explain both capture and processing we will make use of a simple data format from a
voltmeter which is:-
[STX], control (1 byte), value(6 bytes including the decimal point), [ETX]
Control 0x00 = No Units
0x01 = kilo Volts
0x02 = Volts
0x04 = millivolts
if the control byte has 0x80 added to it the number is negative
Thus
[STX][0x04]55.678[ETX] will represent 55.678mV
[STX][0x01]55.678[ETX] will represent 55.678kV
[STX][0x82]55.678[ETX] will represent -55.678V
Pattern Capture
In order to capture data it has to have a defined structure. The structure is often fixed by the manufacturer but can be
configured in some cases. In our example above, the pattern is 9 bytes in length including the two fixed framing bytes,
one at the start and one at the end. The 7 bytes in the middle can change depending on the range and value measured by
the system.
The BEKA display can be set up to handle 4 separate patterns at the same time or to use one pattern to control and
redefine other patterns. For the purpose of this document we will only work with one pattern.
Although the pattern definition commands may be used in any order an error will result if you try to enable a pattern
before having set up the key matching elements.
The
*PS
n
,
m
Pattern Size command defines the length of the data to be captured. .
n
is the pattern number which must
be in the range of 1 to 4, and
m
is the length which must be in the range of 1 to 32. Thus in the case of the pattern above
*PS1,9
would define the size of pattern 1 to be 9 bytes.
Once the size of the pattern has been defined we need to tell the Script engine to jump to a decoding routine when it
gets a match. This is done using Events which work in the same way as the keypress event described in the scripting
section. The
*PE
n
,
label
Pattern Event command is used for this purpose, which causes the script to execute
commands starting at label
label
. In just two simple commands we have configured the display to capture 9 bytes of
data and go and process it.
In order to start the whole capture process off, the system has to be enabled by using the
*PC
n
,
m
Pattern Control
command where
n
is the pattern number,
m
= 1 enables pattern matching and m=0 disables matching. Note that
n
may
take the value of 0 which will control all 4 patterns simultaneously.