Could someone help me to fix this error while trying to connect RPi 3 B+ to an inverter in order to read data via CH340G usb module, Below the used code :

from pymodbus.client.sync import ModbusSerialClient as ModbusClient  
from pymodbus.register_read_message import ReadInputRegistersResponse  
client = ModbusClient(method='rtu', port='/dev/ttyUSB0', stopbits=1, bytesize=8, parity='N', baudrate=9600, timeout=0.3)  
value=client.read_input_registers(2301, 4, unit=0x01)  

Error message:

Traceback (most recent call last): File "/home/iot/Desktop/test.py", line 6, in value=client.read_input_registers(2301, 8, unit=0x01)                           File "/usr/local/lib/python3.6/dist-packages/pymodbus/client/common.py", line 125, in read_input_registers – return self.execute(request)   
File "/usr/local/lib/python3.6/dist-packages/pymodbus/client/sync.py", line 105, in execute raise ConnectionException("Failed to connect[%s]" % (self.str())) pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[ModbusSerialClient(rtu baud[9600])]
  • There is no way to answer this question given the information provided. You need to provide all relevant information up front. – joan May 2 '19 at 8:54
  • hi, please specifie what kind of informations i can share with you – Brahim May 2 '19 at 9:03
  • 2
    Possible duplicate of Modbus communication – Milliways May 2 '19 at 9:16
  • What is the difference to the question you asked 14 hours before? – Ingo May 2 '19 at 9:34
  • 1
    It is not a duplicate as the error described there was solved by the answer given there. This is an issue that came up after that... thus a new question, which I suggested the OP to post it as such. – Ghanima May 2 '19 at 13:27


Setup Rpi3B+ config = CH340 USB/TTL adapter UART connfig = /dev/ttyUSB0, 96008N1, timeout = 0.3

Error = "/usr/local/lib/python3.6/dist-packages/pymodbus/client/sync.py", line 105 failed to connect


Rpi CH340 seems not able to connect to pymodus. Suggest to first do Rpi/CH340 side loopback test.


Pymodbus A Python Modbus Stack - 2018oct23

Modbus communication RpiSE Post - 2018may02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.