2 releases

0.1.1 Aug 22, 2023
0.1.0 Aug 11, 2023

#1038 in Hardware support

32 downloads per month
Used in instrument-ctl

Custom license

40KB
756 lines

Rust USBTMC

Pure Rust implementation of the USBTMC protocol to connect to instruments.

Thus far, this library implements the basic USBTMC control endpoint commands, writing DEVICE_DEPENDENT messages to the BULK OUT endpoint and reading DEVICE_DEPENDENT messages to the BULK IN endpoint.

Usage

To use, add the following line to your project's Cargo.toml dependencies:

rs-usbtmc = "0.1"

Example

The example below demonstrates how to connect to, send commands to and query the device.

use rs_usbtmc::UsbtmcClient;

const DEVICE_VID: u16 = 0x0000;
const DEVICE_PID: u16 = 0x0000;

fn main() {
    // connect to the device
    let device = UsbtmcClient::connect(DEVICE_VID, DEVICE_PID).expect("failed to connect");

    // send a command to the device
    device.command("*IDN?").expect("failed to send command");

    // query the device and get a string
    let response: String = device.query("*IDN?").expect("failed to query device");

    // query the device and get a bytes
    let response: Vec<u8> = device.query_raw("*IDN?").expect("failed to query device");
}

Project Plans

I created this driver as part of a project to control an oscilloscope during a summer research position. Alone, I do not have access to an oscilloscope. If I do obtain one, the plan is to:

  • Fully implement all possible requests
  • Implement the usb488 subclass requests

I'll reach out to my university for access to an instrument to complete this project, but I'm open to collaborating.

Dependencies

~1.6–2.4MB
~50K SLoC