Skip to content

Commit f1fd7aa

Browse files
authored
Merge pull request #272 from mathoudebine/fix/269-io-errno-5-no-autodiscovery
2 parents c0b6e85 + 85e6700 commit f1fd7aa

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

library/lcd/lcd_comm.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,27 @@ def get_height(self) -> int:
7474

7575
def openSerial(self):
7676
if self.com_port == 'AUTO':
77-
lcd_com_port = self.auto_detect_com_port()
78-
if not lcd_com_port:
77+
self.com_port = self.auto_detect_com_port()
78+
if not self.com_port:
7979
logger.error(
8080
"Cannot find COM port automatically, please run Configuration again and select COM port manually")
8181
try:
8282
sys.exit(0)
8383
except:
8484
os._exit(0)
85-
logger.debug(f"Auto detected COM port: {lcd_com_port}")
86-
self.lcd_serial = serial.Serial(lcd_com_port, 115200, timeout=1, rtscts=1)
85+
else:
86+
logger.debug(f"Auto detected COM port: {self.com_port}")
8787
else:
88-
lcd_com_port = self.com_port
89-
logger.debug(f"Static COM port: {lcd_com_port}")
90-
self.lcd_serial = serial.Serial(lcd_com_port, 115200, timeout=1, rtscts=1)
88+
logger.debug(f"Static COM port: {self.com_port}")
89+
90+
try:
91+
self.lcd_serial = serial.Serial(self.com_port, 115200, timeout=1, rtscts=1)
92+
except Exception as e:
93+
logger.error(f"Cannot open COM port {self.com_port}: {e}")
94+
try:
95+
sys.exit(0)
96+
except:
97+
os._exit(0)
9198

9299
def closeSerial(self):
93100
try:

0 commit comments

Comments
 (0)