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.