Reputation: 1
I have a Python script to monitor an electronic device via Modbus. I use pyModbus library for that. Till now I worked with devices with ModBus implemented over an RS485 interface, so I use an USB-RS485 dongle on the PC side. It works fine. These days, we are working with a device without RS485 interface. But to keep testing funcionality, we still have ModBus implemented but over TTL (Directly to the microcontroller pins). It should be as easy as changing the USB-RS485 dongle by a USB-TTL one. I confirm this works for SW like ModBus Poll, but when I exceute my Python script, I get the following error:
*0
Cleanup recv buffer before send: 0x44
Traceback (most recent call last):
File "C:\Users\xtorres\PycharmProjects\MonTouch\main.py", line 52, in <module>
teclatFilt = equip.read_holding_registers(address=regKeyPressed, count=1,
slave=1).registers[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'ModbusIOException' object has no attribute 'registers'
Process finished with exit code 1*
The script is reading a couple of registers periodically to check for any change on them. I first open the port: *equip = ModbusSerialClient(port=portComMB, baudrate=9600, parity='N', stopbits=1, timeout=0.1) * and then read the two registers: teclat = equip.read_holding_registers(address=regKeyboard, count=1, slave=1).registers[0] print(teclat) teclatFilt = equip.read_holding_registers(address=regKeyPressed, count=1, slave=1).registers[0] print(teclatFilt)
The first zero is the value of the register, so it reads one register but looks like the buffer is not cleared. My guess is that it has something to do with hardware handshake. I read in this old post (https://github.com/pymodbus-dev/pymodbus/issues/33) to use client.socket.setRTS = 1, but setRTS seems to be no longer implemented.
I've tried adding a time.sleep (1) sentence after each read to add a 1 second delay, with the following result. *0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 0 Cleanup recv buffer before send: 0x44 Traceback (most recent call last): File "C:\Users\xtorres\PycharmProjects\MonTouch\main.py", line 52, in teclat = equip.read_holding_registers(address=regKeyboard, count=1, slave=1).registers[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'ModbusIOException' object has no attribute 'registers' *
I tried, just for check, to open the port, read a register and then close it again. This for both registers. This is the result: *0 0 0 0 0 Traceback (most recent call last): File "C:\Users\xtorres\PycharmProjects\MonTouch\main.py", line 56, in teclatFilt = equip.read_holding_registers(address=regKeyPressed, count=1, slave=1).registers[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'ModbusIOException' object has no attribute 'registers'
Process finished with exit code 1*
Upvotes: 0
Views: 52