From 6f217c71c7611c053de2aa4c280fc8eb1aca3a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Sun, 4 Jun 2017 23:24:01 +0100 Subject: hiddevice: add a 1-second timeout to reads. This is a semantics difference between hidraw and HIDAPI, cover for it. --- glucometerutils/support/hiddevice.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/glucometerutils/support/hiddevice.py b/glucometerutils/support/hiddevice.py index a3f2776..b360841 100644 --- a/glucometerutils/support/hiddevice.py +++ b/glucometerutils/support/hiddevice.py @@ -50,6 +50,7 @@ class HidDevice(object): # If the user passed a device, try opening it. if device: self.handle_ = open(device, 'w+b') + self.handle_mode_ = 'hidraw' else: logging.info( 'No --device parameter provided, using hidapi library.') @@ -57,6 +58,7 @@ class HidDevice(object): import hid self.handle_ = hid.device() self.handle_.open(self.USB_VENDOR_ID, self.USB_PRODUCT_ID) + self.handle_mode_ = 'hidapi' except ImportError: raise exceptions.ConnectionFailed( message='Missing requied "hidapi" module.') @@ -76,4 +78,7 @@ class HidDevice(object): This is important as it handles the one incompatible interface between hidraw devices and hidapi handles. """ - return bytes(self.handle_.read(size)) + if self.handle_mode_ == 'hidraw': + return self.handle_.read(size) + else: + return bytes(self.handle_.read(size, timeout_ms=1000)) -- cgit v1.2.3