Python in Physics
OSU logo
The content of this page is undergoing revision and will be moved to another site soon.
USB

Table of Contents

Finding USB Busses and Devices

  • For Linux, use lsusb to list usb busses and devices connected to them. The command, lsusb -v will provide much information. Then use lsmod to list the kernel modules loaded. Note that LinuxCommand.Org explains shell commands.

Instrument USB Interfaces

USB Linux Kernel Drivers

PyVISA and the NI-VISA Library on Windows

  • PyVisa can be used with XP to communicate with this oscilloscope via USB. As the documentation shows, this is accomplished using a LabView Visa compatible DLL.
  • Tektronix TDS1012B Digital Oscilloscope

    • This Python program acquires a waveform and performs an FFT using the FFT function in the SciPy or numpy packages. The crude tds1012b.py module provides a few functions and classes for the scope. The programming manual for the tds1000/2000 series explains the command sequences.

PyVISA and the NI-VISA Library on Linux

PySerial

  • The PySerial module provide a simple means to achieve low speed communication using the serial.Serial class with /dev/tty0usb. As an example, channels.py and prologix_usb2gpib.py modules can be used to create a prologix usb to gpib converter object based on the serial.Serial communication channel object. The Prologix USB to GPIB converter uses the FTDI FT232BL USB-Serial (UART) IC to mimic a serial port connection to the GPIB bus, thus requiring the use of the pyserial module. Upon enumeration, the FT232 usb device is claimed by the kernel modules ftdi_sio and usbserial. You can see if these are loaded by running the lsmod command

Python and Libusb with Linux

  • Libusb provides user-space access to usb devices, and the PyUSB module provides access through Python. The libusb api can be used in lieu of PyUSB documentation. PyLibUSB seems to be similar but uses ctypes. Together with the libusb api, this is an attractive choice.
  • Examples

    • PyUSB can be used to communicate with the prologix device as well, although you have to know much about how the microcontroller uses the IO stream from the FTDI USB chip. The program prologix_pyusb.py finds and claims interface 0 of configuration 1. Note that interface needs to be released from the kernel module that initially claimed the device upon enumeration, presumably ftdi_sio. Also, create or modify /etc/udev/rules.d/11-prologix.rules with GROUP="users" and MODE="0666" so that all users can open the device.

Other Dynamic Libraries, Libusb and Python

  • Libftdi uses libusb to talk to FTDI FT232BM/245BM, FT2232C/D and FT232/245R controllers. This is the open-source version of FTDIs libftd2xx. There is said to be a Python module.
  • The LabJack family of USB analog and digital IO devices uses a custom dynamic library to communicate through libusb. Make sure the file /etc/udev/rules.d/10-labjack.rules has GROUP="users" and MODE="0666" so that all users can open the device. With the LabJack disconnected, reload the udev rules using "udevadm control --reload-rules". Also, download the source code for exodriver from labjack.com/support and follow the simple installation instructions. Under Linux, the library liblabjack.so (actually a link to the real library liblabjack.so.2.0.1) is in /usr/local/lib, an unusual location. If the "import LabJackPython" line in a program results in the error "could not load LabJackUSB driver", do the following. In /etc/ld.so.conf.d create the file labjack.conf. This file has only one line: /usr/local/lib . Then as root, run ldconfig. If in doubt, run "ldconfig -v | grep labjack", and you should see a statement about liblabjack.so.

Other Dynamic Libraries And Libusb But No Python