Be more robust in case we receive non-Unicode characters on the serial port
This commit is contained in:
parent
52a13f0511
commit
a9cb834499
1 changed files with 7 additions and 2 deletions
|
@ -36,8 +36,7 @@ class SerialPlugin(SensorPlugin):
|
||||||
self.serial_lock = threading.Lock()
|
self.serial_lock = threading.Lock()
|
||||||
self.last_measurement = None
|
self.last_measurement = None
|
||||||
|
|
||||||
@staticmethod
|
def _read_json(self, serial_port):
|
||||||
def _read_json(serial_port):
|
|
||||||
n_brackets = 0
|
n_brackets = 0
|
||||||
is_escaped_ch = False
|
is_escaped_ch = False
|
||||||
parse_start = False
|
parse_start = False
|
||||||
|
@ -48,6 +47,12 @@ class SerialPlugin(SensorPlugin):
|
||||||
if not ch:
|
if not ch:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
try:
|
||||||
|
ch = ch.decode()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.warning('Could not decode character: {}'.format(str(e)))
|
||||||
|
output = bytes()
|
||||||
|
|
||||||
if ch.decode() == '{' and not is_escaped_ch:
|
if ch.decode() == '{' and not is_escaped_ch:
|
||||||
parse_start = True
|
parse_start = True
|
||||||
n_brackets += 1
|
n_brackets += 1
|
||||||
|
|
Loading…
Reference in a new issue