usbtmc

package module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 9 Imported by: 5

README

usbtmc

Go library to communicate with a USB Test and Measurement Class (USBTMC) enabled USB device.

GoDoc Go Report Card Build Status License Badge

Overview

USBTMC is a USB device class specification for test equiment and instrumentation devices, such as oscilloscopes, digital multimeters, and function generators. USBTMC requires three endpoints:

  • Control endpoint
  • Bulk-OUT endpoint
  • Bulk-IN endpoint

Additionally, the USBTMC subclass USB488 has an Interrupt-IN endpoint.

USBTMC Descriptors

  • Interface class = 0xFE (application-specific)
  • Interface subclass = 0x03 (indicates USBTMC)

Installation

$ go get github.com/gotmc/usbtmc

Usage

To use the usbtmc package, you must register which Go-based libusb interface library should be used. libusb is "a C library that provides generic access to USB devices." There are two Go-based libusb hardware interface libraries available:

You'll need to install one of the above libraries using:

$ go get -v github.com/google/gousb
$ go get -v github.com/gotmc/gotmc

To indicate which libusb interface library should be used, include one of the following blank imports:

import _ "github.com/gotmc/usbtmc/driver/google"
import _ "github.com/gotmc/usbtmc/driver/gotmc"

Documentation

Documentation can be found at either:

Contributing

To contribute, please fork the repository, create a feature branch, and then submit a pull request.

Testing

Prior to submitting a pull request, please run:

$ make check

To update and view the test coverage report:

$ make cover
Disclosure and Call for Help

While this package works, it does not fully implement the USBTMC specification. Please submit pull requests as needed to increase functionality, maintainability, or reliability.

License

usbtmc is released under the MIT license. Please see the LICENSE.txt file for more information.

Documentation

Overview

Package usbtmc uses libusb to communicate with USB Test & Measurement Class (USBTMC) compliant devices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(d driver.Driver)

Register is called to register a driver for use by the program.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context hold the USB context for the registered driver.

func NewContext

func NewContext() (*Context, error)

NewContext creates a new USB context using the registered driver.

func (*Context) Close

func (c *Context) Close() error

Close closes the USB context for the underlying USB driver.

func (*Context) NewDevice

func (c *Context) NewDevice(address string) (*Device, error)

NewDevice creates a new USBTMC compliant device based on the given VISA address string.

func (*Context) NewDeviceByVIDPID

func (c *Context) NewDeviceByVIDPID(VID, PID int) (*Device, error)

NewDeviceByVIDPID creates new USBTMC compliant device based on the given the vendor ID and product ID. If multiple USB devices matching the VID and PID are found, only the first is returned.

func (*Context) SetDebugLevel

func (c *Context) SetDebugLevel(level int)

SetDebugLevel sets the debug level for the underlying USB device using the given integer.

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device models a USBTMC device, which includes a USB device and the required USBTMC attributes and methods.

func (*Device) Close

func (d *Device) Close() error

Close closes the underlying USB device.

func (*Device) Command added in v0.3.0

func (d *Device) Command(format string, a ...interface{}) error

Command sends the SCPI/ASCII command to the underlying USB device. A newline character is automatically added to the end of the string.

func (*Device) Query

func (d *Device) Query(s string) (string, error)

Query writes the given string to the USBTMC device and returns the returned value as a string. A newline character is automatically added to the query command sent to the instrument.

func (*Device) Read

func (d *Device) Read(p []byte) (n int, err error)

Read creates and sends the header on the bulk out endpoint and then reads from the bulk in endpoint per USBTMC standard.

func (*Device) Write

func (d *Device) Write(p []byte) (n int, err error)

Write creates the appropriate USBMTC header, writes the header and data on the bulk out endpoint, and returns the number of bytes written and any errors.

func (*Device) WriteString

func (d *Device) WriteString(s string) (n int, err error)

WriteString writes a string using the underlying USB device. A newline terminator is not automatically added.

type VisaResource

type VisaResource struct {
	// contains filtered or unexported fields
}

VisaResource represents a VISA enabled piece of test equipment.

func NewVisaResource

func NewVisaResource(resourceString string) (*VisaResource, error)

NewVisaResource creates a new VisaResource using the given VISA resourceString.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL