'Pymodbus error with read_input_register function
I am using pymodbus to test my electronic board. By using the RTU version I don't have any kind of problems, but when I test the TCP part, pymodbus fail and I don't understand why! The version of python is 3.9, and pymodbus is 2.5.3.
My code is:
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
SERVER_HOST = '192.168.1.123'
SERVER_PORT = 502
if __name__ == '__main__':
c = ModbusClient(SERVER_HOST, port=SERVER_PORT, timeout=4)
c.connect()
if not c.is_socket_open():
if not c.connect():
print("unable to connect!")
ver = c.read_input_registers(
address=0x05,
count=1,
unit=1)
assert(not ver.isError())
The error is:
Traceback (most recent call last):
File "/Users/warcomeb/Projects/AMMICROSYSTEMS/LOCCIONI_BatterySimulator_CFirmware/test/test_modbustcp_basic.py", line 138, in <module>
ver = c.read_input_registers(
File "/usr/local/lib/python3.9/site-packages/pymodbus/client/common.py", line 125, in read_input_registers
return self.execute(request)
File "/usr/local/lib/python3.9/site-packages/pymodbus/client/sync.py", line 109, in execute
return self.transaction.execute(request)
File "/usr/local/lib/python3.9/site-packages/pymodbus/transaction.py", line 174, in execute
response, last_exception = self._transact(
File "/usr/local/lib/python3.9/site-packages/pymodbus/transaction.py", line 271, in _transact
packet = self.client.framer.buildPacket(packet)
File "/usr/local/lib/python3.9/site-packages/pymodbus/framer/socket_framer.py", line 206, in buildPacket
data = message.encode()
File "/usr/local/lib/python3.9/site-packages/pymodbus/register_read_message.py", line 33, in encode
return struct.pack('>HH', self.address, self.count)
struct.error: required argument is not an integer
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
