do the whole RS485 DE handling in Python
This commit is contained in:
26
src/MyRS485.py
Normal file
26
src/MyRS485.py
Normal 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)
|
||||
|
Reference in New Issue
Block a user