From 0dc02af78d627affaf18f66b4344fbc8dc1a7d45 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Thu, 27 Sep 2012 15:16:43 +0300 Subject: [PATCH] properly distinguish between read error and no data read --- lib/hidapi.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/hidapi.py b/lib/hidapi.py index bc996873..cee24562 100644 --- a/lib/hidapi.py +++ b/lib/hidapi.py @@ -277,8 +277,11 @@ def read(device_handle, bytes_count, timeout_ms=-1): """ out_buffer = _C.create_string_buffer(b'\x00' * (bytes_count + 1)) bytes_read = _native.hid_read_timeout(device_handle, out_buffer, bytes_count, timeout_ms) - if bytes_read > -1: - return out_buffer[:bytes_read] + if bytes_read == -1: + return None + if bytes_read == 0: + return b'' + return out_buffer[:bytes_read] def send_feature_report(device_handle, data, report_number=None):