1

I am trying to transfer data from PC to Raspberry PI 3B+ using pymodbus library. I want to send data by Modbus Slave program on my PC. To get the connection I an using CH340 modbus-USB converter, but it's not working. This is the code I am using on raspberry:

from pymodbus.client import ModbusSerialClient
from pymodbus.transaction import ModbusRtuFramer as ModbusFramer

client = ModbusSerialClient(
    framer=ModbusFramer,
    method='rtu',
    port='dev/ttyUSB0',
    baudrate=9600,
    bytesize=8,
    parity="N",
    stopbits=1,
    retries = 5,
    timeout=1,
    debug = True
    )

client.strict = False
client.connect()

res = client.read_holding_registers(address=300, count=1, unit=1)
res.registers

I get an error saying that "failed to connect [{str(self)}]" in line 19 I also get an error on the Modbus Slave program (its saying that device connected to the computer is not working): enter image description here I was trying to do something similar to this video: https://www.youtube.com/watch?v=ZlHqEOmvW6M but version of the pymodbus has changed since that video was made and I dont know what to do now.

Albert B
  • 11
  • 1
  • You’re only showing half your code- to have a viable modbus system you need a master and a slave, but you only show master code above. If you post what you’ve set up on your PC also it may be possible to troubleshoot. – Hayden Eastwood Jun 13 '23 at 05:52

0 Answers0