diff --git a/Python/sock.py b/Python/sock.py index ac1f8d1..534e34c 100644 --- a/Python/sock.py +++ b/Python/sock.py @@ -101,33 +101,32 @@ 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() - - # GPIO_18 to switch RS-485 driver (IC1) to TX-mode - GPIO.output(18, GPIO.HIGH) - - # send reset - DMXSER.send_break(DMXRST / 1000000.0) - - # break-time - time.sleep(DMXBRK / 1000000.0) - - # send complete data array - DMXSER.write(bytearray(DMXDATA)) - - - - - # 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) + DMXSER.reset_input_buffer() + GPIO.output(18, GPIO.LOW) + + wr = bytearray(DMXDATA) + + print("start read for ", DMXSLP, "ms") + DMXRDM = DMXSER.read(400) + print("end read, input is ", DMXRDM) + + # GPIO_18 to switch RS-485 driver (IC1) to TX-mode + GPIO.output(18, GPIO.HIGH) + + # send reset + DMXSER.send_break(DMXRST / 1000000.0) + + # break-time + time.sleep(DMXBRK / 1000000.0) + + # send complete data array + DMXSER.write(wr) + +