-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Versions
- Python: 3.8.1
- OS: Linux
- Pymodbus: 2.5.1
- Modbus Hardware (if used):
MCU via CP2102 (USB)
Rockwell, Siemens PLCs (FTDI Adapter)
ESP32 over UART (FTDI Adapter)
Pymodbus Specific
- Client: rtu - sync
Description
This issue was identified as a upstream issue with pymodbus from Home Assistant's Modbus Component.
This issue emerged in Home Assistant 2021.5, when the pymodbus library was updated from 2.3.0 to 2.5.1.
In pymodbus 2.3.0 a Modbus device connected over serial worked but often produced an error on startup in Home Assistant:
Cleanup recv buffer before send: 0x4d 0xfb .
After this error occurred the Modbus client would continue to function correctly and the error would not occur again. Communication between the modbus device functioned as expected.
In pymodbus 2.5.1, serial devices do not work after after the first modbus command. The first command always works but this error is produced and all future modbus commands fail:
2021-05-11 02:10:25 DEBUG (SyncWorker_1) [pymodbus.client.sync] New Transaction state 'SENDING'
2021-05-11 02:10:25 WARNING (SyncWorker_1) [pymodbus.client.sync] Cleanup recv buffer before send: 0x4d 0xfb
2021-05-11 02:10:25 ERROR (SyncWorker_1) [homeassistant.components.modbus.modbus] Pymodbus: Modbus Error: [Input/Output] No Response received from the remote unit/Unable to decode response
Reverting back to pymodbus 2.30 fixes the issue.
It is possible this issue is related: #510
This is a significant issue, as Modbus RTU does not work after the initial command.
Testing was conducted with USB UART connections and RS485 serial connections to several microcontrollers and PLCs.
Speaking with @janiversen, (maintainer of Home Assistant Modbus Component) we identified the issue to be caused by updating to pymodbus 2.5.1.
Code and Logs
Although configuration applies to Home Assistant, I have included it for reference. NOTE: I am not using pymodbus directly, when testing.
modbus:
- name: Curtain Controller
type: serial
method: rtu
port: /dev/serial/by-id/usb-www.freetronics.com_0003_95437313934351505191-if00
baudrate: 9600
stopbits: 1
bytesize: 8
parity: N
timeout: 10
switches:
#Curtain Controller
- name: "Bedroom Curtain - UP"
slave: 1
address: 0
write_type: coil
- name: "Bedroom Curtain - Down"
slave: 1
address: 1
write_type: coil
- name: "Bedroom Curtain - Stop"
slave: 1
address: 2
write_type: coil