usbtmc

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 4 Imported by: 1

README

USB TMC

This is a fork from https://github.com/gotmc/usbtmc.

Overview

The purpose is to renew the repo completely based on gousb, since the feature of selecting between two usb libraries is not working anymore(or I failed miserably). This is targeted specifically for controlling USB test instruments without visa library. The goal is to provide similar experience as in pyvisa package from python.

USB TMC Specs

Refer to USB TMC Spec for details. If you are not familiar with USB protocol, which I'm also, take a tour on USB in a nutshell

Installation

$ go get github.com/grvstick/usbtmc

Usage

You'll need to install gousb. Please note that libusb is a prerequisite for gousb

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

Refer to tests directory for example usage of the library

Documentation

Refer to original repo or see

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][gousbtmc] is released under the MIT license. Please see the [LICENSE.txt][] file for more information.

Documentation

Index

Constants

View Source
const (
	MsgIdDevDepMsgOut            msgIDtype = 1   // DEV_DEP_MSG_OUT
	MsgIdRequestDevDepMsgIn      msgIDtype = 2   // REQUEST_DEV_DEP_MSG_IN
	MsgIdDevDepMsgIn             msgIDtype = 2   // DEV_DEP_MSG_IN
	MsgIdVendorSpecificOut       msgIDtype = 126 // VENDOR_SPECIFIC_OUT
	MsgIdRequestVendorSpecificIn msgIDtype = 127 // REQUEST_VENDOR_SPECIFIC_IN
	MsgIdVendorSpecificIn        msgIDtype = 127 // VENDOR_SPECIFIC_IN
	MsgIdTrigger                 msgIDtype = 128 // TRIGGER
)

The following msgID values are found in Table 2 under the MACRO column of the USBTMC Specificiation 1.0, April 14, 2003. The end of line comment shows the MACRO names as given in the USBTMC specification. The trigger msgID comes from Table 1 -- USB488 defined msgID values of the USBTMC-USB488 Specification 1.0, April 14, 2003.

Variables

This section is empty.

Functions

func CheckTMC added in v0.0.6

func CheckTMC(val gousb.InterfaceSetting) (bool, gousb.Protocol)

Types

type Device added in v0.0.6

type Device struct {
	BulkInEndpoint      *gousb.InEndpoint
	BulkInMaxPktSize    int
	BulkOutEndpoint     *gousb.OutEndpoint
	InterruptInEndpoint *gousb.InEndpoint
	// contains filtered or unexported fields
}

func NewDevice added in v0.0.6

func NewDevice(vid, pid int, sn string) (*Device, error)

NewDevice searches for device matching vid, pid and serial number. Serial number can be omitted by passing empty string If serial number is omitted it will look for first device matching vid & pid If a device is detected, it will go over configurations to see if thare is a TMC configuration.

func (*Device) Close added in v0.0.6

func (d *Device) Close() error

Close closes the Device.

type UsbTmc

type UsbTmc struct {
	UsbDevice *Device
	// contains filtered or unexported fields
}

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

func NewUsbTmc added in v0.0.6

func NewUsbTmc(dev *Device, termchar byte) *UsbTmc

func (*UsbTmc) Close

func (d *UsbTmc) Close() error

Close closes the underlying USB device.

func (*UsbTmc) Query

func (d *UsbTmc) 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 (*UsbTmc) Read

func (d *UsbTmc) Read() ([]byte, error)

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

func (*UsbTmc) Write

func (d *UsbTmc) Write(data []byte) (int, error)

func (*UsbTmc) WriteString

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

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

Jump to

Keyboard shortcuts

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