usbpymodbus

pymodbus serial RTU inter-character timeout and USB


USB is a packet protocol: it buffers bytes, then sends a packet. This is causing me a problem because the software I am using (pymodbus) sees an incomplete Modbus Packet in a complete USB packet, and reports a short-packet error ("No Response received from the remote unit/Unable to decode response")

With some devices I can mitigate against this problem by adjusting the USB packet latency to minimum. Other devices/drivers/systems don't offer this adjustment.

Is there a setting in pymodbus (ModbusSerialClient) that allows me to tell it to relax RTU inter-character timeout (which is meaningless in this case), or otherwise allow for USB devices?


Solution

  • ModbusSerialClient takes a parameter 'strict' with default value True, which controls strict RTU timing. For relaxed RTU timing, set strict=False.

    try:
      from pymodbus.client.sync import ModbusSerialClient as ModbusClient
    except:
      from pymodbus.client import ModbusSerialClient as ModbusClient
    
    client = ModbusClient(port='com3',strict=False)
    
    answer = client.read_holding_registers(0XB2,2,unit=8).registers