From 52f1892d8a6b3cc674196e8cbcaa9e0f42cc4d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Tue, 6 Jun 2017 08:34:39 +0100 Subject: hiddevice: make hidapi calls take a timeout, default to 1 second. This is important for a meter I'm working on right now, as there is no obvious way to tell whether to wait for new packets or not. --- glucometerutils/support/hiddevice.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/glucometerutils/support/hiddevice.py b/glucometerutils/support/hiddevice.py index b360841..a1af95a 100644 --- a/glucometerutils/support/hiddevice.py +++ b/glucometerutils/support/hiddevice.py @@ -30,11 +30,18 @@ class HidDevice(object): If the VID/PID pair is not provided, the driver will require a device path to be used. + + Optional parameters available: + + TIMEOUT_MS: (int, default: 1000) the read timeout in milliseconds, used + for hidapi reads only. """ USB_VENDOR_ID = None USB_PRODUCT_ID = None + TIMEOUT_MS = 1000 + def __init__(self, device): if None in (self.USB_VENDOR_ID, self.USB_PRODUCT_ID) and not device: raise exceptions.CommandLineError( @@ -81,4 +88,4 @@ class HidDevice(object): if self.handle_mode_ == 'hidraw': return self.handle_.read(size) else: - return bytes(self.handle_.read(size, timeout_ms=1000)) + return bytes(self.handle_.read(size, timeout_ms=self.TIMEOUT_MS)) -- cgit v1.2.3