rearrange serial

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

View File

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