Skip to content

Crash when attempting to add input registers #2

@codar030

Description

@codar030

First of all to thank you for your contribution. Your tutorials have helped me a lot to understand the protocol.

I am trying to replicate the same tempSensors project. I used your code for the Modbus server with a simple client code.
My problem is that I get the following error when reviewing the server query:

DEBUG:pymodbus.factory:Factory Request[ReadInputRegistersRequest: 4]
DEBUG:pymodbus.datastore.context:validate: fc-[4] address-1: count-1
DEBUG:pymodbus.datastore.context:getValues fc-[4] address-1: count-1
Unhandled Error
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/twisted/python/log.py", line 103, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/usr/local/lib/python3.5/dist-packages/twisted/python/log.py", line 86, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/local/lib/python3.5/dist-packages/twisted/python/context.py", line 122, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/local/lib/python3.5/dist-packages/twisted/python/context.py", line 85, in callWithContext
return func(*args,**kw)
--- ---
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
why = selectable.doRead()
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 243, in doRead
return self._dataReceived(data)
File "/usr/local/lib/python3.5/dist-packages/twisted/internet/tcp.py", line 249, in _dataReceived
rval = self.protocol.dataReceived(data)
File "/usr/local/lib/python3.5/dist-packages/pymodbus/server/asynchronous.py", line 70, in dataReceived
unit=units)
File "/usr/local/lib/python3.5/dist-packages/pymodbus/framer/socket_framer.py", line 153, in processIncomingPacket
self._process(callback)
File "/usr/local/lib/python3.5/dist-packages/pymodbus/framer/socket_framer.py", line 181, in _process
callback(result) # defer or push to a thread?
File "/usr/local/lib/python3.5/dist-packages/pymodbus/server/asynchronous.py", line 91, in _execute
self._send(response)
File "/usr/local/lib/python3.5/dist-packages/pymodbus/server/asynchronous.py", line 100, in _send
pdu = self.framer.buildPacket(message)
File "/usr/local/lib/python3.5/dist-packages/pymodbus/framer/socket_framer.py", line 206, in buildPacket
data = message.encode()
File "/usr/local/lib/python3.5/dist-packages/pymodbus/register_read_message.py", line 79, in encode
result += struct.pack('>H', register)
struct.error: required argument is not an integer

DEBUG:pymodbus.server.asynchronous:Client Disconnected: [Failure instance: Traceback: <class 'struct.error'>: required argument is not an integer.

It seems that the register_read_message method requires an integer.
I don't know if you could help me with this problem.

Thank you

the client code:

from pymodbus.client.sync import ModbusTcpClient as ModbusClient

import logging

FORMAT = ('%(asctime)-15s %(threadName)-15s '
'%(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
logging.basicConfig(format=FORMAT)
log = logging.getLogger()
log.setLevel(logging.DEBUG)

client = ModbusClient('localhost', port=502)
connection = client.connect()
print("Connected: " + str(connection))

request = client.read_input_registers(0, 1)

if request.isError():
# handle error, log?
print('Modbus Error:', request)
else:
result = request.registers
print(result)

client.close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions