Problems communicating with Modbus devices via USB to rs485.
so I am using some python 3.5 and am using the PyModbus, PySerial
and my code is based on the PyModbus serial example and under windows it works fine and communicates to the Modbus device correctly
when I run my code on the Raspberry Pi3 running Ubuntu mate 16.04.5 LTS, the device is not responding from my code. I first thought the adapter was not installed correctly but after double checking everything, I installed gtkterm and configured the port to /dev/ttyUSB0 9600 8-n-2 and tried sending the hex data to the Modbus and still no reply I then noticed under flow control it has an RS485-HalfDuplex(RTS) setting and under the advanced options if I set the send delay to 20 milliseconds and 10 ms RTS off
now when I try and send the hex modus packet the device responds as expected.
I connected my Oscilloscope and from the python code, it is transmitting some small packet of data randomly looking more like after a timeout when the data is sent. after digging around a bit it seems that some USB to rs485 devices need the RTS to toggle the device to transmit mode and then RTS off to put it back into receive mode.
I also discovered that pySerial has an RS485 setting and have tried these and then the packets being transmitted was more regular and larger before but still much shorter than the gtkterm, and much messing around with the timing helped a bit, I have now gone back to using the original code but putting in
socket.setRTS(1)
time.sleep(0.02)
socket.write(request)
time,sleep(0.1)
socket.setRTS(0)
seems to give me the longest packet picked up on the oscilloscope but the packet is 8.42ms long as where the packet from gtkterm is 9.36ms and taking a glance between the trace of both messages it seems as if the end of the packet is missing. but even if I increase the sleep time before turning off the RTS signal it makes no difference.