quang-ha / nxt-python

Automatically exported from code.google.com/p/nxt-python
GNU General Public License v3.0
0 stars 0 forks source link

ValueError: No backend available #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Install pyusb
2. Install nxt-python
3. run `python spin.py`

What is the expected output? What do you see instead?

    Traceback (most recent call last):
      File "spin.py", line 12, in <module>
        b = nxt.locator.find_one_brick()
      File "/Library/Python/2.7/site-packages/nxt/locator.py", line 112, in find_one_brick
        for s in find_bricks(host, name, silent, method):
      File "/Library/Python/2.7/site-packages/nxt/locator.py", line 43, in find_bricks
        for s in socks:
      File "/Library/Python/2.7/site-packages/nxt/usbsock.py", line 84, in find_bricks
        for bus in usb.busses():
      File "/Library/Python/2.7/site-packages/usb/legacy.py", line 333, in busses
        return (Bus(),)
      File "/Library/Python/2.7/site-packages/usb/legacy.py", line 329, in __init__
        self.devices = [Device(d) for d in core.find(find_all=True)]
      File "/Library/Python/2.7/site-packages/usb/core.py", line 846, in find
        raise ValueError('No backend available')
    ValueError: No backend available

What version of nxt-python are you using? On what operating system?

Mac OS X 10.7.2 with nxt-python 2.2.1

Please provide any additional information below.

NXT is turned on and connected. Same steps work on Linux.

PyFantom does not get detected, LightBlue does not even install. I'm able to 
control the NXT with remote control software.

Original issue reported on code.google.com by pepijndevos on 25 Nov 2011 at 12:19

GoogleCodeExporter commented 9 years ago
It turns out you manually need to install libusb. Now I have a different error:

>>> b = nxt.locator.find_one_brick(debug=True)
Warning: Config file (should be at /Users/pepijndevos/.nxt-python) was not 
read. Use nxt.locator.make_config() to create a config file.
Host: None Name: None Strict: True
USB: True BT: True Fantom: False FUSB: False FBT: False
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/nxt/locator.py", line 119, in find_one_brick
    info = b.get_device_info()
  File "/Library/Python/2.7/site-packages/nxt/brick.py", line 27, in poll
    self.sock.send(str(ogram))
  File "/Library/Python/2.7/site-packages/nxt/usbsock.py", line 69, in send
    self.handle.bulkWrite(self.blk_out.address, data)
  File "/Library/Python/2.7/site-packages/usb/legacy.py", line 148, in bulkWrite
    return self.dev.write(endpoint, buffer, self.__claimed_interface, timeout)
  File "/Library/Python/2.7/site-packages/usb/core.py", line 610, in write
    intf = self._ctx.get_interface(self, interface)
  File "/Library/Python/2.7/site-packages/usb/core.py", line 153, in get_interface
    cfg = self.get_active_configuration(device)
  File "/Library/Python/2.7/site-packages/usb/core.py", line 169, in get_active_configuration
    raise USBError('Configuration not set')
USBError: [Errno None] Configuration not set
Failed to connect to possible brick
Bluetooth module unavailable, not searching there
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/nxt/locator.py", line 137, in find_one_brick
    raise BrickNotFoundError
nxt.locator.BrickNotFoundError

Original comment by pepijndevos on 25 Nov 2011 at 12:40

GoogleCodeExporter commented 9 years ago
Finally, running Python in 32 bit and issuing

b = nxt.locator.find_one_brick(debug=True, 
method=nxt.locator.Method(fantomusb=True, usb=False))

it worked, but now and then it returns an error on connecting.

Traceback (most recent call last):
  File "latency.py", line 7, in <module>
    b = nxt.locator.find_one_brick()
  File "/Library/Python/2.7/site-packages/nxt/locator.py", line 112, in find_one_brick
    for s in find_bricks(host, name, silent, method):
  File "/Library/Python/2.7/site-packages/nxt/locator.py", line 69, in find_bricks
    for s in usbsocks:
  File "/Library/Python/2.7/site-packages/nxt/fantomsock.py", line 109, in find_bricks
    nxt = d.get_nxt()
  File "/Library/Python/2.7/site-packages/pyfantom.py", line 267, in get_nxt
    Status.check(status)
  File "/Library/Python/2.7/site-packages/pyfantom.py", line 188, in check
    raise FantomException(description)
pyfantom.FantomException: error -4000ffc2 (hex

Original comment by pepijndevos on 25 Nov 2011 at 2:20

GoogleCodeExporter commented 9 years ago
Sorry it took me a while to get back to you. I'm not sure what's up with the 
pyusb/libusb error. You might try pulling the code from nxt.usbsock.USBSock's 
connect() and send() methods and running it by itself to see if you can 
duplicate the error. If so, ask the pyusb people and see if they can help you.

As for the pyfantom exception, talk to Tat-Chee Wan or Nicolas Schodet, the 
developers of pyfantom. It also looks like your traceback may be incomplete, so 
please check that out before sending it along.

Again, my apologies for taking a while to reply. For now, I don't believe that 
there is a problem with nxt-python itself (as it works with linux and the API 
for pyusb should be the same on both systems), so I'm going to mark this as 
Invalid.

Original comment by marcus@wanners.net on 5 Dec 2011 at 8:54

GoogleCodeExporter commented 9 years ago
It would nevertheless be a good idea to move to the new API. It doesn't look to 
difficult, except that I have no idea about devices, interfaces, endpoints and 
descriptors.

Why are you storing config[0] but setting config[1]? What is connect doing in 
plain english?

This seems to be the same problem as 
http://code.google.com/p/nxt-python/issues/detail?id=33 which is mentioned in 
the source. Maybe the same solution applies to Mac?

Original comment by pepijndevos on 12 Dec 2011 at 11:47

GoogleCodeExporter commented 9 years ago
Hm, apparently that's not the solution either, but it does give a different 
error.

>>> import nxt.usbsock
>>> b = nxt.usbsock.find_bricks().next().connect()
>>> b.get_battery_level()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/nxt/brick.py", line 29, in poll
    igram = Telegram(opcode=opcode, pkt=self.sock.recv())
  File "/Library/Python/2.7/site-packages/nxt/usbsock.py", line 73, in recv
    data = self.handle.bulkRead(self.blk_in.address, 64)
  File "/Library/Python/2.7/site-packages/usb/legacy.py", line 159, in bulkRead
    return self.dev.read(endpoint, size, self.__claimed_interface, timeout)
  File "/Library/Python/2.7/site-packages/usb/core.py", line 654, in read
    self.__get_timeout(timeout)
  File "/Library/Python/2.7/site-packages/usb/backend/libusb10.py", line 541, in bulk_read
    timeout)
  File "/Library/Python/2.7/site-packages/usb/backend/libusb10.py", line 641, in __read
    timeout))
  File "/Library/Python/2.7/site-packages/usb/backend/libusb10.py", line 403, in _check
    raise USBError(_str_error[ret], ret, _libusb_errno[ret])
usb.core.USBError: [Errno 60] Operation timed out

Original comment by pepijndevos on 12 Dec 2011 at 12:00

GoogleCodeExporter commented 9 years ago
I agree that we should move to the new pyusb API. However, making the 
modifications to the usbsock module would be hard for me to do. Doug Lau wrote 
the original communications backends and we haven't messed with them very much 
since. I don't have much experience programming for USB devices and none with 
pyusb (I have a tendency to stick to the standard serial interface and let the 
kernel do the hard work). I'm willing to land a move to the new pyusb API in 
v2.3 since there shouldn't be any nxt-python API breaking, but I don't have 
time to figure out how to port it myself at the moment. Even if I did, I have 
no way of testing on macs and testing on windows would be a pain.

So I'll put it on my list of things to do eventually. If anyone wants to do the 
heavy lifting themselves, you'll have my support and feedback, and I'll do the 
best I can to get it tested.

Not sure what's going on with your E60 timed out. Looks like the connect() and 
write() for the request for an input voltage reading works fine and then it 
fails when trying to read the battery. If you want to see what's going on, set 
the USBSock's debug attribute to True before calling connect() and 
get_battery_level(). My guess is that because the handle is reset(), the 
request is dropped somewhere or otherwise doesn't make it to the brick and as a 
result, there is no reply so the recv() times out. As I said, I'm not an expert 
at the USB code, so I'm not sure exactly what's going on or why this is.

Original comment by marcus@wanners.net on 12 Dec 2011 at 7:58

GoogleCodeExporter commented 9 years ago

Check this:

https://code.google.com/p/nxt-python/issues/detail?id=54

Original comment by alan...@gmail.com on 21 May 2013 at 10:00