Selection guide
Choosing a Python 3 library for Modbus TCP reads from a PLC
Short answer
For a Productivity 2000 or any PLC with a Modbus TCP server, read it from Python 3 with pyModbusTCP or pymodbus over port 502; a current cpppo release also runs on Python 3. Prove the TCP path, then verify one mapped register's area, offset, width and word order against the live value before polling the whole map.
On this page
- Which Python 3 library do I pick for PLC reads?
- How do I prove the network path before touching registers?
- Why does one register read prove the mapping?
- How do I decode a 32-bit float from two registers?
- What order do I scale up and add writes?
- When does the PLC act as the Modbus client instead?
- Questions asked
The Productivity 2000 speaks Modbus TCP from its CPU, so your Python 3 application should use a Modbus TCP client library, not a ported Python 2-era EtherNet/IP driver. Choose pyModbusTCP or pymodbus, both current Python 3 libraries; if you must keep an existing cpppo application, the current cpppo release also supports Python 3. The order that works: select the library, prove the TCP path to port 502, verify one mapped register against the live value, then scale up. Do not start by converting old libraries or trying several drivers against live outputs; that never fixes a missing network path or a wrong register interpretation.
Which Python 3 library do I pick for PLC reads? #
Pick pyModbusTCP or pymodbus for Modbus TCP, and keep a current cpppo release only when you specifically need its EtherNet/IP services under Python 3. Both Modbus libraries are maintained Python 3 packages; install them in an isolated environment and record the interpreter and package versions you tested. An EtherNet/IP-capable library is not a universal PLC tag driver: two devices can share the protocol while exposing different objects and services. If you have no specific EtherNet/IP requirement, take the Modbus TCP branch, since the controller already runs a Modbus TCP server.
| Application requirement | First choice | Check before proceeding |
|---|---|---|
| Read and write mapped PLC data | Modbus TCP with pyModbusTCP or pymodbus | PLC server configuration, address mapping, installed library API |
| Existing cpppo application | A Python 3-compatible cpppo release | Whether its client services match what your code calls |
| Existing pycomm application | Review its protocol assumptions first | Whether it implements the needed services, not just whether it imports |
If your plan is a Python data-collection station beside the controller, the same choice applies when that code runs on an industrial mini PC acting as gateway or data logger.
How do I prove the network path before touching registers? #
Confirm the PLC's configured IP address and Modbus TCP server settings in the engineering project, then open a TCP connection to port 502 from your computer. The default Modbus TCP port is 502, and the server must be enabled in the CPU configuration before any client connects. Compare the controller's actual endpoint with your computer's active interface and routing; do not copy settings from another machine.
The failure mode tells you where to look: a connection refusal means a reachable address with no accepting service (server disabled, wrong port), while a timeout points to routing, filtering or a wrong address. A successful ping proves neither Modbus availability nor correct mapping. Fix the path here, before any address arithmetic.
Why does one register read prove the mapping? #
One verified read proves the data area, the offset convention, the width and the word order all at once, and every one of those can silently corrupt a value. Pick one noncritical PLC value visible in the engineering software and record its Modbus assignment: data area, address, length and access permission together. Modbus distinguishes bit-oriented areas from register-oriented areas, and a valid numeric address in the wrong area returns unrelated data or an exception; a read that crosses a gap in the map returns exception 02, as covered in Modbus exception 02 when a read crosses a register map gap.
Check whether the PLC documentation uses reference-style register labels while your client expects protocol offsets, and translate once at the mapping boundary. Repeatedly nudging an offset until a plausible value appears hides a wrong mapping.
How do I decode a 32-bit float from two registers? #
Read the raw registers first, then decode against the mapped PLC type. Modbus registers carry 16-bit units, not types: a REAL occupies two registers and its word order must be confirmed against a known live value. Worked example: the PLC displays a tank level of 12.5 in the engineering software, and your client returns raw registers 0x4148 and 0x0000. Decode as big-endian word order: 0x41480000 is a 32-bit IEEE 754 float with sign 0, exponent 0x82 (130, so 2^3), mantissa 1.5625, giving 1.5625 × 8 = 12.5. It matches, so the word order is confirmed. Repeat with a second approved value, because two wrong registers can also decode to a plausible number. The same decoding step decides a CLICK PLC float read over Modbus TCP, as shown in Reading a CLICK PLC float over Modbus TCP in an HMI.
For a multi-register value that can change mid-read, have the PLC serve a coherent snapshot or a consistency flag for values that must agree.
What order do I scale up and add writes? #
Add the remaining reads in small groups, checking each mapping against the engineering display, and keep the application read-only until every read is verified. Flag failed reads as invalid; retaining the last number without marking it stale makes a disconnected application look healthy. Reconnect with bounded retries, not a tight loop that loads the controller. Introduce writes only afterward, to an approved noncritical destination with defined limits and PLC-side validation, following Safe Modbus writes to PLC output registers from SCADA. Keep a mapping table of PLC tag, Modbus area, client offset, width, encoding, units and access permission, and pin the tested package versions.
If you later move from a script to a full OPC UA path instead, the architecture in Where an OPC UA server sits when Python reads PLC data applies, but for direct Modbus TCP reads no server layer is needed.
When does the PLC act as the Modbus client instead? #
When the PLC must poll other devices rather than be polled, the Productivity 2000 CPU can connect to 16 Modbus TCP server devices as a client. That role is configured in the PLC project, and it is independent of your Python reads: the same CPU serves your Python client on port 502 while acting as a client elsewhere, within its documented connection limits.
Questions asked
Does cpppo run on Python 3?
Yes, the current cpppo release supports Python 3, so an existing cpppo application does not force you to stay on Python 2. Its strength is EtherNet/IP, so for plain register reads a Modbus TCP client such as pyModbusTCP or pymodbus is the simpler choice.
Can I keep using pycomm with Python 3?
Check which protocol services your existing pycomm code calls before deciding. A package that imports successfully under Python 3 has not proved it implements the controller objects and services your application used. If the application only reads and writes mapped tags, moving it to Modbus TCP removes that dependency.
How many Modbus TCP server devices can a Productivity 2000 CPU connect to as a client?
That limit is for connections the PLC initiates; it is separate from the number of Python clients the PLC's own server side accepts, which the manual's server section covers.
Why does my read return a plausible but wrong float?
Two 16-bit registers in the wrong word order still decode to a valid-looking float. Capture the raw registers, swap the word order once in your decoding, and compare with a value the engineering software displays. Repeat with a second known value; one plausible number does not prove the word order.