From f2837f8bfe2b9608afc5794e63baf20d4904d892 Mon Sep 17 00:00:00 2001 From: klaute Date: Tue, 30 Aug 2016 18:48:15 +0200 Subject: [PATCH] The multiplexer control python script works fine now. --- tools/muxctrl.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tools/muxctrl.py b/tools/muxctrl.py index 8226b4d..ec19566 100755 --- a/tools/muxctrl.py +++ b/tools/muxctrl.py @@ -6,11 +6,12 @@ import threading import time import serial import copy +import binascii ############################################################################### parser = argparse.ArgumentParser(description='USB2SerialMux control helper tool.') -parser.add_argument("-g", "--getBaudrate", default=False, help="Get the baudrate for the USART connection.", action='store_true') +parser.add_argument("-b", "--getBaudrate", default=False, help="Get the baudrate for the USART connection.", action='store_true') parser.add_argument("-s", "--setBaudrate", type=int, help="Something like 9600 or 115200.") parser.add_argument("-m", "--getMuxLine", default=False, help="Get the current multiplexer control line state.", action='store_true') parser.add_argument("-l", "--setMuxLine", type=int, help="Something like 0 to 7.") @@ -135,19 +136,21 @@ def cc_dataReceiverThread(): # 1. read byte from serial port into incoming incoming = [] - incoming = ser.read(64) + bytesToRead = ser.inWaiting() + if bytesToRead > 0: + incoming = list(ser.read(64)) - # 2. process the received data - for c in incoming: + # 2. process the received data + for c in incoming: + c = int(binascii.hexlify(c), 16) - # call the cc_state specific function to process the currently received byte - cc_state_fn[cc_state](c) + # call the cc_state specific function to process the currently received byte + cc_state_fn[cc_state](c) - if cc_state not in cc_state_list: - cc_state = CC_STATE_WAIT_SOD1 + if cc_state not in cc_state_list: + cc_state = CC_STATE_WAIT_SOD1 time.sleep(THREAD_LOOP_DELAY_S) - thread_stop = True thread_started = False @@ -210,6 +213,7 @@ def cc_state_fn_get_type(c): if c in msg_type_list: msg_type = c + if msg_type_data_to_read[msg_type] > 0: cc_state = CC_STATE_READ_DATA else: @@ -318,9 +322,9 @@ def sendSerialData(data): global ser - ser.write([ MSG_SOD1, MSG_SOD2 ]) + ser.write(bytearray([ MSG_SOD1, MSG_SOD2 ])) ser.write(bytearray(data)) - ser.write([ MSG_EOD1, MSG_EOD2 ]) + ser.write(bytearray([ MSG_EOD1, MSG_EOD2 ])) ###############################################################################