From 744a746b7fa9c54afc5573c81de55a8544da1a6b Mon Sep 17 00:00:00 2001 From: klaute Date: Tue, 20 Sep 2016 12:57:28 +0200 Subject: [PATCH] New serial test tool added - serial connection test. --- firmware/firmware.ino | 3 ++- tools/meas.py | 8 +++++--- tools/test.py | 12 ++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 tools/test.py diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 1633ff8..425a04b 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -22,7 +22,7 @@ void setup() pinMode(A1, INPUT); // Init the serial connection - Serial.begin(115200); + Serial.begin(57600); // initialize the command control module cc_init(); @@ -70,6 +70,7 @@ void loop() if (Serial.available() > 0) { uint8_t c = Serial.read() & 0xff; + //Serial.write(c); // TODO cc_processData(c); } diff --git a/tools/meas.py b/tools/meas.py index ff7e224..1a7758b 100644 --- a/tools/meas.py +++ b/tools/meas.py @@ -154,8 +154,11 @@ def cc_dataReceiverThread(): incoming = [] bytesToRead = ser.inWaiting() if bytesToRead > 0: + #print bytesToRead # TODO incoming = list(ser.read(64)) + print incoming # TODO + # 2. process the received data for c in incoming: 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. try: - ser = serial.Serial(d, 115200, timeout=0) + ser = serial.Serial(d, 57600, timeout=0) except: print "ERROR: Can't open the serial device " + device exit(1) @@ -380,6 +383,7 @@ if __name__ == "__main__": while dataSend > 0 and timeout < TIMEOUT_CNT_MAX: thread_lock.acquire() + #ser.write("9") # TODO tmp_messages = copy.deepcopy(cc_received_messages) thread_lock.release() @@ -387,8 +391,6 @@ if __name__ == "__main__": for e in tmp_messages: if e[2] == False: # test for unread message - print "1>>" + str(dataSend) - # process it and set the data to read if e[1] == MSG_TYPE_ANSWER_OK: print "recv: OK" diff --git a/tools/test.py b/tools/test.py new file mode 100644 index 0000000..2a605fa --- /dev/null +++ b/tools/test.py @@ -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()