3
votes

I am writing software in python to detect cosmic muons using a USB-connected radiation detector.

I am trying to use the PyUSB module to interact with the device, but PyUSB is not finding my radiation detector in particular. The device itself has a serial port, but I am using FTDI USB/serial adapter, and I have cross-checked the VID/PID for the adapter with the company and in control panel.

The following code yields <generator object device-iter at 0x02AADA80>. This is one of four USB devices on my PC (mouse, keyboard, WiFi adapter, and radiation detector).

import usb
import usb.core
import usb.util

dev = usb.core.find(find_all=True)
if dev is None:
    raise ValueError("device not found")
else:
    print(dev)

The code from the PyUSB tutorial I was using to locate the device also failed:

import usb
import usb.core
import usb.util

dev  usb.core.find("idVendor="0x0403", idProduct="0x6001") # VID/PID verified by company
if dev is None:
    raise ValueError("device not found")
else:
    print(dev)

I am running Python 2.7.1 on Windows 7, and I have the latest editions of PyUSB and libusb. I can't seem to find a reason why my device can't be found, although I'm probably missing something very fundamental.

2
What do you see on usb.core.find() and usb.core.show_devices() - flamenco
Is the device driver for the detector possibly not compatible with PyUSB? - paisanco
There are definitely too many quotation marks in your usb.core.find call. AFAIR you have to give the values as hex ints and not as strings. Just try to remove the quotation marks. - Klaus D.

2 Answers

3
votes

I didn't realize PyUSB requires a driver (.inf file) for each device you want to interact with python; I assumed the automatic driver installation on Windows would suffice. The Windows Installer for libusb comes with a very convenient INF creator and installer, and the problem was resolved after I applied that tool.

0
votes

Your code on line dev usb.core.find("idVendor="0x0403", idProduct="0x6001") has the following mistakes:

  1. Missing =. Change it to dev = usb.core.find....
  2. Extra " at find("idVendor
  3. According to PyUSB doc, you might want to try dev = usb.core.find(idVendor=0x0403, idProduct=0x6001)