The multiplexer control python script works fine now.

This commit is contained in:
klaute 2016-08-30 18:48:15 +02:00
parent d9546a3120
commit f2837f8bfe

View file

@ -6,11 +6,12 @@ import threading
import time import time
import serial import serial
import copy import copy
import binascii
############################################################################### ###############################################################################
parser = argparse.ArgumentParser(description='USB2SerialMux control helper tool.') 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("-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("-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.") 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 # 1. read byte from serial port into incoming
incoming = [] incoming = []
incoming = ser.read(64) bytesToRead = ser.inWaiting()
if bytesToRead > 0:
incoming = list(ser.read(64))
# 2. process the received data # 2. process the received data
for c in incoming: for c in incoming:
c = int(binascii.hexlify(c), 16)
# call the cc_state specific function to process the currently received byte # call the cc_state specific function to process the currently received byte
cc_state_fn[cc_state](c) cc_state_fn[cc_state](c)
if cc_state not in cc_state_list: if cc_state not in cc_state_list:
cc_state = CC_STATE_WAIT_SOD1 cc_state = CC_STATE_WAIT_SOD1
time.sleep(THREAD_LOOP_DELAY_S) time.sleep(THREAD_LOOP_DELAY_S)
thread_stop = True
thread_started = False thread_started = False
@ -210,6 +213,7 @@ def cc_state_fn_get_type(c):
if c in msg_type_list: if c in msg_type_list:
msg_type = c msg_type = c
if msg_type_data_to_read[msg_type] > 0: if msg_type_data_to_read[msg_type] > 0:
cc_state = CC_STATE_READ_DATA cc_state = CC_STATE_READ_DATA
else: else:
@ -318,9 +322,9 @@ def sendSerialData(data):
global ser global ser
ser.write([ MSG_SOD1, MSG_SOD2 ]) ser.write(bytearray([ MSG_SOD1, MSG_SOD2 ]))
ser.write(bytearray(data)) ser.write(bytearray(data))
ser.write([ MSG_EOD1, MSG_EOD2 ]) ser.write(bytearray([ MSG_EOD1, MSG_EOD2 ]))
############################################################################### ###############################################################################