question

edgargw22 avatar image
edgargw22 asked

Modbus: trying to read Serial in register 800

I'm trying to read register 800, Serial [char(6)] via Modbus. I'm not sure what this looks like, but I get "Serial: b'508c'" from the following code. Does this look right to you?

from pymodbus.constants import Defaults
from pymodbus.constants import Endian
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.payload import BinaryPayloadDecoder
Defaults.Timeout = 25
Defaults.Retries = 5
client = ModbusClient('10.186.47.212', port='502')
result = client.read_input_registers(800, 2)
decoder = BinaryPayloadDecoder.fromRegisters \
(result.registers, byteorder=Endian.Big)
Serial = decoder.decode_string(size=6)
print("Serial: ",Serial)

Thank you.

Raspberry PiModbus TCP
1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

btw, what is this string supposed to look like?
0 Likes 0 ·
1 Answer
elvis avatar image
elvis answered ·

from pymodbus.constants import Defaults
from pymodbus.constants import Endian
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.payload import BinaryPayloadDecoder


client = ModbusClient(192.168.20.156, port='502')

SerialSystem = client.read_input_registers(800, unit=100)
decoder = BinaryPayloadDecoder.fromRegisters(SerialSystem.registers, byteorder=Endian.Big)
SerialSystem = decoder.decode_16bit_int()
print(f" Serial (System)........... {SerialSystem:.0f}", sep="")


Serial (System)........... 25652


2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.