Making Decisions - The "IF" Conditional

Sometimes a script needs to take different actions according to user input or what it finds on the network. This can be accomplished with the IF command.

The syntax is IF [tag == value] {command} The command can be any scripting command, and typically is a SEND or a GOTO. The tag must be already defined in a MONITOR, DEFINE, or CONSTANT statement, or it must be one of the predefined tags listed below. For example:


DEFINE PARKBRAKE 1FFF4 [F51]

@CHECKPARKBRAKE
: Get Chassis Mobility Status PGN
SEND EAFF F4 FF 01 FF FF FF FF FF
: Give a little time for a response
WAIT 1
IF [PARKBRAKE == 1] {GOTO STARTTEST}
"Please Set the Park Brake before continuing test.
PAUSE
: Check the park brake status again
GOTO CHECKPARKBRAKE

: This following part of the script won't execute unless the park brake is set
@STARTTEST

There are some special values used. N/D indicates "No Data", while Err indicates an RV-C error value. Note that there are no quotes around them.


DEFINE PARKBRAKE 1FFF4 [F51]
: If we haven't received a park brake signal, send a request
IF [PARKBRAKE == N/D] {SEND EAFF F4 FF 01 FF FF FF FF FF}

Sometimes instead of wanting to check if something is equal, we want the opposite. To check for inequality, we use the "!=" symbol.


DEFINE GENSTATUS 1FFDC [B1]
: request generator status
SEND EAFF DC FF 01 FF FF FF FF FF
: Stop the genset if it isn't already stopped
IF [GENSTATUS != 0] {SEND 1FFDA 00 FF FF FF FF FF FF FF}

You must be careful with floating point values, such as voltages or temperatures. These are calculated to three decimal places, and you must include all three in the comparison.

There are several special tags defined. These are listed in a separate entry.