Skip to content

Call ​

Purpose: run a subroutine and come back to the next step, optionally passing parameters and receiving a return value.

Call settings

After you pick the subroutine to call, its parameters are listed below; fill in a value for each. Save result to is the variable that receives the return value (optional).

JSON ​

json
{ "call": { "sub": "read_sum", "args": { "addr": "0x0700" }, "store": "total" } }
FieldRequiredMeaning
subYesSubroutine name
argsNoParameter values, {"parameter": value}. Values can be expressions, worked out with the caller's variables. Parameters without a default must be passed
storeNoVariable that receives the value from Return

Result ​

ResultWhen
PASSNo step in the subroutine FAILs. With store, the Actual column shows the value received
FAILA step in the subroutine FAILs, or store is given but the subroutine returns no value

If communication fails inside the subroutine under on_error: skip, the rest of the calling case is skipped too.

Example ​

read_sum first calls another subroutine, fill, to write 1, 2 and 3, then reads the 3 registers back and returns their sum. The case receives it with store: "total", and the Log prints Sum of 0x0700..0x0702 = 6.

Call example result

Notes ​

  • Passing a parameter the subroutine does not have, or leaving out one without a default, stops the script from loading, and the error names the parameter.
  • A Call takes up to 8 parameters.

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