Rust Instrument Control with USB
The standard way to remote control or gather data from digital oscilloscope, DMM, signal generator, etc., is through GPIB/LAN/serial port at the back of these instruments, making connection to the PC.
Once the hardware cable is connected, at software level, you need to install some quite large VISA runtime/library. Lastly, you send SCPI commands, which consists of ASCII based text commands, to control the underlying instruments. LabView was the major platform/environment to send these ASCII strings. Nowadays Python through PyVISA provides nice wrapper for SCPI commands as well.
At this point, the only piece of documentation you need to look into, is a manual of all the SCPI commands (all ASCII strings) that your instrument implements. Here are a few examples of these programming manuals:
- OWON XDG AWG Programmer Manual (link)
- Rigol DM3058E DMM Programming Guide (link)
- Siglent SDS1204X-E Oscilloscope Programming Guide (link)
- Rigol DP832A Power Supply Programming Guide (link)
- OWON HDS272S Handheld Scope + Waveform Generator SCPI Manual (link)
- UNI-T UTG962E AWG Programming Guide (link)
(a more detailed explanation: the hardware/software stack of VISA from this link)
You may notice that we focus mainly on cheap Chinese brand instruments, such as Rigol, Siglent, OWON and UNI-T etc., but Tektronix, Agilent and others work the same way.
Some of these cheap instruments only come with a single USB port. The interesting question, how to send SCPI commands over that USB port?
In theory, if the instrument implements USBTMC (specification link), PyVISA should be able to communicate with it like other physical VISA ports.
But there are a few exceptions, for example, HDS272S (OWON) doesn’t seem to be recognized by pyvisa.ResourceManager().list_resources()
This is when Rust rusb
comes to help. The following code is heavily borrowed from the post (https://gill.net.in/posts/reverse-engineering-a-usb-device-with-rust/)
The goal is to be able to send SCPI ASCII commands over USB endpoints directly to HDS272S, bypassing the VISA abstraction layer on the PC side.