132
IN_8. It is important to note that
*MV
will only convert real numbers in a numeric format that it understands e.g. 1.234,
12E-2, -1000.7 etc. It cannot cope with non numbers and will just give an error. As with the
*PV
command above, the
error causes the
*MV
command to ignore the data and not update the display. Once again the
*VD
command can be used
to have the error reported for debug purposes.
In our previous example program, the value from the voltmeter was written directly to the screen and was not connected
to cyclic data. The following example sets up a mapped variable and a bar graph and then puts the data received from
the voltmeter into this mapped variable. The displayed value and bargraph are automatically updated each time new
data is received, without having to redraw the screen in any way.
*BB
NS
F2
CM2,0
DV1,6,1,0,1
CM3,0
DB1,120,0,0,0
DL1,0,100
*PS1,9
*PE1,gotit
*PD1,1,2
*PD1,9,3
*PC1,1
*BI
*LAgotit
*BB
*PV1,3,6
*MV1
*BI
The
DV
command sets up the variable IN_1 on the screen with a field width of 6 and 1 decimal place and the
DB
command defines a bar below the variable (This is far from pretty but it demonstrates the basic steps!). Finally the
DL
command defines the upper and lower limits of the bargraph to be 0 and 100.
Some data streams include flags that set the position of the decimal point or indicate the sign of the measured value so it
may be necessary to add ASCII characters to the store before it is processed with the
*MV
command. The
*AVstring
Add Variable command does exactly this.
*AV
combined with
*PV
allows the store to be set as needed. E.g.
*IV
*AV-
*PV1,3,6
*MV1
The above code initialises the store, loads a minus sign into it and then adds the value from the matched data before
sending it to cyclic data IN_1. This it makes it appear as negative number. Note that any number of
*AV
commands can
be used before or after each
*PV
command.
In order to decide if the value is positive or negative we need to be able to make a decision and influence the flow of the
script. For our voltmeter example we need to determine if the MSB of the control byte set or not. If it is we need to add
the minus sign before adding the variable with the
*PV
command.
Decision Making Commands
The
*PJ
n
,
m
,
p
,
q
,
label
Pattern Jump command allows the user to do this decision making. As before
n
is the
pattern number,
m
is the byte in the matched stream to be examined,
p
is a mask value, which is ANDed to the data
before the test is made, allowing bits that are not important to be hidden during the test, and
q
is the value to be
expected. If the conditions of the test are true, then script flow is redirected to the label. If the test fails, the script carries
on from the next line.
This sounds complicated but an example will demonstrate how straightforward the process is. In our voltmeter example,
the control byte consists of two parts. The lower three bits indicate the units and the MSB indicates the sign. If we
wanted to just look at the sign bit, ignoring the 3 unit bytes, we would set the mask to 0x80 (or 128 in decimal).