Training course
Every exercise and answer in this course was run and checked in the v1.3.4 (Windows) Release build.
This is a one-day Roach Modbus Tool training course, from Modbus basics all the way to production-line automation. Each unit has key points, hands-on exercises and answers, followed by a final quiz and trainer notes. Every exercise runs on a single PC, with Slave simulating the device, so no real hardware is needed.
Contents
| Section | Topic | Time |
|---|---|---|
| 1 | Course overview | — |
| 2 | Before the course | Before class |
| 3 | Unit 1: Modbus basics | 60 min |
| 4 | Unit 2: Poll hands-on | 60 min |
| 5 | Unit 3: Slave hands-on | 45 min |
| 6 | Unit 4: Script basics | 60 min |
| 7 | Unit 5: Advanced Script | 60 min |
| 8 | Unit 6: Production-line automation | 45 min |
| 9 | Final quiz | 20 min |
| 10 | Trainer notes | — |
1. Course overview
Audience
| Audience | Focus units |
|---|---|
| Production test staff | 1, 2, 4, 6: read values, run ready-made scripts, understand reports and exit codes |
| Firmware engineers | All: simulate devices with Slave, write verification tests with Script |
| FAEs (field application engineers) | 1, 2, 3: connect and debug on site, read frames, reproduce problems with Slave |
Course goals
After the course, trainees can:
- Turn the addresses and data types in a device manual into function codes, addresses and formats in the tool.
- Connect to a device with Poll, read and write registers, and set up engineering conversion.
- Build a simulated device with Slave and test master programs without real hardware.
- Write Script tests that judge PASS / FAIL automatically and export reports.
- Run scripts from the command line and use the exit code to integrate with fixtures or schedulers.
Timetable (one day)
| Time | Topic |
|---|---|
| 09:00–10:00 | Unit 1: Modbus basics |
| 10:10–11:10 | Unit 2: Poll hands-on |
| 11:20–12:05 | Unit 3: Slave hands-on |
| 13:10–14:10 | Unit 4: Script basics |
| 14:20–15:20 | Unit 5: Advanced Script |
| 15:30–16:15 | Unit 6: Production-line automation |
| 16:15–16:35 | Final quiz |
| 16:35–17:00 | Review and Q&A |
Short on time? Classes for production test staff can skip units 3 and 5.
2. Before the course
Each trainee
- A Windows 10 / 11 PC (or Linux x86_64) that can run two or three program windows.
- Roach Modbus Tool installed; see Getting started 2. Install. The first start gives a 30-day trial, so no license is needed for the course.
- The course's practice files, downloaded into one folder:
| File | Purpose |
|---|---|
| 09-trainer.mbslave | Training device (Slave project), shared by every unit |
| u2-answer.mbproj | Unit 2 answer (Poll project) |
| u3-answer.mbslave, u3-check.mbproj | Unit 3 answer (Slave project) and the Poll project used to check it |
| u4-answer.json | Unit 4 answer (script) |
| u5-answer.json | Unit 5 answer (script) |
| u6-run.bat | Unit 6 answer (batch file) |
Trainers should hand out the answer files only after each exercise is finished.
The training device
Every unit connects to the same simulated device: in one window switch to Slave, open 09-trainer.mbslave with File → Open Project..., and click Listen. It listens on 127.0.0.1:502, Slave ID 1, and holds the following (this table is the trainees' "device manual"):
| Function area | Address | Name | Description | Initial value |
|---|---|---|---|---|
| Holding Registers | 0x0000 | Status | 0 = stopped, 1 = running | 1 |
0x0001 | Setpoint | Set temperature, in 0.1 °C | 250 | |
0x0002 | Temperature | Current temperature, in 0.1 °C, signed | -55 | |
0x0003 | Mode | 0 = Off, 1 = Heat, 2 = Cool | 1 | |
0x0010–0x0011 | Pressure | Pressure (bar), 32-bit float, CD AB order | 1.25 | |
0x0020–0x0029 | Data 0–9 | Test data area | 0 | |
| Input Registers | 0x0000 | Firmware | Firmware version; 0x0103 means 1.3 | 0x0103 |
| Coils | 0x0000 | Heater | Heater, 1 = on | 1 |
0x0001 | Alarm | Alarm, 1 = alarm active | 0 |
If the values get scrambled during the exercises, close the Slave window and open 09-trainer.mbslave again.
Trainer
- Prepare a projector or large screen, and show the Slave and Poll windows side by side when demonstrating.
- Make sure every PC can listen on
127.0.0.1:502: no other Modbus program on the same PC may hold port 502. If it is taken, Slave shows that Listen failed; see Troubleshooting. - The whole course runs on
127.0.0.1(this PC), so no firewall changes and no network are needed.
3. Unit 1: Modbus basics
Key points
Roles: the master sends requests and the slave (the device) answers. Poll and Script act as the master; Slave mode acts as the device.
The four data areas and their function codes
| Data area | Contents | Read | Write | Common manual notation |
|---|---|---|---|---|
| Coils | Coils (0 / 1), read-write | FC01 | FC05 (single), FC15 (multiple) | 0xxxx, for example 00001 |
| Discrete Inputs | Discrete inputs (0 / 1), read-only | FC02 | — | 1xxxx, for example 10001 |
| Input Registers | 16-bit registers, read-only | FC04 | — | 3xxxx, for example 30001 |
| Holding Registers | 16-bit registers, read-write | FC03 | FC06 (single), FC16 (multiple) | 4xxxx, for example 40001 |
Addresses: addresses in the frame start at 0. When a manual says 40001, it means the first holding register, frame address 0x0000. The tool takes frame addresses and does not subtract 1 for you. A few manuals give frame addresses directly ("register 0", for example); go by what the manual says.
Data types: a register is 16 bits, read as unsigned (0 to 65535) or signed (-32768 to 32767). A 32-bit integer or float takes two registers, and which comes first is up to the device (AB CD, CD AB and so on); see Script core concepts: Value formats.
TCP and RTU: TCP connects by IP and port (502 by default) and puts a 6-byte MBAP header in front of each frame; RTU uses a serial port, has no header, and ends with a 2-byte CRC. Both have a Slave ID.
Exception responses: when a device cannot handle a request, it replies with the function code plus 0x80, followed by an exception code: 01 illegal function, 02 illegal data address, 03 illegal data value, 04 device failure.
Exercise 1-1: Converting addresses
Fill in the function code and frame address for each manual entry:
| Manual notation | Task | Function code | Frame address |
|---|---|---|---|
| 40001 | Read | ||
| 40011 | Write one value | ||
| 30001 | Read | ||
| 00002 | Read | ||
| 10002 | Read |
Exercise 1-2: Reading frames
Poll reads 4 holding registers from 0x0000 on the training device, and the Communication Log records these two lines (a real capture):
TX 00 49 00 00 00 06 01 03 00 00 00 04
RX 00 49 00 00 00 0B 01 03 08 00 01 00 FA FF C9 00 01- What are the TX's transaction ID, Slave ID, function code, start address and quantity?
- How many data bytes does the RX return, and what are the four register values?
- What is
FF C9as unsigned and as signed? According to the device manual, which one applies, and what is the actual temperature?
Exercise 1-3: Floats and byte order
Pressure's two registers, 0x0010 and 0x0011, hold the raw values 0x0000 and 0x3FA0. The manual says the order is CD AB.
- Put into AB CD order (high word first), what is the 32-bit value?
0x3FA00000is the float 1.25. If you set the format to Float AB CD in the tool, what do you see, and why?
Exercise 1-4: Exception responses
Reading a device returns 01 83 02 (RTU, CRC left out). What does it mean, and what should you check first?
Answers
1-1
| Manual notation | Function code | Frame address |
|---|---|---|
| 40001 read | FC03 | 0x0000 |
| 40011 write one value | FC06 | 0x000A (decimal 10) |
| 30001 read | FC04 | 0x0000 |
| 00002 read | FC01 | 0x0001 |
| 10002 read | FC02 | 0x0001 |
1-2
- TX: transaction ID
0x0049, protocol0x0000, length 6, Slave ID 1, function code 03, start address0x0000, quantity 4. - RX: length
0x0B(11 bytes: Slave ID, function code, byte count, plus 8 data bytes); the 8 data bytes are0x0001= 1,0x00FA= 250,0xFFC9,0x0001= 1. 0xFFC9is 65481 unsigned and -55 signed. The manual says Temperature is signed, so it is -55; times 0.1 gives -5.5 °C.
1-3
- CD AB puts the low word first; back in AB CD order it is
0x3FA0 0000, which is 1.25. - Float AB CD treats
0x0000 3FA0as the float, giving a value very close to 0 (about 2.3×10⁻⁴¹), not 1.25. A wrong byte order raises no error; you just read a value that makes no sense, so always check against the manual or a known value.
1-4: 01 is Slave ID 1 and 83 is function code 03 plus 0x80, so it is an exception response; exception code 02 means "illegal data address". First check that the address was converted as the manual says (one too many, or 40001 typed in as 40001), and that the device really has that address.
4. Unit 2: Poll hands-on
Reference: Poll guide.
Exercise 2-1: Building a Poll project
Open a second window (Poll mode), choose File → New Project, and build a project from the training device's manual:
- Rename the device to
Trainer, connection127.0.0.1:502, Slave ID 1. - In
03 Holding Registers, delete the 10 default rows and add0x0000–0x0003and0x0010. - Add
04 Input Registers(0x0000) and01 Coils(0x0000–0x0001). - Set names, formats and engineering values as below:
| Address | Name | Raw format | Access | Conversion |
|---|---|---|---|---|
HR 0x0000 | Status | Unsigned | RO | Value map: 0 Stopped, 1 Running |
HR 0x0001 | Setpoint | Unsigned | RW | Scale × 0.1, °C |
HR 0x0002 | Temperature | Signed | RO | Scale × 0.1, °C |
HR 0x0003 | Mode | Unsigned | RW | Value map: 0 Off, 1 Heat, 2 Cool |
HR 0x0010 | Pressure | Float CD AB | RO | Scale × 1, bar |
IR 0x0000 | Firmware | Hex | — | No conversion |
Coil 0x0000 | Heater | Unsigned | RW | Value map: 0 Off, 1 On |
Coil 0x0001 | Alarm | Unsigned | RO | Value map: 0 OK, 1 Alarm |
- Click Connect and note each row's Eng. Value.
- Save it as
u2.mbprojwith File → Save Project As....
Exercise 2-2: Writing
- Change the set temperature to 30.0 °C.
- Change Mode to Cool.
- In the Slave window, check the values of
0x0001and0x0003, and the Last access column.
Answers
Answer project: u2-answer.mbproj

| Name | Eng. Value |
|---|---|
| Status | Running |
| Setpoint | 25 °C |
| Temperature | -5.5 °C |
| Mode | Heat |
| Pressure | 1.25 bar |
| Firmware | 0x0103 |
| Heater | On |
| Alarm | OK |
2-2:
- Type
300(30.0 ÷ 0.1) in Setpoint's Raw column and click Write F6. Engineering values are for display only; writes take the raw value. - Type
2in Mode's Raw column and write it; Eng. Value showsCool. - In the Slave window,
0x0001becomes 300 and0x0003becomes 2, Last access briefly shows an orangeWrite, andWritesin the status bar goes up.
Common mistakes:
- Pressure set to Float AB CD, reading a value close to 0.
- Temperature set to Unsigned, showing 6548.1 °C.
- Status and Temperature not set to RO, so trainees change them by accident.
5. Unit 3: Slave hands-on
Reference: Slave guide.
Exercise 3-1: Building a simulated device
A customer's pump station has a Modbus TCP gateway with two pumps behind it. Simulate it with Slave (open a third window, and leave the training device alone):
| Item | Setting |
|---|---|
| Listener | 127.0.0.1:1502 |
| Pump A | Slave ID 1: HR 0x0000 Speed = 1450 (rpm), HR 0x0001 Running = 1, Discrete Input 0x0000 Fault = 0 |
| Pump B | Slave ID 2: HR 0x0000 Speed = 0, HR 0x0001 Running = 0, Discrete Input 0x0000 Fault = 0 |
Hint: first change the device's Listen IP and port to 127.0.0.1:1502, then click + to add the second device. It goes on the same listener, and its Slave ID is set to 2 by itself.
Exercise 3-2: Checking with Poll
- In Poll, add a device connected to
127.0.0.1:1502and read ID 1 and ID 2 with Slave ID tabs (or just openu3-check.mbproj). - In Slave, change Pump B's Speed to 1200 and Running to 1, and check that Poll reads them on the next round.
- In Slave, click Stop and then Listen, and check that Pump B's values are still there.
- In Poll, add a Slave ID 3 tab with one register to the device, and watch Quality.
Answers
Answer project: u3-answer.mbslave; for checking: u3-check.mbproj


3-2:
- A changed Value is served to the master at once, so Poll reads
1200 rpmandRunningon the next round. - Values are kept across Stop and Listen; see Slave guide 7.
- There is no Slave ID 3 behind the gateway, so Slave does not answer: Poll's Quality shows
Timeoutand the device turns into an orangeN% ok. This is what "one device is not answering" looks like on site.
6. Unit 4: Script basics
Reference: Script tutorial, Script core concepts.
Exercise 4-1: A first verification script
Open another window and switch to Script (keep the training device listening). Set channel A to TCP 127.0.0.1:502, Slave ID 1, and build two cases:
Status
- Read
0x0000(FC03), expecting 1. - Read
0x0002, format Signed, range -100 to 100 (the temperature must be sensible). - Read input register
0x0000(FC04), expecting0x0103(the firmware version).
Setpoint
- Write
0x0001= 280 (FC06). - Wait 100 ms.
- Read
0x0001, expecting 280. - Write
0x0001= 250 to put the setting back. - Read
0x0001, expecting 250.
After the run, click Export to export an Excel report, and save the script as u4.json.
Exercise 4-2: Making it fail
- In Slave, change Firmware to
0x0104and run again. Which step FAILs, and what is the Release result? - In Slave, click Stop and run again. What is the result?
Answers
Answer script: u4-answer.json
Actual output from a command-line run (excerpt):
Status: PASS
A 0x0000 = 0x0001 (expect 0x0001)
A 0x0002 = -55 (expect -100 - 100)
A 0x0000 = 0x0103 (expect 0x0103)
Setpoint: PASS
A 0x0001 = 0x0118 (expect 0x0118)
A 0x0001 = 0x00FA (expect 0x00FA)
PASS 2 - FAIL 0 - SKIP 0 - DISCONNECT 0 - Release PASS4-2:
- Step 3 of Status FAILs (it reads
0x0104, expecting0x0103), and the Release result is BLOCKED. If any case is not PASS, the release is blocked. - The device cannot be reached, so both cases are DISCONNECT and the Release result is BLOCKED. DISCONNECT means communication failed, not that the device's values were wrong; see Script core concepts.
7. Unit 5: Advanced Script
Reference: Script command reference, Script examples.
Exercise 5-1: Subroutines and loops
Build a subroutine write_check with parameters addr and value: it writes value to addr, then reads it back and compares.
Then build a case Data block: count a variable i from 0 to 9, calling write_check to write i × 10 into 0x0020 + i. Finish with a Log message saying how many registers were checked.
Exercise 5-2: Conditions and forced verdicts
Build a case Mode and temperature:
- Read
0x0002(Signed) without comparing, store it in variablet, and computetemp = t / 10.0. - If Mode (
0x0003) is 1 (Heat):- Log the current temperature.
- If
t < 0: Log a warning, and read Coil0x0000(Heater) expecting 1.
- Otherwise: Log "Mode is not Heat" and force the verdict to FAIL.
Answers
Answer script: u5-answer.json

Key points:
0x0020 + ${i}and${i} * 10are both expressions: addresses and values can both be built from variables.- Subroutine parameters are passed in the call, for example
{"call": {"sub": "write_check", "args": {"addr": "0x0020 + ${i}", "value": "${i} * 10"}}}. - If can be nested. Here the outer If uses a read condition (read Mode and compare), the inner one an expression condition (
${t} < 0). - Going further: in Slave, change Mode to 2 (Cool) and run again. The second case takes the Else branch and FAILs, and the command-line exit code is 1.
8. Unit 6: Production-line automation
Reference: Command-line runs.
Key points
RoachModbusTool --run-script <script.json> [--report <report.xlsx or .csv>] [--loops N] [--case <case name>] [--log <log.txt>]| Exit code | Meaning |
|---|---|
| 0 | Release PASS |
| 1 | Some FAIL, SKIP or DISCONNECT |
| 2 | Could not run (file, format, serial port or option error) |
| 3 | No license |
On Windows you need start /wait, or PowerShell's Start-Process -Wait, to get the exit code.
Exercise 6-1: Running from the command line
- Run
u4.jsonfrom the command line for three rounds, writing the reportreport.xlsxand the loglog.txt. - Get the exit code.
- Click Stop in Slave and run again. What is the exit code now?
Exercise 6-2: A batch file
Write a batch file that sits next to RoachModbusTool.exe: it runs the Unit 4 script for three rounds, names the report and log after the date and time, shows PASS, FAIL or ERROR according to the exit code, and passes the exit code back to whatever called it (fixture software or a scheduler).
Answers
6-1:
start /wait "" RoachModbusTool.exe --run-script u4.json --loops 3 --report report.xlsx --log log.txt
echo %ERRORLEVEL%With Slave running, the exit code is 0. With Slave stopped, the device cannot be reached, the result is DISCONNECT, and the exit code is 1.
6-2: u6-run.bat
@echo off
rem Run the Unit 4 script three rounds and keep a report named after the date and time.
rem Put this file next to RoachModbusTool.exe and u4-answer.json.
setlocal
cd /d "%~dp0"
for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd_HHmmss"') do set STAMP=%%i
start /wait "" RoachModbusTool.exe --run-script u4-answer.json --loops 3 --report report_%STAMP%.xlsx --log log_%STAMP%.txt
set RC=%ERRORLEVEL%
if %RC%==0 (
echo PASS
) else if %RC%==1 (
echo FAIL: see report_%STAMP%.xlsx
) else (
echo ERROR %RC%: the script could not run
)
exit /b %RC%Tested: with Slave listening it shows PASS with exit code 0; with Slave stopped it shows FAIL: see report_20261126_070515.xlsx with exit code 1. Every run produces report_<date>_<time>.xlsx and log_<date>_<time>.txt.
Notes:
cd /d "%~dp0"makes the batch file run in its own folder, wherever it is called from.- The timestamp comes from PowerShell, so it does not depend on Windows regional settings (the format of
%date%changes with them). exit /b %RC%hands the exit code back to the caller, so fixture software can check it directly.
9. Final quiz
Multiple choice, 5 points each, 15 questions. The answers are at the end of this section.
- A device manual says "40005: setpoint". Which function code and address read it in the tool? (A) FC03,
0x0005(B) FC03,0x0004(C) FC04,0x0004(D) FC04,0x0005 - Which data area can a master write? (A) Discrete Inputs (B) Input Registers (C) Holding Registers (D) All of the above
- A register reads
0xFF9C, and the manual says it is a signed temperature in 0.1 °C. What is the temperature? (A) 6545.2 °C (B) -10.0 °C (C) -0.1 °C (D) 10.0 °C - What does the response
01 86 02mean? (A) Write succeeded (B) FC06 exception, illegal data address (C) FC06 exception, illegal data value (D) CRC error - Which is true about Poll's Raw column and Eng. Value? (A) To write 25.0 °C (× 0.1), type 250 in Raw (B) Typing 25.0 in Eng. Value is enough (C) They are always the same (D) Eng. Value is stored in the device
- In Poll, how do you auto poll only certain rows? (A) Delete the other rows (B) Mark only those rows with ★ (C) Check those rows and click Read F5 (D) Make the poll interval longer
- One Poll device needs to read Slave IDs 1 and 2 behind the same gateway. What do you do? (A) It cannot be done (B) Add ID 2 as a Slave ID tab (C) Increase Timeout (D) Run two copies of the program
- When Slave receives a request for a Slave ID it does not have, it: (A) Replies with exception 02 (B) Replies with 0 (C) Does not answer, so the master times out (D) Adds that ID by itself
- After Stop and Listen in Slave, values the master wrote earlier are: (A) Cleared to 0 (B) Restored from the project file (C) Kept (D) Random
- In a Script case, a read value does not match what is expected. The result is: (A) DISCONNECT (B) FAIL (C) SKIP (D) PASS
- While a script runs, the device cannot be reached. The case's result is: (A) FAIL (B) DISCONNECT (C) PASS (D) The program crashes
- If any case is not PASS, the Release result is: (A) PASS (B) BLOCKED (C) FAIL (D) It depends on the number of cases
- Which one lets a Read's address change with a loop? (A)
"address": "0x0020 + ${i}"(B)"address": "${0x0020+i}"(C) Addresses must be fixed (D)"address": "i" - A command-line run has a FAIL. The exit code is: (A) 0 (B) 1 (C) 2 (D) 3
- To get the exit code of
RoachModbusTool --run-scriptin the Windows Command Prompt, you must: (A) Just run it (B) Usestart /wait(C) Add--wait(D) Switch to RTU
Quiz answers
| Q | Answer | Why |
|---|---|---|
| 1 | B | 4xxxx is a holding register; 40005 is the 5th, frame address 0x0004, read with FC03 |
| 2 | C | Discrete Inputs and Input Registers are read-only to the master |
| 3 | B | 0xFF9C signed is -100; × 0.1 = -10.0 °C |
| 4 | B | 86 = 06 + 0x80; exception 02 is illegal data address |
| 5 | A | Engineering values are for display only; writes take the raw value in Raw |
| 6 | B | Auto poll only reads ★ rows |
| 7 | B | Several Slave IDs on the same IP and port go in Slave ID tabs |
| 8 | C | Without that Slave ID it does not answer |
| 9 | C | After Stop and Listen, every address is back to its value before Stop |
| 10 | B | A mismatch is FAIL |
| 11 | B | A communication failure is DISCONNECT |
| 12 | B | Release PASS needs every case to PASS |
| 13 | A | Address fields take expressions, with variables written as ${name} |
| 14 | B | 0 PASS, 1 some FAIL / SKIP / DISCONNECT, 2 could not run, 3 no license |
| 15 | B | The program is a Windows GUI program, so you have to wait for it to finish explicitly |
80 points (12 questions) or more is a pass.
10. Trainer notes
Before the course
- Run every exercise once on the trainer's PC, and make sure ports 502 and 1502 are not taken by other programs.
- Other Modbus software on trainee PCs (a PLC development environment's simulator, for example) may hold port 502; close it beforehand.
- The trial lasts 30 days from the first start. On PCs installed early for testing, check the trial will still be running on the day.
Reminders by unit
| Unit | Common trainee problem | What to do |
|---|---|---|
| 1 | Using 40001 as the address | Stress that frame addresses start at 0, and compare with the hint Monitors wire address N at the bottom of Poll's Add register window |
| 1 | Not seeing why signed and unsigned matter | Show FF C9 from exercise 1-2: the same bits read two very different ways |
| 2 | Pressure reads close to 0 | Wrong byte order; change it to Float CD AB |
| 2 | Changing Eng. Value does nothing | Engineering values are for display only; write by changing Raw |
| 2 | A written value goes back to the old one | Write F6 was never clicked, only the value on screen changed (orange Changed) |
| 3 | The second device became another listener | Devices added with + go on the first device's listener; if the first device's port was changed first, make sure both use the same port |
| 3 | Poll does not change after a Slave edit | Poll is not polling (state Connected, not Polling), or that row has no ★ |
| 4 | Every step of the script is DISCONNECT | The training device is not listening, or channel A's port or Slave ID is wrong |
| 4 | Script and Slave in the same window | Switching to Script mode stops Slave's listener; always use separate windows |
| 5 | Expressions have no effect | Variables are written ${i}, not i |
| 6 | No exit code (always 0) | start /wait was not used; see Troubleshooting 7 |
Resetting the practice environment
- The training device's values are scrambled: close the Slave window and open
09-trainer.mbslaveagain. The project file keeps the initial values, and is not overwritten unless someone clicks Save Project. - A trainee saved over
09-trainer.mbslave: download a fresh copy.
Extra exercises for advanced classes
- Turn the Unit 4 script into a two-channel test: channel A writes to the training device and channel B reads the Unit 3 pump station, to practise gateway forwarding; see Script examples 3.
- Use Ask (text input) to have the operator enter a serial number and write it into the report; see Script examples 7.
- Simulate a power cycle with Slave's Stop / Listen and Wait Until; see Script examples 4.
