Read Modbus TCP holding/input registers from a device using pymodbus

domain: pymodbus.readthedocs.io · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. pip install pymodbus and import the sync client with: from pymodbus.client import ModbusTcpClient
  2. Instantiate client = ModbusTcpClient('192.168.1.100', port=502) and call client.connect()
  3. Read holding registers with result = client.read_holding_registers(address=0, count=10, slave=1); use read_input_registers for function code 0x04
  4. Check result.isError() before use; on success read values from result.registers (list of 16-bit unsigned ints)
  5. For 32-bit floats/ints spanning multiple registers, decode with pymodbus.payload.BinaryPayloadDecoder.fromRegisters(result.registers, byteorder=Endian.BIG)
  6. Call client.close() when done, or use AsyncModbusTcpClient for polling multiple devices concurrently

Known gotchas

Related routes

Read Modbus RTU holding registers over a serial connection using pymodbus
pymodbus.readthedocs.io · 6 steps · unrated
Read inverter registers from a SunSpec-compliant device using Modbus TCP
sunspec.org · 5 steps · unrated
Read Modbus Holding Registers (function code 03) vs Input Registers (function code 04) with correct addressing
iot · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans