New serial test tool added - serial connection test.

This commit is contained in:
klaute 2016-09-20 12:57:28 +02:00
parent 5149646717
commit 744a746b7f
3 changed files with 19 additions and 4 deletions

View file

@ -22,7 +22,7 @@ void setup()
pinMode(A1, INPUT); pinMode(A1, INPUT);
// Init the serial connection // Init the serial connection
Serial.begin(115200); Serial.begin(57600);
// initialize the command control module // initialize the command control module
cc_init(); cc_init();
@ -70,6 +70,7 @@ void loop()
if (Serial.available() > 0) if (Serial.available() > 0)
{ {
uint8_t c = Serial.read() & 0xff; uint8_t c = Serial.read() & 0xff;
//Serial.write(c); // TODO
cc_processData(c); cc_processData(c);
} }

View file

@ -154,8 +154,11 @@ def cc_dataReceiverThread():
incoming = [] incoming = []
bytesToRead = ser.inWaiting() bytesToRead = ser.inWaiting()
if bytesToRead > 0: if bytesToRead > 0:
#print bytesToRead # TODO
incoming = list(ser.read(64)) incoming = list(ser.read(64))
print incoming # TODO
# 2. process the received data # 2. process the received data
for c in incoming: for c in incoming:
c = int(binascii.hexlify(c), 16) c = int(binascii.hexlify(c), 16)
@ -289,7 +292,7 @@ def openSerialDevice(d):
# Why 115200? Because the host defines the baudrate for the USB serial connection. # Why 115200? Because the host defines the baudrate for the USB serial connection.
try: try:
ser = serial.Serial(d, 115200, timeout=0) ser = serial.Serial(d, 57600, timeout=0)
except: except:
print "ERROR: Can't open the serial device " + device print "ERROR: Can't open the serial device " + device
exit(1) exit(1)
@ -380,6 +383,7 @@ if __name__ == "__main__":
while dataSend > 0 and timeout < TIMEOUT_CNT_MAX: while dataSend > 0 and timeout < TIMEOUT_CNT_MAX:
thread_lock.acquire() thread_lock.acquire()
#ser.write("9") # TODO
tmp_messages = copy.deepcopy(cc_received_messages) tmp_messages = copy.deepcopy(cc_received_messages)
thread_lock.release() thread_lock.release()
@ -387,8 +391,6 @@ if __name__ == "__main__":
for e in tmp_messages: for e in tmp_messages:
if e[2] == False: # test for unread message if e[2] == False: # test for unread message
print "1>>" + str(dataSend)
# process it and set the data to read # process it and set the data to read
if e[1] == MSG_TYPE_ANSWER_OK: if e[1] == MSG_TYPE_ANSWER_OK:
print "recv: OK" print "recv: OK"

12
tools/test.py Normal file
View file

@ -0,0 +1,12 @@
import serial, sys
port = "/dev/ttyUSB0"
baudrate = 57600
ser = serial.Serial(port,baudrate,timeout=0.001)
while True:
ser.write(bytearray([0x3c, 0x3e, 0x10, 0x0d, 0x0a]))
if ser.inWaiting() > 0:
data = list(ser.read(64))
print data
sys.stdout.flush()