Serial port not blown properly

I have an RPi (Yes, I know, maybe someone thinks this belongs to the RPi site, but I think that it is related to Linux as a whole, so StackOverflow is the right place) and I talk between some Arduinos over MAX485 using Python3 and pySerial . This works more or less, because I found that I need to make some kind of weird workaround so that everything works "correctly."

If I send data using:

GPIO.output(23, 1) # Pulling transmit pin high to send
comport.write("Some data".encode()) # Writing data
comport.flush() # Flushing the buffer
GPIO.output(23, 0) # Pulling pin down to receive

Arduino receives the data and responds immediately, but since pySerial is somehow not ready yet, it does not return anything and we have a lost packet.

However, if I try like this:

GPIO.output(23, 1)
comport.write("Some data".encode())
time.sleep(.001) # Add some delay of only 1ms
comport.flush()
GPIO.output(23, 0)

. : flush? :

GPIO.output(23, 1)
comport.write("Some data".encode())
time.sleep(.001) # Add some delay
# -- No flush --
GPIO.output(23, 0)

, . , "" flush.

pySerial ? , , sleep () , ( 500 ), .

, , TTL USB, flush ing ( , ), , Linux, .

- , flush , , , ( ), , , .

+4
2

pyserial write_timeout timeout ( ), , , .

, write_timeout, , . , .

, .

UART RPi, , . , , .

USB UART, , FTDI, wirte . , .

( ): 1. tx . 2. tx .

.

, tx . FTDI , ( tx).

+1

, , , MAX485 . , , , .

?

. . - .

enter image description here

, :

Arduino , pySerial - , .

PySerial, , MAX485 GPIO-23.

, Moxa Half Duplex 485 RS-485

enter image description here

, GPIO-23 (MASTER-RTS ) , . , , , .

?

: . GPIO-23 . , , - Arduino , . sleep() , , GPIO-23 , Arduino .

, GPIO-23. SW, . , 100% , python GPIO-23. , HW .

, RS-485, Full Duplex, RS-422 , , RS-232.

+1

Source: https://habr.com/ru/post/1675911/


All Articles