From 6532d19a83f5f5e86ddcc9537b051da147986624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sun, 9 Dec 2018 15:14:45 +0000 Subject: sdcodefree: allows an arbitrary number of null-bytes before challenge. This appears to be quite variable, and this should make it more reliable. --- glucometerutils/drivers/sdcodefree.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/glucometerutils/drivers/sdcodefree.py b/glucometerutils/drivers/sdcodefree.py index 4636d2a..1eba6e6 100644 --- a/glucometerutils/drivers/sdcodefree.py +++ b/glucometerutils/drivers/sdcodefree.py @@ -99,13 +99,16 @@ class Device(serial.SerialDevice): return pkt.message def wait_and_ready(self): - challenge = self.serial_.read(1) - # The first packet read may have a prefixed zero, it might be a bug in - # the cp210x driver or device, but discard it if found. - if challenge == b'\0': - logging.debug('spurious null byte received') - challege = self.serial_.read(1) + challenge = b'\0' + while challenge == b'\0': + challenge = self.serial_.read(1) + + # The first packet read may have a prefixed zero, it might be a bug + # in the cp210x driver or device, but discard it if found. + if challenge == b'\0': + logging.debug('spurious null byte received') + continue if challenge != b'\x53': raise exceptions.ConnectionFailed( message='Unexpected starting bytes %r' % challenge) -- cgit v1.2.3