summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-06-05 00:24:01 +0200
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-06-05 00:24:01 +0200
commit6f217c71c7611c053de2aa4c280fc8eb1aca3a02 (patch)
tree14361b860b40f3611c8896db1b97e9b72919b067
parentAdd a ne support class for HID-based devices. (diff)
downloadglucometerutils-6f217c71c7611c053de2aa4c280fc8eb1aca3a02.tar
glucometerutils-6f217c71c7611c053de2aa4c280fc8eb1aca3a02.tar.gz
glucometerutils-6f217c71c7611c053de2aa4c280fc8eb1aca3a02.tar.bz2
glucometerutils-6f217c71c7611c053de2aa4c280fc8eb1aca3a02.tar.lz
glucometerutils-6f217c71c7611c053de2aa4c280fc8eb1aca3a02.tar.xz
glucometerutils-6f217c71c7611c053de2aa4c280fc8eb1aca3a02.tar.zst
glucometerutils-6f217c71c7611c053de2aa4c280fc8eb1aca3a02.zip
-rw-r--r--glucometerutils/support/hiddevice.py7
1 files changed, 6 insertions, 1 deletions
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))