A Universal USBTMC Package for Python
universal_usbtmc is 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 module
USBTMC via python-usbtmc (uses libusb)
TCP Socket via socket (remote connection e.g. via rpi-usbtmc-gateway)
VXI-11 via python-vxi11 (an RPC-based TCP connection, not really usbtmc)
RS-232 via PySerial
As already mentioned, you’ll automatically gain a large deal of platform independence as any operating system will support at least some of those backends.
Installation
pip install universal_usbtmc
Usage
Backends
To communicate with your device, the following backends are available:
linux_kernel
python_usbtmc
tcp_socket
python_vxi11
pyserial
Backend Details
linux_kernel
To use this backend, you must be using a Linux kernel and have the kernel module compiled and loaded. Look for the device /dev/usbtmc0 to check your USBTMC device is detected.
You can run the usbtmc shell to check if everything works OK:
usbtmc-shell --backend linux_kernel /dev/usbtmc0
python_usbtmc
Uses the libusb-/PyUSB-based python-usbtmc.
Here’s how to use the usbtmc shell with it:
usbtmc-shell --backend python_usbtmc USB::0x1ab1::0x0588::INSTR
To use the backend python_usbtmc, you need to install the requirements python-usbtmc and PyUSB:
pip install python-usbtmc pyusb
The backend works on Mac OS X and Linux.
tcp_socket
This 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 with rpi-usbtmc-gateway!
To connect using the tcp_socket backend, run:
usbtmc-shell --backend tcp_socket 192.168.0.21 # or usbtmc-shell --backend tcp_socket TCPIP::192.168.0.21::5025::SOCKET
This backend has no external dependencies and works on all operating systems.
python_vxi11
This 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 library python-vxi11.
To connect using the python_vxi11 backend, run:
usbtmc-shell --backend python_vxi11 192.168.0.21 # or usbtmc-shell --backend python_vxi11 TCPIP::192.168.0.21::INSTR
To use this backend, install python-vxi:
pip install python-vxi11
The backend should work on all operating systems.
pyserial
This backend uses PySerial to 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::INSTR
Off course, you need to install PySerial first! The backend works on all operating systems.
Resources
A project with a similar aim is python-ivi
Metadata
Release files for universal_usbtmc 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| universal_usbtmc-0.3.5.tar.gz | 10.4 kB | Without provenance | Details |
Release files / universal_usbtmc-0.3.5.tar.gz
| Download URL | universal_usbtmc-0.3.5.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf11a3c144a4233d3f64eefd10e2726e61fb8b73ad3fd320b1c4412026a00d8c
|
|
BLAKE2b-256 checksum How to use checksums |
293fe9ecd5893129391dc7a4864ba26eaded71f9821dcffcb77a33c14c48e8d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for universal_usbtmc 0.3.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.