Skip to content

Commit

Permalink
fix(serial): reload corrupt serial drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKevinWeiss committed Dec 16, 2022
1 parent fd657a0 commit f944df6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mm_pal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

__author__ = "Kevin Weiss"
__email__ = "[email protected]"
__version__ = "1.2.0"
__version__ = "1.2.1"

__all__ = ['MmIf',
'MmCmd',
Expand Down
25 changes: 15 additions & 10 deletions mm_pal/serial_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
import time
from typing import Dict
from serial import Serial, PARITY_NONE
from serial import Serial, PARITY_NONE, SerialException
from serial.tools import list_ports


Expand Down Expand Up @@ -133,15 +133,20 @@ def _connect(self, *args, **kwargs):

if _serialports.get(port):
self.logger.debug("Serial port %r already exists", port)
self.dev = _serialports[port]
if 'parity' in kwargs:
self.dev.parity = kwargs['parity']
else:
self.dev.parity = PARITY_NONE
if 'timeout' in kwargs:
self.dev.timeout = kwargs['timeout']
if 'baudrate' in kwargs:
self.dev.baudrate = kwargs['baudrate']
try:
self.dev = _serialports[port]
if 'parity' in kwargs:
self.dev.parity = kwargs['parity']
else:
self.dev.parity = PARITY_NONE
if 'timeout' in kwargs:
self.dev.timeout = kwargs['timeout']
if 'baudrate' in kwargs:
self.dev.baudrate = kwargs['baudrate']
except SerialException:
del _serialports[port]
self.dev = Serial(*args, **kwargs)
_serialports[port] = self.dev
else:
self.dev = Serial(*args, **kwargs)
_serialports[port] = self.dev
Expand Down

0 comments on commit f944df6

Please sign in to comment.