Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Python recurrent error: LabJackPython.LabJackException: Could only write 0 of 14 bytes


  • Please log in to reply
3 replies to this topic

#1 francois H

francois H
  • Members
  • 1 posts

Posted 19 June 2012 - 02:35 AM

Hello, I have a recurrent error in python, when i run openAllU3 method, I cannot use already defined device.I am obliged to redefined the device. Do you know if it is a wanted behaviour and if yes why? Do you have any workaround? Here under are log with two U3 devices then one U3 device. BR [email protected]:labjack$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import u3 >>> u3.openAllU3() {'320048570': <u3.U3 object at 0xb778698c>, '320046629': <u3.U3 object at 0xb77866ec>} >>> d = u3.U3() >>> d.configU3() {'TimerClockConfig': 2, 'TimerClockDivisor': 256, 'LocalID': 1, 'SerialNumber': 320046629, 'CIOState': 0, 'TimerCounterMask': 64, 'DAC1Enable': 1, 'EIODirection': 0, 'DeviceName': 'U3-HV', 'FIODirection': 0, 'FirmwareVersion': '1.32', 'CIODirection': 0, 'DAC0': 0, 'DAC1': 0, 'EIOAnalog': 0, 'CompatibilityOptions': 0, 'EIOState': 0, 'HardwareVersion': '1.30', 'FIOAnalog': 15, 'VersionInfo': 18, 'FIOState': 0, 'BootloaderVersion': '0.27', 'ProductID': 3} >>> d.readRegister(6701) 255 >>> u3.openAllU3() {'320048570': <u3.U3 object at 0xb742f24c>, '320046629': <u3.U3 object at 0xb742f16c>} >>> d.readRegister(6701) libusb error: LIBUSB_ERROR_IO Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 371, in readRegister response = self._modbusWriteRead(pkt, numBytes) File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 504, in _modbusWriteRead self.write(request, modbus = True, checksum = False) File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 259, in write wb = self._writeToExodriver(writeBuffer, modbus) File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 209, in _writeToExodriver raise LabJackException( "Could only write %s of %s bytes." % (writeBytes, len(writeBuffer) ) ) LabJackPython.LabJackException: Could only write 0 of 14 bytes. >>> [email protected]:labjack$ python Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import u3 >>> u3.openAllU3() {'320046629': <u3.U3 object at 0xb76dc6ec>} >>> d = u3.U3() >>> d.configU3() {'TimerClockConfig': 2, 'TimerClockDivisor': 256, 'LocalID': 1, 'SerialNumber': 320046629, 'CIOState': 0, 'TimerCounterMask': 64, 'DAC1Enable': 1, 'EIODirection': 0, 'DeviceName': 'U3-HV', 'FIODirection': 0, 'FirmwareVersion': '1.32', 'CIODirection': 0, 'DAC0': 0, 'DAC1': 0, 'EIOAnalog': 0, 'CompatibilityOptions': 0, 'EIOState': 0, 'HardwareVersion': '1.30', 'FIOAnalog': 15, 'VersionInfo': 18, 'FIOState': 0, 'BootloaderVersion': '0.27', 'ProductID': 3} >>> d.readRegister(6701) 255 >>> u3.openAllU3() {'320046629': <u3.U3 object at 0xb73840cc>} >>> d.readRegister(6701) libusb error: LIBUSB_ERROR_IO Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 371, in readRegister response = self._modbusWriteRead(pkt, numBytes) File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 504, in _modbusWriteRead self.write(request, modbus = True, checksum = False) File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 259, in write wb = self._writeToExodriver(writeBuffer, modbus) File "/usr/local/lib/python2.7/dist-packages/LabJackPython.py", line 209, in _writeToExodriver raise LabJackException( "Could only write %s of %s bytes." % (writeBytes, len(writeBuffer) ) ) LabJackPython.LabJackException: Could only write 0 of 14 bytes. >>> d = u3.U3() >>> d.readRegister(6701) 255

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 19 June 2012 - 04:29 PM

The last handle you get to a device by a open call (openAllU3 or u3.U3) is the only valid handle. Previous handles/opens to a device will lose their interface claims meaning they lose USB communications. This is a libusb and usbfs limitation.

My suggestions are to use the U3 objects from the openAllU3 call as it opens all U3's for you and do not use "d = u3.U3()", or only use "d = u3.U3()" to open devices and use LabjackPython.listAll(3) to figure out the devices you can connect to. For example this should be fine:
>>> import u3
>>> d = u3.openAllU3()
>>> d['320046629'].configU3()
>>> d['320046629'].readRegister(6701)
>>> d = u3.openAllU3()
>>> d['320046629'].readRegister(6701)

I also recommend calling the close member on your current U3 object to clean up the libusb handle before opening the same device again.

#3 redoptic

redoptic
  • Members
  • 1 posts

Posted 27 July 2013 - 01:05 PM

I also have the same problem.  To avoid the problem, is it sufficient to simply open the u3, complete any given read / write operation, then close the u3?

 

I only have one u3 device connected, so would the following code be correct:

 

 

import u3
d = u3.U3()
d.writeRegister(50591, mybinarynumber)
d.close()
 
...then repeat as required for future read / write operations
 
As an alternative, is there any function call that allows me to check that the u3 still has normal USB communications, allowing me to reopen the u3 if a problem is flagged?


#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 29 July 2013 - 11:46 AM

If you open your U3, which u3.U3() does, in multiple parts of your code then yes you will want an open/close scheme like you are doing. If you only open your U3 once and use the handle globally then the d.close is not necessary until you reopen your U3 or close the program.

 

As for a function to check the USB status, no there is not a function like that. An exception from your write/readRegister calls though will indicate USB problems (and other things) and you can set your U3 has a problem flag to reopen based on that.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users