Dear Luc,
We are using the Modbus_tk in a script, it was working fine. Yang was a collegue of mine and you have communincating with her in the past (4-5 years ago).
Now we encountering some problems.
The script we use:
# Create logger and server
logger = modbus_tk.utils.create_logger(name="console", record_format="%(message)s",level=logging.DEBUG)
server = modbus_rtu.RtuServer(serial.Serial(PORT, baudrate=19200))
server.set_verbose(True)
try:
logger.info("running...")
logger.info("enter 'quit' for closing the server")
def log_data(data):
server, bytes_data = data
logger.info(bytes_data)
hooks.install_hook('modbus_rtu.RtuServer.after_read', log_data)
hooks.install_hook('modbus_rtu.RtuServer.before_write', log_data)
server.start()
print("server started")
slave_1 = server.add_slave(1)
print("slave_1 is added")
slave_1.add_block('block1', cst.HOLDING_REGISTERS, 99, 127)
print("holding registers are added")
slave_1.set_values('block1', 99, initial_regi_values[:127])
The reponse in the logger:
Connected to pydev debugger (build 182.4129.34)
RtuServer COM1 is opened
server started
slave_1 is added
holding registers are added
bytearray(b'\x01\x03\x01+\x00Ou\xca')
Modbus Error: Exception code = 2
b'\x01\x83\x02\xc0\xf1'
bytearray(b'\x02d\x04\xe8,\tS\xf2\xd4\xd1\x00\x19\r\xf4')
handle request failed: Invalid CRC in request
b'\x81\x04'
bytearray(b'\re\x00$\x00o\x00\x08@ >@\x0c\x10')
handle request failed: Invalid CRC in request
b'\x81\x04'
bytearray(b'\xef\x11O\xd4G\xe8\xfd\x82]\x00\x07\x00\x00\x11')
handle request failed: Invalid CRC in request
b'\x81\x04'
bytearray(b'1\x03\xeb\x04D\x06\xf1z\x00p\x05\xe3\x1d\xba')
handle request failed: Invalid CRC in request
b'\x81\x04'
bytearray(b'\x1d\xfb\x1e\xa6\x1c\xaf\xe1')
handle request failed: Invalid CRC in request
b'\x81\x04'
We have connected with a MODSIM-program to the port and we were able to read out the Modbus. It seems that the connection is ok but the reading is incorrect.
What could be the reason of the "handle request failed: Invalid CRC in request"? And is there a way to solve it?
Thanks in advance
Ivo