Package: universal_usbtmc
A Universal USBTMC Package for Pythonuniversal_usbtmcis an effort to fix the clutter of USBTMC
implementations for Python.This project provides a unified interface to the different ways/
implementations (“backends”) to talk to USBTMC devices (“instruments”).
This allows you to write very platform independent code.It also comes with an interactive USBTMC shell.You can use the following instrument implementations (“backends”) in
your software:USBTMC via the Linux kernel moduleUSBTMC viapython-usbtmc(uses
libusb)TCP Socket viasocket(remote
connection e.g. viarpi-usbtmc-gateway)VXI-11 viapython-vxi11(an
RPC-based TCP connection, not really usbtmc)RS-232 viaPySerialAs already mentioned, you’ll automatically gain a large deal of platform
independence as any operating system will support at least some of those
backends.Installationpip install universal_usbtmcUsageThis software is mainly made to be used by other software, not humans.It comes, however, with a small command line tool calledusbtmc-shell. You can use it to test if the different backends
work for you. (Or for trying to talk to a new device you just bought.)
See below in the backends sections on how to use it with different
backends.BackendsTo communicate with your device, the following backends are available:linux_kernelpython_usbtmctcp_socketpython_vxi11pyserialBackend Detailslinux_kernelUses the Linux Kernel ModuleusbtmcThe source code of the kernel module can be foundhere.To use this backend, you must be using a Linux kernel and have the
kernel module compiled and loaded. Look for the device/dev/usbtmc0to check your USBTMC device is detected.You can run the usbtmc shell to check if everything works OK:usbtmc-shell --backend linux_kernel /dev/usbtmc0python_usbtmcUses the libusb-/PyUSB-basedpython-usbtmc.Here’s how to use the usbtmc shell with it:usbtmc-shell --backend python_usbtmc USB::0x1ab1::0x0588::INSTRTo use the backendpython_usbtmc, you need to install the
requirementspython-usbtmcandPyUSB:pip install python-usbtmc pyusbThe backend works on Mac OS X and Linux.tcp_socketThis backend connects to your instrument via TCP sockets. How is this
possible if the instrument itself doesn’t have an Ethernet port? You can
put it on the net withrpi-usbtmc-gateway!To connect using thetcp_socketbackend, run:usbtmc-shell --backend tcp_socket 192.168.0.21
# or
usbtmc-shell --backend tcp_socket TCPIP::192.168.0.21::5025::SOCKETThis backend has no external dependencies and works on all operating
systems.python_vxi11This backend connects to your instrument via VXI-11. This is not USBTMC
in a way but the interface with SCPI commands is usually the same.Uses the Python librarypython-vxi11.To connect using thepython_vxi11backend, run:usbtmc-shell --backend python_vxi11 192.168.0.21
# or
usbtmc-shell --backend python_vxi11 TCPIP::192.168.0.21::INSTRTo use this backend, install python-vxi:pip install python-vxi11The backend should work on all operating systems.pyserialThis backend usesPySerialto
connect to your device via RS232. On some devices, this is more stable
than the USBTMC connection.usbtmc-shell --backend pyserial ASRL::/dev/ttyUSB0,9600::INSTROff course, you need to installPySerialfirst! The backend works
on all operating systems.ResourcesA project with a similar aim ispython-ivi