Read
Purpose: read registers or coils, compare them with the expected values, and optionally store what was read in variables.

Compare has four choices:
| Choice | Meaning |
|---|---|
| No check | Read only, no compare. PASS if the device responds |
| = equals | PASS only if equal to Expected value |
| ≠ not equal | PASS only if not equal to Expected value |
| In range | PASS only if between the Pass when limits (inclusive) |

Save to variable stores the values read in a variable, and Save as decides how:
| Choice | JSON (store_mode) | Result |
|---|---|---|
| First value | first (default) | Stores only the first value |
| Each value | each | Stores each value separately: r_0, r_1, r_2…, and r itself equals r_0 |
| 32-bit, high first | u32_hi_first | Combines 2 registers into one 32-bit value, the first being the high word |
| 32-bit, low first | u32_lo_first | Same, with the first being the low word |
JSON
json
{ "read": { "function": 3, "address": "0x0100", "expected": 100 } }
{ "read": { "address": "0x0101", "compare_op": "!=", "expected": 7 } }
{ "read": { "address": "0x0100", "range": [90, 110] } }
{ "read": { "address": "0x0110", "count": 3, "store": "r", "store_mode": "each" } }| Field | Required | Meaning |
|---|---|---|
address | Yes | Start address. Expression allowed |
end_address / count | No | The range to read, as in Write. Up to 123 |
function | No | 1 coils, 2 discrete inputs, 3 holding registers (default), 4 input registers |
format | No | Default unsigned |
expected | No | Expected value. A single value must match at every position; a list is compared value by value. Expression allowed |
compare_op | No | "==" (default) or "!=". "eq" and "ne" are also accepted |
range | No | Range: [low, high], {"min": low, "max": high}, or a string like "0x10-0x20" for Unsigned |
tolerance | No | Allowed difference (0–65535): equal if |actual − expected| ≤ tolerance |
compare | No | Defaults to true when expected or range is given. false reads without comparing |
store | No | Name of the variable to store into |
store_mode | No | See the table above. Needs store |
channel, max_ms | No | See Common fields |
Result
| Result | When |
|---|---|
| PASS | The compare matches, or there is no compare and the device responds |
| FAIL | The compare does not match, the device returns an exception code, or the response is slower than max_ms |
| DISCONNECT | The device does not respond |
Example
| Case | What it does | Result |
|---|---|---|
| Prepare data | Writes the data the later cases read | PASS |
| Equal and not equal | 0x0100 equals 100; 0x0101 (value 0) is not 7 | PASS |
| Range and tolerance | 0x0100 (100) is within 90–110; equals 98 ± 5 | PASS |
| Several registers | 0x0110..0x0112 equal 10, 20, 30 in order | PASS |
| Save to variables | Stores into v, r_0..r_2 and big, then prints them with Log | PASS |
| Other function codes | Reads with FC04 and FC02 | PASS |
| Fails on purpose | 0x0102 is 5, expected 6 | FAIL |

The Log prints v = 100, r_0..r_2 = 10, 20, 30, big = 65538. big is built from 0x0001, 0x0002 with the high word first: 1 × 65536 + 2 = 65538. Overall the run is Release BLOCKED because the last case FAILs.
Notes
- The screen has no separate tolerance field: JSON with
"expected": 98, "tolerance": 5opens on screen as In range0x005D–0x0067(93–103). Both give the same result. - With
store_mode: "each", the variable name can be at most 27 characters (leaving room for_0up to_122). u32_hi_first/u32_lo_firstonly work with the Unsigned format, FC03 or FC04, and exactly 2 registers. Other formats (such aslong_abcd) already combine the registers into one value, so just store it.- When the start address is an expression,
countcovers the whole range. The same is true of Write and Wait Until.end_addressstill works, for example"${addr} + 2".
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.
