Interactive Lab

Assemble and parse Modbus frames by hand in the lab; reproduce tasks like reading greenhouse temperature, writing setpoints, and reading device status — bridging paper framing to real-device practice.

Chapter Objectives

Scenario: Now It's Your Turn

With the theory this far, Ms. Wang's gateway is "yours to assemble". Open the Lab page—it is not a simulator but a real message encoder/decoder: you pick the parameters and it generates standard bytes; you paste hex and it takes it apart byte by byte. Every action you practise here is exactly the action you will perform later when debugging real devices with Modbus tools.

Why It Matters

A frame you assembled yourself is the only knowledge you truly own. Being unable to read a capture, or not knowing which parameters to fill in a tool, is usually because you never "put your hands on it" in the Lab.

Core Concepts: The Five-Step Framing Method

  1. Choose the protocol: RTU (serial) or TCP (Ethernet)—this decides the envelope;
  2. Choose the function code: read or write, single or multiple—this decides the action;
  3. Fill in the address: slave address (RTU) or unit ID (TCP) + starting address;
  4. Fill in the data: quantity (for reads) or value (for writes);
  5. Read the CRC / copy: RTU computes the CRC automatically; copy the complete hex and go parse it.

Two easily forgotten points to review: big-endian order—the high byte of a 16-bit value comes first (100 = 00 64); bit packing—coil responses are stored by bit, least significant bit first within a byte (0x0B = coils 0, 1 and 3 on).

Protocol Details and Byte-Level Example: A Complete Write Command

Task: write the humidity target 60 (0x003C) into holding register 0x0001 of slave 1 (RTU). After the five steps, the complete frame the Lab produces is:

■ RTU Address ■ Function Code ■ Data ■ CRC
Slave 1 01
FC 06: Write Single Register 06
Register address 0x0001 00 01
Value written = 60 (0x003C) 00 3C
CRC-16 (computed automatically) D8 1B
ByteValueMeaning
001Slave 1
106Function code: Write Single Register
2–300 01Register address
4–500 3CValue written = 60
6–7D8 1BCRC-16

The response should echo this frame verbatim—when you see a matching echo, the write succeeded.

Real-World Applications: Greenhouse Task Cards

Task Card 1: Reproduce the Greenhouse Temperature Read Frame

  1. Protocol RTU; operation "Read Holding Registers" (FC 03);
  2. Slave address 1, starting address 0x0000, quantity 2;
  3. Expected request: 01 03 00 00 00 02 C4 0B;
  4. Copy the hex into the "Parse" area and check it byte by byte against Chapter 4;
  5. Take the complete frame (including the CRC) and compute the CRC; the result should be 0x0000.

Task Card 2: Write the Humidity Target 60

  1. Protocol RTU; operation "Write Single Register" (FC 06);
  2. Slave address 1, register address 0x0001, value 60 (60 = 0x003C, big-endian);
  3. Expected request: 01 06 00 01 00 3C D8 1B;
  4. After sending, check the echo in the response.

Task Card 3 (Challenge): Read Device Status

Use FC 01 to read 10 coils from 0x0000: expected request 01 01 00 00 00 0A BC 0D. Map the bits in the response to the states of "exhaust fan, water pump, shade curtain" (bit 0 = exhaust fan, bit 1 = water pump, bit 2 = shade curtain, and so on).

Then try FC 05 to write coil 0x0000 to ON: expected request 01 05 00 00 FF 00 8C 3A—remember that ON for a coil write is FF 00, not 00 01.

(All the exercises above stay within FC 01/03/05/06, which the Lab supports; FC 02/04/15/16 are not required hands-on in this course.)

Hands-On Lab Guide

This chapter is the Lab itself. After finishing the three task cards, you can also:

Chapter Summary and What's Next

In this chapter you assembled four kinds of requests by hand—read a temperature, write a setpoint, read status, switch a device on—and verified every byte with the decoder. You now have the most critical link between "framing on paper" and "commissioning on real hardware".

In the next chapter (Chapter 9), we pull the camera back to Ms. Wang's greenhouse—connecting to a real TCP slave and turning theory into data moving on your screen.