So i have been having this problem with an RS485 client for a long time. I have been trying to use UART->485 communication instead of USB->232->485. The latter method works perfectly though as the FTDI provides a perfectly in-sync RTS signal when it decodes the USB packet. This can be used for the RE*/DE flow control pin in the MAX485 chip. However, since I have to use UART, I am running into problems. The Raspberry Pi provides its RTS signal on GPIO17 as ALT3 functionality. However, I have found no way to enable this RTS signal while using pymodbus. Here is my code:-
#!/usr/bin/python
import time, serial
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.transaction import ModbusRtuFramer
client = ModbusClient(port = '/dev/ttyAMA0', retries = 1000, rtscts = True, method = 'rtu', framer = ModbusRtuFramer, baudrate = 19200, stopbits = 1, parity = 'N', bytesize = 8, timeout - 10) #used a very large timeout and a large number of retries in my last ditch attempt to see if it works
val = client.connect()
if not val:
print "Error in Client Connection"
rcv_data = client.read_holding_registers(3902, count = 2, unit = 2)
time.sleep(1/1000000.0)
print("Registers are")
print(rcv_data.registers[0])
print(rcv_data.registers[1])
client.close()
-------------------------------------------------------------------------------------
The pymodbus documentation provides no way to enable the RTS signal. However, since the pymodbus serial client is actually an object of the pyserial object Serial, which allows us to enable RTS ( Serial(...., rtscts = True,..) , can we not do the same for the pymodbus serial client as well?
Help will be really appreciated, I have been stuck here for a long time!
Thank you!