rearrange serial

This commit is contained in:
Jens Ullmert 2022-07-27 17:43:02 +02:00
parent bf653c4d46
commit 97f07b65ce

View File

@ -101,33 +101,32 @@ def sendDMX(data):
global DMXRDM global DMXRDM
global DMXSLP global DMXSLP
# UART configuration and definition
DMXSER = serial.Serial('/dev/serial0', baudrate=250000, timeout=(DMXSLP/1000.0), stopbits=serial.STOPBITS_TWO, bytesize=8)
while True: while True:
with serial.Serial('/dev/serial0', baudrate=250000, timeout=(DMXSLP/1000.0), stopbits=serial.STOPBITS_TWO, bytesize=8) as DMXSER:# UART configuration and definition DMXSER.reset_input_buffer()
#DMXSER.cancel_read() GPIO.output(18, GPIO.LOW)
# GPIO_18 to switch RS-485 driver (IC1) to TX-mode wr = bytearray(DMXDATA)
GPIO.output(18, GPIO.HIGH)
print("start read for ", DMXSLP, "ms")
# send reset DMXRDM = DMXSER.read(400)
DMXSER.send_break(DMXRST / 1000000.0) print("end read, input is ", DMXRDM)
# break-time # GPIO_18 to switch RS-485 driver (IC1) to TX-mode
time.sleep(DMXBRK / 1000000.0) GPIO.output(18, GPIO.HIGH)
# send complete data array # send reset
DMXSER.write(bytearray(DMXDATA)) DMXSER.send_break(DMXRST / 1000000.0)
# break-time
time.sleep(DMXBRK / 1000000.0)
# GPIO_18 to switch RS-485 driver (IC1) to RX-mode # send complete data array
DMXSER.reset_input_buffer() DMXSER.write(wr)
GPIO.output(18, GPIO.LOW)
# Sleep between TX packages, use time to get RDM packages
print("start read for ", DMXSLP, "ms")
DMXRDM = DMXSER.read(400)
print("end read, input is ", DMXRDM)