From a92a327f68003aa2cd4a6939700686e591bff565 Mon Sep 17 00:00:00 2001 From: Mark Goodall Date: Mon, 15 Jun 2015 19:52:14 +0100 Subject: [PATCH] Added support for Linux in the SerialCom.py connection function The connect would previously only work immediately preceding a download (on Debian Jessie). This was solved by connecting first with rtscts enabled, which triggers something to allow messages to be received. I think the board is being reset on each connection, this is a workaround. --- mDrawGui/SerialCom.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mDrawGui/SerialCom.py b/mDrawGui/SerialCom.py index 47fa4de..6397f94 100644 --- a/mDrawGui/SerialCom.py +++ b/mDrawGui/SerialCom.py @@ -4,6 +4,8 @@ import serial import platform import threading +import time +import platform try: import _winreg @@ -42,7 +44,6 @@ def __init__(self,ser,cb): def run(self): while self.running: l = self.ser.readline() - print l self.cb(l) class serialCom(): @@ -52,6 +53,12 @@ def __init__(self,rxCallback): return def connect(self,port,baud=115200): + if "Linux" in platform.system(): + connection = serial.serial_for_url(port, baud, timeout=2, rtscts=True) + time.sleep(0.1) + connection.close() + time.sleep(2) + self.ser = serial.Serial(port, baud) self.rxth = serialRead(self.ser,self.rxcb) self.rxth.setDaemon(True) @@ -68,6 +75,7 @@ def send(self,msg): if self.ser == None: return self.ser.write(msg) + self.ser.flush()