From e9330d16cc7532e57bfbeb6554fe694da80f1f60 Mon Sep 17 00:00:00 2001
From: Michael DM Dryden <mdryden@chem.utoronto.ca>
Date: Wed, 9 Nov 2016 17:23:17 -0500
Subject: [PATCH] Fix reconnection code.

---
 dstat_interface/dstat_comm.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/dstat_interface/dstat_comm.py b/dstat_interface/dstat_comm.py
index 0a366f7..ac58436 100755
--- a/dstat_interface/dstat_comm.py
+++ b/dstat_interface/dstat_comm.py
@@ -33,15 +33,20 @@ exp_logger = logging.getLogger("dstat.comm.Experiment")
 def _serial_process(ser_port, proc_pipe, ctrl_pipe, data_pipe):
     ser_logger = logging.getLogger("dstat.comm._serial_process")
     
-    ser = serial.Serial(ser_port, baudrate=1000000, timeout=1)
+    ser = delayedSerial(ser_port, baudrate=1000000, timeout=1)
     ser_logger.info("Reattaching DStat udc")
     ser.write("!R") # Send restart command
     ser.close()
     
-    time.sleep(1) # Give OS time to enumerate
+    for i in range(5):
+        time.sleep(1) # Give OS time to enumerate
     
-    ser = serial.Serial(ser_port, baudrate=1000000, timeout=1)
-    ser_logger.info("Connecting")
+        try:
+            ser = delayedSerial(ser_port, baudrate=1000000, timeout=1)
+            ser_logger.info("Connecting")
+            break
+        except serial.SerialException:
+            pass
     
     ser.write("ck") # Keep this to support old firmwares
     
@@ -53,6 +58,7 @@ def _serial_process(ser_port, proc_pipe, ctrl_pipe, data_pipe):
             time.sleep(.5)
             ser.write('!')
         else:
+            ser.write('V')
             break
 
     while True:
-- 
GitLab