Raspberry PI writing to RS485 driver, DIR pin not holding state - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Raspberry PI writing to RS485 driver, DIR pin not holding state (/thread-30640.html) |
Raspberry PI writing to RS485 driver, DIR pin not holding state - zazas321 - Oct-29-2020 Hello. I am writing data to my modbus DRIVER and learning about modbus in general. I am using logic analyzer to check my signals. I have noticed a very strange behaviour of my DIR pin. Before I send data to RS485 driver, I toggle DIR pin HIGH and keep it HIGH until the data transfer is finished. The code: # \x02 - trigger scanning # \x03 after scanning is done import serial import RPi.GPIO as GPIO import time sendSerial = serial.Serial ("/dev/serial0", 9600) GPIO.setmode(GPIO.BOARD) # Use physical pin numbering GPIO.setup(16, GPIO.OUT) # Set pin 10 to be an input pie to be pulled low (off) GPIO.output(16,1) sendSerial.write (str.encode("hello")) GPIO.output(16,0) print("done") sendSerial.close()And the signal analzyer shows: https://ibb.co/xsJR28b As you can see from the image above, the DIR pin does not want for the serial write to finish I have tried to add : sendSerial.flush() after the writing but it looks even more strange: https://ibb.co/qy0CDXv Now its holding DIR pin for way too long. Can someone help me understand this strange behaviour and how to fix it? RE: Raspberry PI writing to RS485 driver, DIR pin not holding state - deanhystad - Oct-29-2020 Serial I/O is buffered. You usually don't want to wait for the write to complete. I was looking at the PySerial documentation and it looks like you could loop until out_waiting is zero if waiting until done is important. RE: Raspberry PI writing to RS485 driver, DIR pin not holding state - zazas321 - Oct-30-2020 (Oct-29-2020, 06:46 PM)deanhystad Wrote: Serial I/O is buffered. You usually don't want to wait for the write to complete. I was looking at the PySerial documentation and it looks like you could loop until out_waiting is zero if waiting until done is important. Its not that I want to wait. The rs485 driver requires me to hold the DIR pin high untill all bytes are transmittet.But as you can see from the examples of code I have posted above , the program wont let me do it. How can i build a proper modbus structure then? From what I undestood, the serial.flush() function should do the job but it does not |