Skip to content

Power-cycle test ​

Need: power the device off and on repeatedly. After every boot, confirm that the device responds in time and its state is right, then wait for the next power-off. Matches the library's Power cycle.json.

Script structure ​

loop_infinite: true: runs until you click Stop. Each round is one "boot → check → power off":

StepWhat it does
1Log Waiting for the device to power up
2Wait Until: met as soon as 0x0000 responds (compare: false). timeout_ms: 0 waits forever
3Wait 3000 ms: time for the device to finish booting
4Call check_values, storing the return value in result
5–7If ${result} != 1 → Verdict FAIL
8Log Waiting for the power to go off
9Wait Until: met when 0x0000 stops responding (no_response: true), also waiting forever

The check_values subroutine keeps reading the status at 0x0000 and the voltage (a float) until "status = 1 and voltage within 219.5–240.5 V", then returns 1. If the power goes off before that happens, it returns 2 and logs the last status it read.

on_error is continue: losing data during power-off is expected, so a communication failure must not skip the remaining steps.

Practising with Slave ​

Use the Slave window's Stop/Listen to simulate power off and on:

  1. Click Listen in the Slave window.
  2. First run 04-power-cycle-prepare.json, which writes status 0x0000 = 1 and voltage 230.0 (float ABCD, 0x0010..0x0011) into the Slave. These values survive a Stop and Listen in the Slave, like a device's non-volatile memory.
  3. Open 04-power-cycle.json and click Run. The script waits for power-off at step 9.
  4. Click Stop in the Slave window (power off): this round PASSes, and the next round starts waiting for boot.
  5. Click Listen in the Slave window (power on): the script waits 3 seconds, checks the values, then goes back to waiting for power-off.
  6. Repeat 4 and 5. Click Stop Esc when done.

Power-cycle test running (round 2)

The screen shows round 2: step 2 shows how long it waited for the boot (met after 3078 ms), and PASS 1 at the top is round 1's result.

The practice file's steps are identical to the library's Power cycle.json; only channel A's IP is changed to 127.0.0.1. For a real device, change the IP in channel_a to the device's IP, and change the status and voltage addresses to match its manual.

Notes

  • A wrong result keeps retrying: the While in check_values has no pass limit (max_loops: 0), so a wrong value is re-read every 500 ms until the power goes off, and that round is judged FAIL. The test never hangs and never misses a boot.
  • To limit the number of cycles, set Loop in the toolbar to N×, for example 100 rounds.
  • When running without a limit, the report only keeps the latest 9999 rounds (the Log shows report keeps latest 9999). Click Export from time to time to keep the results you need.

Download the sample scripts ​

Sample scripts

Run 04-power-cycle-prepare.json first to write the values into the Slave, then run 04-power-cycle.json, following "Practising with Slave" above. See How to use the examples.

Roach Modbus Tool by Mr.Roach