@@ -76,7 +76,8 @@ def openSerial(self):
7676 if self .com_port == 'AUTO' :
7777 lcd_com_port = self .auto_detect_com_port ()
7878 if not lcd_com_port :
79- logger .error ("Cannot find COM port automatically, please run Configuration again and select COM port manually" )
79+ logger .error (
80+ "Cannot find COM port automatically, please run Configuration again and select COM port manually" )
8081 try :
8182 sys .exit (0 )
8283 except :
@@ -95,12 +96,7 @@ def closeSerial(self):
9596 pass
9697
9798 def WriteData (self , byteBuffer : bytearray ):
98- try :
99- self .lcd_serial .write (bytes (byteBuffer ))
100- except serial .serialutil .SerialTimeoutException :
101- # We timed-out trying to write to our device, slow things down.
102- logger .warning ("(Write data) Too fast! Slow down!" )
103-
99+ self .WriteLine (bytes (byteBuffer ))
104100
105101 def SendLine (self , line : bytes ):
106102 if self .update_queue :
@@ -116,14 +112,29 @@ def WriteLine(self, line: bytes):
116112 except serial .serialutil .SerialTimeoutException :
117113 # We timed-out trying to write to our device, slow things down.
118114 logger .warning ("(Write line) Too fast! Slow down!" )
115+ except serial .serialutil .SerialException :
116+ # Error writing data to device: close and reopen serial port, try to write again
117+ logger .error (
118+ "SerialException: Failed to send serial data to device. Closing and reopening COM port before retrying once." )
119+ self .closeSerial ()
120+ self .openSerial ()
121+ self .lcd_serial .write (line )
119122
120123 def ReadData (self , readSize : int ):
121124 try :
122125 response = self .lcd_serial .read (readSize )
123- #logger.debug("Received: [{}]".format(str(response, 'utf-8')))
124- except serial .serialutil .SerialException :
125- # We timed-out trying to read to our device, slow things down.
126+ # logger.debug("Received: [{}]".format(str(response, 'utf-8')))
127+ return response
128+ except serial .serialutil .SerialTimeoutException :
129+ # We timed-out trying to read from our device, slow things down.
126130 logger .warning ("(Read data) Too fast! Slow down!" )
131+ except serial .serialutil .SerialException :
132+ # Error writing data to device: close and reopen serial port, try to read again
133+ logger .error (
134+ "SerialException: Failed to read serial data from device. Closing and reopening COM port before retrying once." )
135+ self .closeSerial ()
136+ self .openSerial ()
137+ return self .lcd_serial .read (readSize )
127138
128139 @staticmethod
129140 @abstractmethod
@@ -348,7 +359,7 @@ def DisplayRadialProgressBar(self, xc: int, yc: int, radius: int, bar_width: int
348359 bar_image = bar_image .crop (box = bbox )
349360
350361 # Draw progress bar
351- pct = (value - min_value )/ (max_value - min_value )
362+ pct = (value - min_value ) / (max_value - min_value )
352363 draw = ImageDraw .Draw (bar_image )
353364
354365 # PIL arc method uses angles with
0 commit comments