wjasper / Linux_Drivers

Open source Linux device drivers
GNU General Public License v3.0
111 stars 64 forks source link

Exception causes variable not found #46

Closed jeffallen closed 1 year ago

jeffallen commented 1 year ago

Getting an exception in AInScanRead will cause a Python error when len(data) happens after. Here's a fix. I didn't put it in a PR because I don't have time right now to go update all the places this error is present. Sorry.

diff --git a/USB/python/usb_1608G.py b/USB/python/usb_1608G.py
index d562a98..710f761 100755
--- a/USB/python/usb_1608G.py
+++ b/USB/python/usb_1608G.py
@@ -435,12 +435,13 @@ class usb1608G(mccUSB):
     else:
       nSamples = self.count*(self.lastElement+1)

+    data = None
     try:
       data =  list(unpack('H'*nSamples, self.udev.bulkRead(libusb1.LIBUSB_ENDPOINT_IN | 6, int(2*nSamples), self.HS_DELAY)))
     except:
       print('AInScanRead: error in bulkRead.')

-    if len(data) != nSamples:
+    if data is not None and len(data) != nSamples:
       raise ValueError('AInScanRead: error in number of samples transferred.')
       return len(data)
wjasper commented 1 year ago

OK I'll put that in. Do you know what caused the exception?

jeffallen commented 1 year ago

USB device in a bad state, I think. I was struggling with a few different errors at the time. Now it's rock solid, thanks!

wjasper commented 1 year ago

Hi Jeff, thanks for the input. I've updated most of the drivers with that logic. I'm going to close out this comment. Glad things are working for you. The USB-1608G is a pretty reliable device. Best, Warren