diff options
-rw-r--r-- | glucometerutils/drivers/sdcodefree.py | 15 |
1 files 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) |