From 02230362e98c08338b79a3375a2fe9276ee69e39 Mon Sep 17 00:00:00 2001 From: Vincent Slotman Date: Fri, 24 Mar 2017 18:37:04 +0100 Subject: [PATCH] Raise timeout exception if <4 bytes received --- usbtmc/usbtmc.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/usbtmc/usbtmc.py b/usbtmc/usbtmc.py index 5e38af0..1773d29 100644 --- a/usbtmc/usbtmc.py +++ b/usbtmc/usbtmc.py @@ -655,6 +655,9 @@ def read_raw(self, num=-1): resp = self.bulk_in_ep.read(read_len+USBTMC_HEADER_SIZE+3, timeout=self._timeout_ms) + if len(resp) < 4: + raise usb.core.USBError('Operation timed out', errno=110) + if sys.version_info >= (3, 2): resp = resp.tobytes() else: