do the whole RS485 DE handling in Python

This commit is contained in:
2019-07-10 13:05:03 +02:00
parent 7c6ebd8d0c
commit 782a4a296b
2 changed files with 31 additions and 2 deletions

26
src/MyRS485.py Normal file
View File

@ -0,0 +1,26 @@
import serial
import serial.serialutil
import ctypes
import wiringpi
import array
import fcntl
import termios
DE_PIN = 0
class MyRS485(serial.Serial):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
wiringpi.wiringPiSetup()
wiringpi.pinMode(DE_PIN, wiringpi.OUTPUT)
self.buf = array.array('h', [0])
def write(self, b):
wiringpi.digitalWrite(DE_PIN, wiringpi.HIGH)
super.write(b)
while True:
fcntl.ioctl(self.fileno(), termios.TIOCSERGETLSR, self.buf, 1)
if self.buf[0] & termios.TIOCSER_TEMT:
break
wiringpi.digitalWrite(DE_PIN, wiringpi.LOW)