Skip to content

Commit 0e0b152

Browse files
authored
Merge pull request #21 from dherrada/master
Fixed an issue mentioned in issue #19 where a UnicodeError would be raised when there was noise over UART
2 parents 7d0c1fa + 3202b43 commit 0e0b152

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_gps.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ def update(self):
9999
"""
100100
# Grab a sentence and check its data type to call the appropriate
101101
# parsing function.
102-
sentence = self._parse_sentence()
102+
try:
103+
sentence = self._parse_sentence()
104+
except UnicodeError:
105+
return None
103106
if sentence is None:
104107
return False
105108
if self.debug:
@@ -145,7 +148,10 @@ def _parse_sentence(self):
145148
sentence = self._uart.readline()
146149
if sentence is None or sentence == b'' or len(sentence) < 1:
147150
return None
148-
sentence = str(sentence, 'ascii').strip()
151+
try:
152+
sentence = str(sentence, 'ascii').strip()
153+
except UnicodeError:
154+
return None
149155
# Look for a checksum and validate it if present.
150156
if len(sentence) > 7 and sentence[-3] == '*':
151157
# Get included checksum, then calculate it and compare.

0 commit comments

Comments
 (0)