Connecting to a Real TCP Slave

Connect to a real Modbus TCP slave, read the register map, convert raw values into engineering values, and master troubleshooting for cannot-connect / timeout / write-failure.

Chapter Objectives

Scenario: Putting Ms. Wang's Greenhouse on the Network

For the first eight chapters, Ms. Wang's greenhouse lived only on paper. Now we bring it to life: this site runs a real Modbus TCP slave (tcp.modbus.kredlab.com:502), which you can treat as "the simulator of Ms. Wang's greenhouse". Connect to it with any standard Modbus client, read the temperature, start the pump, write a setpoint—every byte you have studied becomes real data flowing over a real network.

Why It Matters

Going from "messages in a browser" to "a slave on a real network" is the first real step into industrial communication debugging. The real world has latency, concurrency, and firewalls—pitfalls you never experience in a simulator. This chapter runs into all of them, and solves all of them.

Core Concepts

The Three Connection Essentials

EssentialValue for this slaveNotes
Hosttcp.modbus.kredlab.comServer domain name/IP
Port502Standard Modbus TCP port
Unit ID1Usually 1 or 255

Business Meaning of the Register Map (Greenhouse Terms)

AddressTypeGreenhouse meaningConversion
0x0000 – 0x0009Holding registersSensor values: temperature, pressure, flow, etc.×0.1 etc. (per the page notes)
0x000A – 0x000FHolding registersRun time, event countersRead directly
0x0000 – 0x000FCoilsPump switch, alarms, modes0=off 1=on

Data conversion recap: what the slave returns is a raw integer. For example, if you read 00 64 = 100 and the page notes say "×0.1", the engineering value is 10.0; if you read 1500 and the notes say "speed in RPM", it is 1500 RPM. Read the map before reading the device—just as you would read the device manual first.

Protocol Details and Byte-Level Examples

Use a client to send "read 1 holding register @0x0000" (FC 03). A normal response looks like this:

■ MBAP Header ■ Function Code ■ Data
Transaction ID echoed (same as the request) 00 02
Protocol ID = 0x0000 00 00
Length = 5 (unit ID + FC + byte count + data) 00 05
Unit ID = 1 01
FC 03 echoed 03
Byte count = 2 02
Data = 100 → 10.0 (if ×0.1) 00 64
Request / ResponseValueMeaning
Request (TCP)00 02 00 00 00 06 01 03 00 00 00 01Read 1 holding register @0x0000
Response 0–100 02Transaction ID echoed
Response 2–300 00Protocol ID
Response 4–500 05Length = 5
Response 601Unit ID
Response 703Function code echoed
Response 802Byte count = 2
Response 9–1000 64Data = 100 → 10.0

Note that the response's transaction ID matches the request (both 00 02 here), and length = 0x0005 = unit ID + FC + byte count + data. If the address is out of range, the slave returns an exception: 01 83 02 (function code 0x83 + exception code 02).

Real-World Applications

Case 1: The Greenhouse Wrap-Up Script

  1. Connect a client to tcp.modbus.kredlab.com:502 (unit ID 1);
  2. FC 03 read 10 holding registers from 0x0000 → see the simulated temperature/pressure/flow values;
  3. FC 05 write coil 0x0000 to ON → watch the slave page's live log show "write coil #0 = ON";
  4. FC 06 write a setpoint into a writable register → read it back to confirm;
  5. Keep an eye on the live log on the slave page throughout: every request and response is in there.

Case 2: Closing the VFD Side Case

Remember the VFD's register map? Holding register 0x0000 = target speed. If the slave simulator shows 0x0000 = 1500, it means "the present target is 1500 RPM"—read exactly the same way as the greenhouse's "0x0000 = 10.0 °C": look up the map first, then convert.

Troubleshooting Table

SymptomPossible causeFix
Cannot connect / timeoutFirewall blocking the port, DNS resolution failureMake sure port 502 is allowed; test with a direct IP
Connection refused / rate limitedExceeded the per-IP connection limit (3)Close spare connections; disconnect test scripts promptly when done
Read returns exception 02Address out of range or quantity over the limitCorrect the starting address/quantity against the register map
Write failsTarget area is read-only / wrong addressConfirm the address is writable; read the map before writing

Hands-On Lab Guide

  1. Install a Modbus client: Modbus Poll (Windows), QModMaster (cross-platform, open source), or Python pymodbus;
  2. Create a new TCP connection: host tcp.modbus.kredlab.com, port 502, unit ID 1;
  3. Read first: FC 03, starting address 0x0000, quantity 10—you should see a set of simulated values;
  4. Then write: FC 05 to turn on coil 0, FC 06 to write a setpoint—confirm both in the slave page log;
  5. Disconnect promptly when you are done so that everyone can use this slave fairly.

Chapter Summary and What's Next

Congratulations—you have completed Chapter 9: connecting to a real slave, reading the register map, converting raw values, and troubleshooting three common problems. You can read a device manual, draw a register map, build and parse frames, and talk to real equipment—these are the core fundamentals of a Modbus engineer.

Next: head to the quiz page to test your understanding, read deeper articles in the knowledge base, or go back to the Lab to keep practising. And don't forget there is one chapter left: in Chapter 10 we pull the camera back and walk into the real world of Modbus—which industries use it, and how real systems are put together.