do the whole RS485 DE handling in Python
This commit is contained in:
@ -4,6 +4,7 @@ import RS485Ext
|
||||
import RegisterDatapoint
|
||||
from pymodbus.client.sync import ModbusSerialClient
|
||||
import wiringpi
|
||||
import MyRS485
|
||||
|
||||
|
||||
ERROR_PIN = 29
|
||||
@ -19,8 +20,10 @@ class CommunicationProcessor(threading.Thread):
|
||||
self.daemon = True
|
||||
|
||||
def __getSerial(self):
|
||||
return RS485Ext.RS485Ext(port=self.config.serialPort, baudrate=self.config.serialBaudRate, stopbits=1,
|
||||
timeout=1)
|
||||
# return RS485Ext.RS485Ext(port=self.config.serialPort, baudrate=self.config.serialBaudRate, stopbits=1,
|
||||
# timeout=1)
|
||||
return MyRS485.MyRS485(port=self.config.serialPort, baudrate=self.config.serialBaudRate, stopbits=1,
|
||||
timeout=1)
|
||||
|
||||
|
||||
def run(self):
|
||||
|
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