System designHow-to

Multiple vision cameras on Modbus TCP: one PLC CPU, one poll loop

Wire multiple vision cameras to one PLC CPU over Modbus TCP: direct connections versus a gateway with unit IDs, the poll-cycle math, and a shared register map.

LumaSpec Vision12 min read Share on LinkedIn

On this page 10 sections
  1. 01Can one PLC CPU poll several Modbus TCP vision systems?
  2. 02Do I need a serial-to-Ethernet gateway when the cameras are on Ethernet?
  3. 03What is the unit identifier, and when does it matter?
  4. 04How do I address each camera behind one gateway?
  5. 05How fast can one CPU poll all the cameras?
  6. 06How many Modbus sessions does each device have to accept?
  7. 07What register map should every camera use?
  8. 08When is polling from the PLC the wrong design?
  9. 09How do I bring the cell up step by step?
  10. 10Questions

Three Ethernet vision systems, one PLC CPU, and a controls group that wants every inspection result as holding registers: that is a standard Modbus TCP cell, and it needs no protocol converter. The CPU is the client; each vision system is a server listening on TCP port 502. Two decisions decide whether commissioning takes an afternoon or a week: the addressing architecture (a connection per camera, one gateway with unit identifiers, or one vision controller as the single server) and the poll-cycle budget. This guide commits to both, gives the unit-identifier rules, works the polling arithmetic for Ethernet and for a 19200 baud serial line, and ends with a register map and bring-up steps you can run in order.

Can one PLC CPU poll several Modbus TCP vision systems?

Yes. One CPU acting as Modbus TCP client polls as many vision servers as it has client connections — two or three cameras is routine — provided each server answers at its own IP address on TCP port 502.

Three architectures cover every real cell:

  • A connection per camera. Every vision system runs its own Modbus TCP server on the plant or camera network. The PLC opens one client connection to each. Choose this for up to about three Modbus-capable devices.
  • One gateway, many unit identifiers. A serial-to-Ethernet Modbus gateway fronts devices that only speak Modbus RTU. The PLC holds one connection; the unit identifier in each frame picks the slave.
  • One vision controller as the single server. The cameras stream over GigE to a controller that runs the inspections; the PLC polls that one server.

Commit like this: up to three cameras that already serve Modbus TCP — direct connections, one per camera. Four or more cameras, coordinated triggering, or cameras without their own Modbus server — one vision controller in front and a single server to poll. Serial-only devices — the gateway, with unit identifiers doing the routing.

Do I need a serial-to-Ethernet gateway when the cameras are on Ethernet?

No. A serial-to-Ethernet Modbus gateway exists to carry Modbus RTU from an RS-232 or RS-485 line onto Ethernet; a camera that already runs a Modbus TCP server needs only a switch port and an IP address, not a converter.

The gateway reflex comes from the years when every device sat on a shared serial pair and Ethernet ended at a converter. On a native Ethernet camera the converter adds a store-and-forward hop, a second configuration surface and another power supply, and gives you nothing the switch did not already provide. On-device inspection cameras — smart cameras — hold their results internally; the models in this guide pass them to a vision controller over GigE, and the controller carries the Modbus conversation.

What is the unit identifier, and when does it matter?

The unit identifier is the one-byte field in the Modbus TCP header that replaced the RTU slave address; it routes a request to one slave behind a gateway and does no routing on a direct connection.

Every Modbus TCP frame starts with a 7-byte header: 2 bytes of transaction identifier, 2 bytes of protocol identifier (always zero), 2 bytes of length, then the single unit-identifier byte. The transaction identifier increments with each request and comes back unchanged in the response, which is how you pair answers with questions.

On a direct connection, the IP address has already selected the device, so the unit identifier steers nothing — but most servers still check it. Use 1 everywhere; 255 is the other value commonly accepted as meaning the device itself. Behind a gateway it is the slave address, and it is the only thing telling the gateway which camera you meant.

How do I address each camera behind one gateway?

Give every camera its own slave address from 1 to 247 and leave the gateway at one IP address; the PLC sends all requests to that IP on port 502, and the unit identifier — equal to the slave address — picks the camera.

Two wiring flavors exist. A multi-port gateway maps each serial port to its own unit identifier, so two cameras on two ports never see each other's traffic. A single RS-485 multidrop line carries them all, and every frame passes every slave; that is the cheaper cable and the slower bus. Either way, the PLC side stays one TCP session.

That single session is the gateway's real gift: a second master that needs the same data — an HMI, a line analyzer — opens its own client connection to the same address and port, exactly the pattern worked through in running several Modbus TCP clients to one IP and port.

How fast can one CPU poll all the cameras?

On Ethernet, budget about 7 ms per camera for the poll itself, so four cameras close in roughly 30 ms; behind a 19200 baud RS-485 line the same read costs about 24 ms per camera, and the cycle grows in a straight line with every camera you add.

poll_cycle = N × (t_wire + t_device + t_PLC) t_wire = frame_bytes × bits_per_character / baud

Worked example — four cameras, direct Ethernet, one read of 8 holding registers per camera per poll:

  • Request: 7-byte header + 5-byte read command = 12 bytes. Response: 7 + 2 + 8 × 2 = 25 bytes.
  • Wire time at 100 Mbit/s: (12 + 25) × 8 = 296 bits ≈ 3 µs. The cable is not your problem.
  • For turnaround, use 5 ms per camera and 2 ms of PLC client processing as example values; one measurement at commissioning replaces both. Per camera: 5 + 2 = 7 ms.
  • Four cameras in sequence: 4 × 7 = 28 ms per full poll.

Decision: a 100 ms PLC task polls all four with 72 ms of margin. A 10 ms task polls one camera per scan round-robin and refreshes the whole cell every 40 ms.

The same read over Modbus RTU at 19200 baud, 8E1 framing (11 bits per character), on one multidrop line:

  • Characters per second: 19200 / 11 ≈ 1745. Request 8 bytes + response 21 bytes = 29 bytes.
  • t_wire = 29 / 1745 ≈ 16.6 ms, plus a 3.5-character inter-frame gap (about 2 ms) and a 4 ms slave turnaround: roughly 23 ms per camera.
  • Eight cameras: 8 × 23 ≈ 184 ms. If the task cycle is shorter, raise the line to 115200 baud (29 / 10473 ≈ 2.8 ms of wire time per read) or put the cameras on Ethernet.

The same scan-to-result arithmetic, applied to code readers, is worked through in cutting scan-to-flag latency on a PLC link.

How many Modbus sessions does each device have to accept?

Budget four TCP sessions per polled device: the PLC's client connection, the HMI, your commissioning laptop, and one spare; anything less, and the laptop that worked last week locks the PLC out on Monday.

A session is one TCP connection to port 502. That port number is fixed for Modbus in the open Modbus TCP specification, and PLC client functions default to it, so plan on 502 and nothing else. Unit identifiers never separate masters — separate connections do. When a device offers fewer sessions than your budget, stop polling it directly and put the concentrator or the gateway in front, where one server faces the PLC and the second master reads the same registers from that server.

Keep the cameras on their own switch or VLAN. Discovery broadcasts and camera utilities have no business on the plant network, and the segment boundary must pass port 502 in both directions — the rule set is in TCP ports and firewall rules for a vision-to-PLC link.

What register map should every camera use?

Use one identical ten-register map on every server — status, sequence counter, part ID, x, y, angle, cycle time — read in a single request, so one block instance per camera serves the whole cell.

Register (offset from 40001) Content Scaling
0 Status: 0 idle, 1 running, 2 pass, 3 fail —
1 Result sequence counter +1 per inspection
2-3 Part ID 32-bit, high word first
4-5 x position 0.01 mm per count
6-7 y position 0.01 mm per count
8 Angle 0.1° per count
9 Cycle time 1 ms per count

The sequence counter is the handshake. The PLC stores the last value it read; an unchanged counter means the camera has not finished a new part, and the PLC holds the previous verdict instead of re-failing a part it already handled. A 32-bit value spanning two registers needs a word order — write "high word first" into the map comment, because both orderings exist in the field and a swap turns coordinates into nonsense.

When is polling from the PLC the wrong design?

When inspections must be synchronized to motion or to each other: the Modbus poll is asynchronous by nature, so trigger the cameras from a hardwired output or a controller line, let each camera latch its result, and poll the latched values.

Three cases break the direct-poll design:

For the concentrator role, a controller that keeps camera traffic on its own segment and hands the PLC a single server:

Vision controllersHikrobot MV-VC3301H-128G66 I3-8100, 8GB+128G SSD, No PoE, PCIe expansion supported, Incl. VM6200Pro licenseMV-VC3301H-128G66
LAN ports
5+ LAN ports
USB 3 ports
3-4 USB 3 ports
Light outputs
4 built-in channels
Memory
8 GB
$2,419.00View partBuild a system with it

The MV-VC3301H-128G66 has 5+ LAN ports, 4 built-in channels for lights and 8 GB of memory, with the vision software license included. Lights belong to the trigger, not to the poll: strobe them from the controller's channels or from a dedicated light controller so every image is lit identically.

How do I bring the cell up step by step?

Bring it up one layer at a time — addresses first, one camera polled alone, then the rest — and measure the per-camera turnaround before you trust the cycle arithmetic.

  1. Give every vision device a fixed IP address on the camera segment, DHCP off, and write each address and unit identifier into the panel schedule.
  2. From a laptop Modbus test client, read 8 holding registers from each device at its IP on port 502. This proves the server, the port and the wiring before the PLC is involved.
  3. On serial devices, set and record every slave address (1-247) before mounting; duplicates only surface when two slaves answer inside the same scan.
  4. In the PLC, create one client connection per Ethernet device — or one to the gateway — with unit identifier 1 for direct connections and the slave address behind the gateway.
  5. Load the ten-register map on every server, then poll one camera for a minute and watch the sequence counter step once per inspection.
  6. Time one exchange end to end and put your measured turnaround into the budget above.
  7. Add the remaining cameras one at a time, confirming each poll closes before adding the next.
  8. Run the full line rate for an hour with timeout and CRC counters logging, then hand it to production.

For the inspection layer, on-device cameras with fixed lenses keep each station's wiring simple:

Smart cameras & vision sensorsHikrobot MV-SC5060XM-08M-WBN SC5000X series Smart Camera, 6 MP, Mono, 8 mm focal length, M12-mountMV-SC5060XM-08M-WBN
Interface
GigE
Resolution
6-10 MP
$1,629.00View part
Smart cameras & vision sensorsHikrobot MV-SC6050C-08M-XBN SC6000 Series Smart Camera, 5 MP, Color, 8 mm focal length, M12-mount, Multi-color light sourceMV-SC6050C-08M-XBN
Interface
GigE
Resolution
5 MP
$3,449.00 · quotedView and quote

The MV-SC5060XM-08M-WBN is a 6 MP mono smart camera with an 8 mm focal length, M12 mount and GigE; the MV-SC6050C-08M-XBN is the 5 MP color counterpart with a global shutter and a multi-color light source. For the lights, strobe control that sits next to the trigger rather than inside the poll:

Light controllersDigital control box, 4 ch, 200 W, RS232 (LS-CTL-0070)LS-CTL-0070
Output
Constant voltage 24 V
Channels
4 channels
Control
Digital
Feature
Strobe
$549.00View partBuild a system with it

The LS-CTL-0070 is a digital control box with 4 channels, strobe output, 200 W and an RS232 port.

Once you know the camera count and the cycle time you must beat, start the cell in the configurator or send us the layout and we will size the poll loop with you.

Questions

What unit identifier do I use for a direct Modbus TCP connection to a camera?

Use 1. On a direct connection the unit identifier does not route the message — the IP address already selected the device — but most servers still check the field, and a request with an unexpected value is the usual reason a first poll fails. 255 is the other value servers accept for direct access. Behind a gateway the field carries the slave address, 1 to 247, and routing is its whole job.

How many serial cameras can sit behind one Modbus gateway?

The protocol allows slave addresses 1 to 247, but the wire sets the real limit: at 19200 baud with 8E1 framing, one 8-register read costs about 16.6 ms of line time plus gap and turnaround — roughly 23 ms — so eight cameras need about 184 ms per full poll. If your task runs faster than that, raise the line to 115200 baud (about 2.8 ms of line time per read) or put the cameras on Ethernet.

Should the PLC trigger inspections over Modbus?

No. A Modbus write costs a full client cycle and arrives with jitter, so the exposure no longer lines up with the part. Trigger from a PLC digital output or the vision controller's trigger line, let the camera latch the result with a sequence counter, and use Modbus only to read the latched values. Reserve Modbus writes for recipe and part-type changes, where a few tens of milliseconds do not matter.

Do all the cameras need the same register map?

Yes. One identical ten-register map per server means one block instance per camera with only the connection data changing, one fault routine for the whole cell, and a spare camera you can swap in without editing the PLC. Where a camera lacks a value — angle on a presence check, for example — keep the register and write zero; never shift the layout per model.

Can a second master poll the same cameras as the PLC?

Yes, if each device accepts the extra session. Every master opens its own TCP connection to port 502; unit identifiers never separate masters, connections do. Budget four sessions per device — PLC, HMI, commissioning laptop, and a spare — and where a device cannot serve that many, have the extra masters poll the single server in front instead of every camera.