summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2018-01-01 13:50:17 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2018-01-01 13:50:17 +0100
commit44bc1fad54b171bb758eb336796a487ca28157f9 (patch)
tree3ba3c2754ddaf9af5bfaecc1118df9f32149d6fc
parentotverio2015: rewrite using construct. (diff)
downloadglucometerutils-44bc1fad54b171bb758eb336796a487ca28157f9.tar
glucometerutils-44bc1fad54b171bb758eb336796a487ca28157f9.tar.gz
glucometerutils-44bc1fad54b171bb758eb336796a487ca28157f9.tar.bz2
glucometerutils-44bc1fad54b171bb758eb336796a487ca28157f9.tar.lz
glucometerutils-44bc1fad54b171bb758eb336796a487ca28157f9.tar.xz
glucometerutils-44bc1fad54b171bb758eb336796a487ca28157f9.tar.zst
glucometerutils-44bc1fad54b171bb758eb336796a487ca28157f9.zip
-rw-r--r--glucometerutils/drivers/otultraeasy.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/glucometerutils/drivers/otultraeasy.py b/glucometerutils/drivers/otultraeasy.py
index 0f95e80..ced1f0b 100644
--- a/glucometerutils/drivers/otultraeasy.py
+++ b/glucometerutils/drivers/otultraeasy.py
@@ -133,8 +133,11 @@ class Device(serial.SerialDevice):
self.buffered_reader_ = construct.Rebuffered(_PACKET, tailcutoff=1024)
def connect(self):
- self._send_packet(b'', disconnect=True)
- self._read_ack()
+ try:
+ self._send_packet(b'', disconnect=True)
+ self._read_ack()
+ except construct.ConstructError as e:
+ raise lifescan.MalformedCommand(str(e))
def disconnect(self):
self.connect()
@@ -175,20 +178,26 @@ class Device(serial.SerialDevice):
assert pkt.acknowledge
def _send_request(self, request_format, *args):
- request = request_format.build(*args)
- self._send_packet(request, acknowledge=False, disconnect=False)
+ try:
+ request = request_format.build(*args)
+ self._send_packet(request, acknowledge=False, disconnect=False)
- self.sent_counter_ = not self.sent_counter_
- self._read_ack()
+ self.sent_counter_ = not self.sent_counter_
+ self._read_ack()
+ except construct.ConstructError as e:
+ raise lifescan.MalformedCommand(str(e))
def _read_response(self, response_format):
- pkt = self._read_packet()
- assert not pkt.acknowledge
+ try:
+ pkt = self._read_packet()
+ assert not pkt.acknowledge
- self.expect_receive_ = not self.expect_receive_
- self._send_ack()
+ self.expect_receive_ = not self.expect_receive_
+ self._send_ack()
- return response_format.parse(pkt.message)
+ return response_format.parse(pkt.message)
+ except construct.ConstructError as e:
+ raise lifescan.MalformedCommand(str(e))
def get_meter_info(self):
return common.MeterInfo(