labjack / LabJackPython

The official Python modules and classes for interacting with the LabJack U3, U6, UE9 and U12
https://labjack.com/support/software/examples/ud/labjackpython
MIT License
117 stars 79 forks source link

Index Error #89

Closed allisontsay closed 8 years ago

allisontsay commented 8 years ago

This worked the first time I ran it, but now, I keep getting IndexError: list index out of range?

mnaberez commented 8 years ago

Could you please post the full backtrace? There are a huge number of places where an IndexError could potentially occur (e.g. anytime a list is accessed). Without knowing the file and line number that this occurred in, there's no way to troubleshoot it.

davelopez01 commented 8 years ago

Following up, allisontsay did you resolve your IndexError issue? I'm going to close this issue soon since there are no further comments, and I assume you found the cause of the error on your own since January. Let me know if you need further help with this.

Thank you mnaberez for your help on troubleshooting.

isaac-ped commented 8 years ago

I am getting the same error if I try to initialize a connection without unplugging the device and plugging it back in again. It does not seem to disconnect from the LabJack device until I unplug it.

The easiest way for me to get this error is with the LabJackPython.listAll() command. When I try to list all connected devices twice in a row, it gives me the same error:

>>> import LabJackPython >>> LabJackPython.listAll(3) {'320065320': {'deviceName': 'U3-LV', 'streamStarted': False, 'streamConfiged': False, 'handle': None, 'localId': 1, 'serialNumber': 320065320, '_autoCloseSetup': False, 'deviceLock': <thread.lock object at 0x1044d1990>, 'devType': 3, 'hardwareVersion': '1.30', 'versionInfo': 2, 'bootloaderVersion': '0.27', 'changed': {'deviceName': 'U3-LV', 'hardwareVersion': '1.30', 'localId': 1, 'serialNumber': 320065320, 'bootloaderVersion': '0.27', 'versionInfo': 2, 'ipAddress': '', 'firmwareVersion': '1.46'}, 'debug': False, 'streamPacketOffset': 0, 'ipAddress': '', 'firmwareVersion': '1.46', 'modbusPrependZeros': True}} >>> LabJackPython.listAll(3) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "LabJackPython.py", line 1194, in listAll return __listAllU3Unix() File "LabJackPython.py", line 2767, in __listAllU3Unix device = openLabJack(LJ_dtU3, 1, firstFound = False, devNumber = i+1) File "LabJackPython.py", line 1479, in openLabJack return _makeDeviceFromHandle(handle, deviceType) File "LabJackPython.py", line 1540, in _makeDeviceFromHandle device.localId = rcvDataBuff[21] & 0xff IndexError: list index out of range

davelopez01 commented 8 years ago

That index out of range error is due to there being an incomplete or no response packet from the U3.

Are you using Mac OS X 10.11, El Capitan? If so, update to the latest version of El Capitan (10.11.4 or newer) and that should help. There was an OS X bug that was causing communication issues after opening a LabJack device over USB more than once, and the recent update fixed that.

If that doesn't help, what operating system are you using? What version of Python are you using?

isaac-ped commented 8 years ago

Ahh, excellent! I upgraded to 10.11.4, and it all seems to work now. Thanks so much!