3

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.

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
zh1
  • 231
  • 2
  • 8
  • What do you see on `usb.core.find()` and `usb.core.show_devices()` – flamenco Oct 25 '15 at 01:58
  • Is the device driver for the detector possibly not compatible with PyUSB? – paisanco Oct 25 '15 at 02:34
  • 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. Oct 25 '15 at 05:06

2 Answers2

3

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.

zh1
  • 231
  • 2
  • 8
  • Could not install 'unsigned INF' generated by libusb's inf-wizard tool. Had to run following oneliner/commands. bcdedit /set loadoptions DDISABLE_INTEGRITY_CHECKS & bcdedit /set testsigning on –  May 02 '17 at 19:53
1

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)
FriendFX
  • 2,929
  • 1
  • 34
  • 63
flamenco
  • 2,702
  • 5
  • 30
  • 46
  • Thanks. I changed my code based on your suggestions, but it still doesn't work. Any other ideas? – zh1 Oct 25 '15 at 23:24
  • What do you see on usb.core.find() and usb.core.show_devices()? Before doing anything via PyUSB, you need to make sure that the device is visible from Windows. – flamenco Oct 26 '15 at 03:37
  • Substituting usb.core.find() returns the value error, and usb.core.show_devices() returns nothing at all. But usb.core.find(find_all=True) returns . – zh1 Oct 27 '15 at 18:28
  • Got it figured out - PyUSB doesn't like the windows driver. I highly appreciate your help though. – zh1 Oct 27 '15 at 18:43