Wednesday, August 28, 2013

bladeRF board talks back (more or less) to a python program

I installed libusb0 (libusb-win32). With inf-wizard I managed to make the bladeRF board visible to Windows. When I connect the device I have a libusb-board called bladeRF!

The problem is, however, that libusb0.sys is a libusb 0.1 implementation.

Well, let's see if can find this device with a Python-program:
I found this snippet on the big Internet. Wish I saved the URL to give credit to the programmer!

#!/usr/bin/env python

import usb

for bus in usb.busses():
  for dev in bus.devices:
    print "Bus %s Device %s: ID %04x:%04x %s" % (bus.dirname,dev.filename,dev.idVendor,dev.idProduct,,30))

The output:

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
Bus  Device : ID 1d50:6066 Nuand

This is encouraging!

From a USB-tutorial I copied:

# import usb.backend
# import usb.legacy
import usb.core
# import usb.util
# import usb.control

# find our device
dev = usb.core.find(idVendor=0x1D50, idProduct=0x6066)

# was it found?
if dev is None:
    raise ValueError('Device not found')
    print ('Device found')

    print 'len =', dev.bLength
    print 'bNumConfigurations =', dev.bNumConfigurations
    print 'bDeviceClass =', dev.bDeviceClass
    num = dev.idVendor
    num = "%#x"%(num)
    print 'idVendor = ', num
    #print 'idVendor = ', dev.idVendor
    num = dev.idProduct
    num = "%#x"%(num)
    print 'idProduct = ', num
    #print 'idProduct = ', dev.idProduct
    print 'bcdUSB = ', dev.bcdUSB
    print 'bcdDevice = ', dev.bcdDevice
    print 'iManufacturer = ', dev.iManufacturer
# set the active configuration. With no arguments, the first
# configuration will be the active one

And the output:

Device found
len = 18
bNumConfigurations = 1
bDeviceClass = 0
idVendor =  0x1d50
idProduct =  0x6066
bcdUSB =  768
bcdDevice =  0
iManufacturer =  1

Traceback (most recent call last):
  File "C:\Users\lonneke\python\", line 34, in <module>
  File "C:\Python27\lib\site-packages\usb\", line 547, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "C:\Python27\lib\site-packages\usb\", line 92, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "C:\Python27\lib\site-packages\usb\backend\", line 437, in set_configuration
    _check(_lib.usb_set_configuration(dev_handle, config_value))
  File "C:\Python27\lib\site-packages\usb\backend\", line 384, in _check
    raise USBError(errmsg, ret)
USBError: [Errno None] libusb0-dll:err [set_configuration] could not set config 1: win error: De parameter is onjuist.


The problem seems to be that dev.set_configuration() needs an argument.

I think I have a version problem. I have libusb 0.1 on my Windows system.

I googled a lot and found a lot. The right search-arguments are: "libusb pyusb winusb".
In fact WinUSB is what I was looking for.

Then I found zadig:

I experimented with their zadig.exe
I hope I did not do something very stupid!
You can install WinUSB and also libusbK with that program.

My little python-program did not see the bladeRF board anymore. Luckily I could reinstall the old driver and try again.

This libusb 0.1 1.0 issue is very confusing. There is also a libusbK.
I just want to use PyUSB with my bladeRF board and probably need libusb1.0 for that?
I read something about legacy, backend, etc. A lot to study, I am afraid.

Perhaps now is the time to formulate a question in the bladerf forum...

In VilaCha, Portugal, there is a marvelous small pub
where you can drink and eat typical Portuguese food.
We have been there in February, 2013 and surely will return.
If you drive along, you can't miss this pirate!

1 comment:

  1. Is there a way to read data into python directly from bladerf without creating file?