IMDHMIControls LibraryShop main store

How-to

Set up a CLICK Plus as Modbus TCP client to an S7-1200

Industrial networks Published 6 min read

Short answer

Yes: make the S7-1200 the Modbus TCP server with MB_SERVER mapped to a data block of INTs, and make the CLICK Plus the client with Send and Receive instructions aimed at the CPU's IP address and port 502. Write the shared register map first; the S7 logic copies physical inputs into it and applies its output words to the real outputs.

On this page
  1. What each PLC does in this link
  2. Write the register map first
  3. Set up the S7-1200 as the Modbus TCP server
  4. Configure the CLICK Plus Send and Receive instructions
  5. Working the offsets for a one-word read and a one-word write
  6. Bring the link up in order
  7. Questions asked

Yes to the architecture: CLICK Plus as the Modbus TCP client, S7-1200 as the server, joined by a data-block interface rather than direct remote-I/O access. On the S7-1200, run MB_SERVER on the CPU's built-in port, mapped to a data block of INTs, with a stub program that packs physical input states into those words and applies the output words to the real outputs. On the CLICK Plus, run the Send and Receive instructions as the client, aimed at the CPU's IP address on the Modbus TCP service port, 502. Write the shared register map before entering parameters in either tool: that map is the whole interface between the two programs.

The CLICK Plus initiates every transaction; the S7-1200 answers. Polling rate, retries and timeouts are therefore configured entirely on the CLICK side.

MB_SERVER communicates as a Modbus TCP server through the PROFINET port on the S7-1200 CPU, and no additional communication hardware module is required. Carrying that Modbus traffic on the same on-board port as S7 programming and HMI sessions is a normal arrangement, and it is the one examined in using one S7 CPU PN port for Modbus TCP and S7 comms together.

One documented limit shapes the design: the S7-1200 allows only one connection per IP port. This link consumes port 502 for the CLICK, and anything else that wants Modbus TCP from this CPU needs its own instance on a different port number.

In the evaluation arrangement this article targets, proving CLICK logic against a machine that is already built, the field wiring stays on the S7-1200 and the register map becomes the machine's new control interface.

Write the register map first #

The server exposes only the data block you give it. Physical I/O is not remotely addressable until S7 logic moves it, so the map, not the wiring, defines what the CLICK can see and do. Give every entry a direction, a Modbus register reference, an S7-1200 data-block location, a CLICK memory location, and a meaning; for digital signals, number the bit within the word.

Signal area Modbus references S7-1200 side CLICK side Direction
Input-status words 40001 upward Data-block words packed from the input image Words filled by the Receive instruction S7-1200 to CLICK
Output-command words 40011 upward Data-block words applied to outputs through permissives Words driven by your logic, sent by Send CLICK to S7-1200
Numeric process values Next free references Wherever the owning logic places them Scaled on the consuming side Either

The references above are this article's example map; the worked example below uses its first two words, and the unused words between the two areas are expansion room.

A 16-bit INT carries a packed bit pattern without trouble, but a word with its sign bit set displays as a negative decimal, so inspect bits rather than the signed value when checking digital areas. For any value wider than 16 bits, declare the word order in the map before programming either side, the same conversion job as reading a CLICK PLC float over Modbus TCP.

Set up the S7-1200 as the Modbus TCP server #

  1. Create a global data block of INTs, with the low words reserved for input status and the output-command words placed at a later word.
  2. Insert MB_SERVER and assign that data block to its hold-register parameter, the parameter that ties the instruction to your register map.
  3. Fill the connection parameters with the port and connection identifiers the instruction help lists, and the service port: 502 unless you deliberately changed it.
  4. Call MB_SERVER every program cycle. The documentation calls for executing it each cycle for each connection, and a conditional or skipped call is a common reason a working configuration goes silent.
  5. Add the mapping logic: move input-image states into the input-status words, and move output-command bits to Q addresses through permissives. The link carries data, not safety, so E-stops and guarding stay where they are and those permissive rungs keep a stale or wrong write from commanding motion.
  6. Download and go online. The server now runs whether or not the CLICK exists, so you can prove it from TIA Portal first.

Configure the CLICK Plus Send and Receive instructions #

Chapter 4 of the CLICK PLUS Hardware User Manual (C2-USER-M) is the reference: the Modbus TCP setup example at page 30 and the Send and Receive parameter pages from page 4-35 show the fields your software version actually displays. The names below describe what each field controls; match them to the manual's screenshots.

  1. Enable Modbus TCP client operation for the Ethernet port as the setup example shows.
  2. Configure the Receive instruction: destination address = the S7-1200 CPU's IP address; service port = the server's port; operation = read of the exposed register area; starting register and quantity = the input-status area from your map; local destination = a matching CLICK word range.
  3. Configure the Send instruction against the same address and port: operation = write to the register area; starting register and quantity = the output-command area; local source = the CLICK words your logic drives.
  4. Trigger one transaction at a time per instruction, using the completion and error bits to sequence the next request. Never fire a new request while one is outstanding.
  5. Keep quantities inside the mapped areas so a request can never step past the end of the server's data block.

Working the offsets for a one-word read and a one-word write #

Inputs, each from this article's example map or the standard Modbus convention:

  • First input-status word: holding register reference 40001, quantity 1 register.
  • First output-command word: holding register reference 40011, quantity 1 register.
  • Register width: 16 bits, which is 2 bytes.
  • Base rule: 4x references are one-based for display, and the request itself carries a zero-based offset.

The rule in words: the offset you enter equals the reference minus 40001, and the data moved equals the quantity times 2 bytes.

The read: 40001 - 40001 = 0, so the Receive starts at offset 0 and moves 1 register x 2 bytes per register = 2 bytes.

The write: 40011 - 40001 = 10, so the Send starts at offset 10 and moves 1 register x 2 bytes per register = 2 bytes.

Commission at exactly one word per direction, and scale the quantity only after that word traces end to end: a physical S7-1200 input, its bit in the data-block word, the received CLICK word, and back out through the write. Before typing anything, confirm which base the CLICK field expects, because a field that wants the offset gets 0, a field that wants the reference gets 40001, and one number entered in the other field lands the request far outside the map.

  1. Prove the IP path before any Modbus request: link indication on both interfaces and any switch between them, unique addresses, matching subnets or a valid routed path, and nothing filtering the TCP port along the way.
  2. Read one word, offset 0 and quantity 1, and watch the server's status outputs in TIA Portal while the request lands.
  3. A timeout means the request reached no server: correct the destination address, the service port or the connection parameters before touching the map.
  4. An illegal-data-address exception means the request fell outside the server's data block, the same symptom family as Modbus exception 02 when a read crosses a register map gap, and the offset base is the first thing to fix.
  5. Valid registers with wrong values point to the offset base or to S7 logic overwriting the words; recheck the mapping rungs.
  6. Values that arrive while outputs ignore them put the fault in the S7-1200 output-application rungs and permissives, not in communications.

Questions asked

Which PLC is the client, and why does it matter?

The CLICK Plus is the client and the S7-1200 is the server, and it matters because a Modbus TCP server never initiates anything: the S7-1200 listens on its service port and answers. Every read and write on this link is triggered from the CLICK side, so polling rate, retries and timeout handling all live in the CLICK Send and Receive instructions.

Can a second client poll the same S7-1200 later?

Yes, but not on the same IP port. The S7-1200 allows one connection per IP port, so a second client such as a SCADA package needs a second MB_SERVER instance with a different service port in its connection parameters and its own data block, and that instance must also be executed every scan. Decide the port numbers before anything else joins the link.

A read succeeds but returns the wrong word. What do I check first?

The offset base. A 40001-style reference is a one-based display number, while the request on the wire carries a zero-based offset, so register 40011 is offset 10. Enter the reference where an offset is expected and the request lands far outside the data block and usually draws an illegal-address exception; if the bases differ by one, you simply get the neighboring word. Prove one word end to end before scaling.

How do I commission this without risking machine outputs?

Read-only at first. Toggle or force one physical input on the S7-1200, watch its bit appear in the input-status word in TIA Portal, then watch the CLICK destination word after the Receive completes. Add the write side only after that trace works, and keep the output-application rungs gated by the machine permissives for the whole evaluation so a bad write cannot command motion.

What if a value needs more than one register?

A 32-bit value spans two consecutive registers, and Modbus does not fix which word comes first, so declare the word order in the register map before programming either PLC. Keep multi-register values wholly inside one signal area: an input-status word, an output-command word and half of a 32-bit counter in a single request is a map you will debug forever.

Keep reading

  • 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

  • Troubleshooting

    Modbus exception 02 when a read crosses a register map gap

    The exception is correct: a Modbus block read requests consecutive registers, so a span from 754 through 788 includes the undefined 764-767 gap and the meter rejects it with exception 02, illegal data address. Read the 754-763 setup block at startup and after configuration changes, keep continuous reads inside the 768+ measurement area, and publish the last fully accepted set to your calculation logic.

    Industrial networks

  • Explainer

    Can a Modbus write change PLC outputs?

    Yes, but not by outrunning the scan. On a Modicon CPU the communication interface reaches data memory only between scans, so a write is applied whole and the next scan either consumes it or overwrites it. The real exposure is that Modbus TCP authenticates nothing: any host that can reach the CPU can write an unprotected holding register your logic unpacks into outputs, so pack status into read-only words, keep commands in a separate writable range, and enforce write protection with an IP access control list.

    Industrial networks