Skip to content

Set ​

Purpose: create or change a variable.

Set settings

Fill in the variable name, the operator and the value, in that order. The Quick buttons fill in = 0, += 1 or -= 1. The variables known so far are listed below.

JSON ​

json
{ "set": { "var": "a", "value": 10 } }
{ "set": { "var": "a", "op": "+=", "value": 5 } }
{ "set": { "var": "f", "value": "${a} / 4.0" } }
FieldRequiredMeaning
varYesVariable name
valueYesValue or expression
opNo= (default), +=, -=, *=, /=, %=

Number rules ​

  • Integer with integer gives an integer, and division drops the fraction: 24 / 5 = 4.
  • If either side has a fraction (for example 4.0), so does the result: 24 / 4.0 = 6.0.
  • %, &, |, ^, ~, << and >> only work on integers.

Result ​

Set is PASS, and the Actual column shows the value after setting. If the expression has an error (an undefined variable or a division by 0, for example), the round stops and is judged FAIL.

Example ​

StepsResult
a = 10, += 5, -= 3, *= 2a = 24
b = a, /= 5b = 4
c = a, %= 7c = 3
f = a / 4.0f = 6.0
m = (a >> 1) & 0x0Fm = 12

Set example result

Notes ​

  • Variables carry across cases within a round and are cleared when each round starts; see Concepts › 6. Variables.
  • Each round holds up to 256 numeric variables.

Download the sample script ​

Sample script

Before running it, start a Slave window on 127.0.0.1:502 and click Listen, then open the script with Open JSON in Script mode and click Run. See How to use the examples.

Roach Modbus Tool by Mr.Roach