Skip to main content
. 2023 Jun 18;23(12):5694. doi: 10.3390/s23125694
Listing 1. Code snippet using pyModbusTCP to extract a variable from a PLC.
c = ModbusClient(host=PLC_IP, port=502, unit_id=1, auto_open=True)
regs = c.read_input_registers(1,8)
last_2bytes_registers = (regs[6] << 16) + regs[7]
4bytesregister = struct.pack(’>L’, last_2bytes_registers)
value_float = struct.unpack(’>f’, 4bytesregister)[0]