IMDHMIControls LibraryShop main store

Explainer

What you must configure on the PLC side for Modbus TCP

Industrial networks Published 8 min read

Short answer

On the PLC side you always provide the IP address, port 502 and the register map — but the serving mechanism is what differs: the S7-1200, the Omron CP2E and the Speed7 family need the manufacturer's server function blocks called cyclically, while a ControlLogix needs a socket-based add-on instruction.

On this page
  1. Does the PLC need function blocks to act as a Modbus TCP server?
  2. What must match on the client side of the connection?
  3. How do S7-1200 and S7-1500 controllers run a Modbus TCP server?
  4. How do other controller families provide the server side?
  5. Where does the unit ID get set?
  6. How do you size the register map the client will poll?
  7. What if the project shows a surrogate CPU instead of the real controller?
  8. How do you prove the server is live before trusting it?
  9. Questions asked

Modbus TCP looks symmetrical from outside, but the two ends are not: the client — your gateway, HMI or SCADA — always initiates, and the PLC only answers. The gateway manual stops at its own web pages because the protocol is brand-agnostic; the PLC side is left to you. It comes down to three things: the IP address and port the server listens on, the register map the client reads, and the serving mechanism itself. The first two are settings. The third is where controller families split, and it decides whether the job is ten minutes or a day.

Does the PLC need function blocks to act as a Modbus TCP server? #

Usually yes: on the S7-1200, the S7-1500, the Omron CP2E and the Speed7 family the Modbus TCP server is function blocks you insert and call cyclically, while only a minority of controllers answers from configured memory with nothing more than a vendor block or a settings page.

What the question really asks is whether the controller's firmware contains a Modbus service bound to fixed memory, or whether your program implements the server. Where firmware already serves, the manual shows a communication page with the port and a memory range, and the PLC-side work ends there. Where it does not — every family named above — the manufacturer ships communication blocks, and a server exists only once those blocks sit in the cyclic program with their instance data. The IP address is set in the CPU's communication properties either way, and the port is 502, the port the Modbus TCP specification assigns. The blocks are the part people skip, then blame the gateway when nothing answers.

What must match on the client side of the connection? #

The client sets the PLC's IP address, TCP port 502, the unit ID it sends, and the register addresses and quantities it reads or writes; the PLC side exists to satisfy exactly those four settings.

Those settings live in the gateway's web interface or the SCADA's tag database, and nothing entered there changes the PLC. Reads use function code 03 for holding registers and 04 for input registers; writes use 06 for a single register and 16 for a block, and coils and discrete inputs have their own codes. The server never sends anything unprompted, so the update rate you see is the client's poll rate. Mask writes, function code 22, are optional in the specification, which is why some servers refuse them — what to do when a Modbus TCP server lacks FC22 support covers the workaround.

Because Modbus TCP carries no authentication of its own, any device that reaches port 502 can read and write the mapped registers: keep that port on an isolated machine network or behind controlled routing.

How do S7-1200 and S7-1500 controllers run a Modbus TCP server? #

Insert the MB_SERVER instruction, wire its MB_HOLD_REG parameter to a data block, give the instance its connection ID, and call it every scan: it communicates as a Modbus TCP server through the CPU's PROFINET port, with no additional communication module required.

The data block becomes the holding-register image: register offset n is the nth word of the array behind MB_HOLD_REG, and your program moves process values into it. One instance serves one client connection, identified by the connection ID you assign, so three simultaneous clients need three instances — they may point at the same data block. Call the block level-triggered every scan, not on an edge, or connections stall. The same port also carries ordinary S7 communication; whether one S7 CPU PN port can run Modbus TCP and S7 comms together covers the limits of sharing it.

How do other controller families provide the server side? #

The Omron CP2E takes a vendor function block that then answers clients automatically against the Work Area and Data Memory; the Speed7 family ships the Modbus_TCP_11 library; ControlLogix has no native Modbus TCP server, so the protocol runs over TCP sockets through an AOI such as RA-ModbusTCP-Server.

Controller Server mechanism What you configure
S7-1200, S7-1500 MB_SERVER instruction, cyclic call MB_HOLD_REG data block, one connection ID per client, port 502
Omron CP2E Vendor function block, automatic response Insert the block; clients read the Work Area and Data Memory directly
VIPA Speed7 family, including the Yaskawa Micro PLC Modbus_TCP_11 function block library Block calls with instance data; connection and register mapping per the library manual
ControlLogix No native server; TCP socket messaging Add-on instruction such as RA-ModbusTCP-Server, with tags mapped to registers

On the CP2E, once the block is loaded it answers clients automatically, so the addressing follows the memory layout rather than a parameter you wire. On the Speed7 family, the Modbus_TCP_11 library supplies the blocks for Modbus TCP communication with the controller; its manual is where the connection parameters and register mapping live. One documented library adds a start control of its own: leave the server's start-up parameter at "No activity" and a ModTcpServOnOff block brings it up later at run time, useful when the port must stay closed until the process is ready.

ControlLogix takes the longest route: the protocol runs over TCP socket messaging and an add-on instruction such as RA-ModbusTCP-Server does the work. The socket route also serves the client direction, as in reading Modbus TCP from a ControlLogix PLC without a gateway.

Where does the unit ID get set? #

Nowhere on a native server, in most cases: the unit ID is a routing byte the client sends, 1 to 247 only when a gateway forwards requests to serial slaves; a PLC serving TCP directly either names one accepted value or, like MB_SERVER, identifies connections by connection ID instead.

The unit identifier is one byte of the MBAP header the Modbus TCP specification puts in front of every request. On a direct TCP link it has no routing job, and the reserved value for the TCP device itself is 255; servers that care usually document 1 instead. Behind a gateway bridging to Modbus RTU it is the serial slave address, valid 1 to 247, and it must match that slave exactly. So set the client's device-address field to the RTU slave address when serial slaves sit behind the gateway, to the documented value when the server states one, and to 255 on a direct link otherwise.

How do you size the register map the client will poll? #

Count words, not tags: every 32-bit float takes two holding registers and every 16-bit value one, so a map of six floats and two counters is 6 × 2 + 2 × 1 = 14 registers, and the client polls holding registers 40001 through 40014.

Lay the floats first and the counters after them: offsets 0-1, 2-3, 4-5, 6-7, 8-9 and 10-11 for the six floats, offsets 12 and 13 for the two counters. The fourth float — say Tank B level — starts at offset (4 - 1) × 2 = 6, so it occupies registers 40007 and 40008, because 40001 + 6 = 40007. The client reads start register 40007, quantity 2, data type Float, with the word order the server documents. Keep 32-bit values on even offsets so a pair is never split across two poll ranges.

One trap sits behind half of all addressing faults: the wire uses zero-based offsets while the 4xxxx notation is one-based. A tool that takes raw offsets wants 6 for register 40007; feed it 40007 and it reads 40007 registers past the start. When every value is shifted by exactly one register, this confusion is why. Check also which function codes your server block implements — most expose holding registers, and coil or discrete-input support varies by block.

What if the project shows a surrogate CPU instead of the real controller? #

Follow the real controller's runtime, not the catalog entry: in one documented case a Yaskawa Micro PLC appeared in TIA Portal as a CPU 314C-2PN/DP (314-6EH04-0AB0 V3.3) with its own GSD attached as a PROFINET IO device, yet the working Modbus server still came from the manufacturer's function blocks.

That controller is programmable in Speed7Studio, Simatic Manager or TIA Portal, but it runs its own runtime, and the stand-in CPU in the hardware catalog is a representation, not a promise: it makes the editor usable and lets the unit join PROFINET I/O through its GSD, but it does not make another vendor's communication blocks valid for the underlying firmware. The field case behind that question resolved exactly this way — the gateway configuration was complete, and the missing piece was the manufacturer's blocks, in this family the Modbus_TCP_11 library. Decide the same way every time: choose communication blocks from the actual controller's library documentation, whatever the editor shows, and confirm the block's status after download.

How do you prove the server is live before trusting it? #

Force one known value and read it with one client before touching the gateway: put a fixed number such as 12345 into the first mapped register, point a Modbus test client at the PLC's IP on port 502, and confirm the value arrives before configuring a single tag.

Check in this order: the server block's status output sits in its documented active state with the client connected; the fixed 12345 arrives at register 40001 in the test client; then configure the gateway tags and confirm each one against a forced PLC value. When a tag reads wrong, suspect in order the offset-versus-register confusion, then word order, then the unit ID — that is the order these faults actually occur in.

The decision by controller: an S7-1200 or S7-1500 needs one MB_SERVER per simultaneous client, its MB_HOLD_REG on one data block, and port 502 kept on the machine network. A CP2E needs the vendor block loaded, after which clients read the Work Area and Data Memory directly. A Speed7-family controller — the Yaskawa Micro PLC among them — needs the Modbus_TCP_11 blocks whichever editor the project opened in. A ControlLogix needs the socket-based add-on instruction; there is no settings page to find.

Questions asked

Can several clients poll one PLC server at the same time?

Yes, where the implementation allows it. On an S7-1200 or S7-1500 you call one MB_SERVER instance per simultaneous client, each with its own connection ID; two HMIs and a data logger mean three instances, which may share one data block. Socket-based add-on instructions carry their own documented connection count, so read that limit before promising a third client.

Why do float values look wrong when the addresses are correct?

Word order. A 32-bit value crosses two holding registers, and servers and clients disagree about which register carries the high word. Set the client's word order to match the server's documentation, or swap the words when you copy them into the register image. When numbers look huge, negative or near zero, this is the first thing to change.

What is the difference between the connection ID and the unit ID?

The connection ID is internal to the PLC: it tells the controller's operating system which server instance owns which TCP connection, and you assign it per instance. The unit ID travels inside every request on the wire and only matters when something routes the request onward, such as a gateway in front of serial slaves.

Does writing from the gateway need a second server?

No. The same server instance accepts writes: the client sends function code 06 or 16 against the holding registers, and the mapped data block simply changes. To react in the program, compare each mapped word against a stored copy and flag the difference, because the server blocks do not report which register was written.

Keep reading

  • How-to

    How to build a virtual PLC test bench for protocol practice

    One laptop runs the whole bench: a Modbus TCP server simulator, a master test client, a Node-RED OPC UA server and a SCADA trial connect over loopback, so you can practice addressing, sessions, scaling, alarms and fault diagnosis without a PLC. Work through three bounded projects and finish with seven pass criteria you can defend.

    Industrial networks

  • How-to

    Linking Modbus RTU BMS SCADA to a redundant S7-1500R

    Use one Modbus RTU-to-TCP gateway as the Modbus TCP client, and run the Modbus TCP server on the S7-1500R system IP address that switched communication moves to the surviving CPU. The BMS keeps polling its RS-485 link unchanged; on a switchover the TCP session drops and the gateway reconnects. Set the comm-fail timeout to the measured gap plus one poll interval: 3 s at a 1 s rate in the example.

    Industrial networks

  • How-to

    Set up a QJ71MT91 as Modbus TCP client with scattered registers

    Run the QJ71MT91 as a Modbus TCP client to the remote I/O interface on port 502, one connection at a time, and keep the SCADA host as a client of the module's server function. Split the slave's scattered register table into bounded requests grouped by object type and direction, convert references to zero-based offsets, and stage every network value in D registers instead of X and Y.

    Industrial networks