lxi

package module
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 9 Imported by: 7

README

lxi

Go-based implementation of the LAN eXtensions for Instrumentation (LXI) standard to send SCPI commands or to provide an interface for Interchangeable Virtual Instrument (IVI) drivers.

GoDoc Go Report Card License Badge

Overview

This packages enables controlling LXI compatible test equipment (e.g., oscilloscopes, function generators, multimeters, etc.) over Ethernet. While this package can be used by itself to send Standard Commands for Programmable Instruments (SCPI) commands to a piece of test equipment, it also serves to provide an Instrument interface for both the ivi and visa packages. The ivi package provides standardized APIs for programming test instruments following the Interchangeable Virtual Instrument (IVI) standard.

Installation

$ go get github.com/gotmc/lxi

Documentation

Documentation can be found at either:

Contributing

Contributions are welcome! To contribute please:

  1. Fork the repository
  2. Create a feature branch
  3. Code
  4. Submit a pull request
Development Dependencies
Testing

Prior to submitting a pull request, please run:

$ just check
$ just lint

To update and view the test coverage report:

$ just cover

License

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

Documentation

Overview

Package lxi provides a LAN eXtensions for Instrumentation (LXI) interface for controlling test equipment over Ethernet ports using SCPI commands. It implements the VISA LXI resource string format and serves as an instrument driver for the ivi and visa packages.

This package is part of the gotmc ecosystem. The visa package (github.com/gotmc/visa) defines a common interface for instrument communication across different transports (GPIB, USB, TCP/IP, serial). The asrl package provides the serial transport implementation. The ivi package (github.com/gotmc/ivi) builds on top of visa to provide standardized, instrument-class-specific APIs following the IVI Foundation specifications.

Devices are addressed using VISA resource strings of the form:

TCPIP<boardIndex>::<hostAddress>::<port>::SOCKET

For example:

TCPIP0::192.168.1.101::5025::SOCKET

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrResourceFormat = errors.New("visa: resource string does not match expected format")
	ErrInterfaceType  = errors.New("visa: interface type was not TCPIP")
	ErrResourceClass  = errors.New("visa: resource class was not SOCKET")
	ErrBoardIndex     = errors.New("visa: board index error")
	ErrHostAddress    = errors.New("visa: host address is required")
	ErrPort           = errors.New("visa: port error")
)

Sentinel errors returned by NewVisaResource.

Functions

This section is empty.

Types

type Device

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

Device models an LXI device, which is currently just a TCPIP socket interface. An LXI Device implements the ivi.Transport interface.

func NewDevice

func NewDevice(ctx context.Context, address string) (*Device, error)

NewDevice opens a TCPIP Device using the given VISA address resource string. The context controls the timeout/deadline for the TCP connection attempt.

func (*Device) Close

func (d *Device) Close() error

Close closes the underlying network connection.

func (*Device) Command added in v0.3.0

func (d *Device) Command(ctx context.Context, cmd string, a ...any) error

Command sends a SCPI/ASCII command to the underlying network connection. The command can be optionally formatted according to a format specifier. An endmark character, such as newline, is automatically added to the end of the string. The context deadline, if set, is applied to the underlying network connection.

func (*Device) Query

func (d *Device) Query(ctx context.Context, cmd string) (string, error)

Query writes the given SCPI/ASCII command to the underlying network connection and returns the response string. The device's endmark character (newline by default) is automatically added to the query command. The trailing endmark character is stripped from the response. The context deadline, if set, is applied to the underlying network connection for both the write and read operations.

func (*Device) Read

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

Read reads from the network connection into the given byte slice.

func (*Device) ReadBinary added in v0.16.0

func (d *Device) ReadBinary(ctx context.Context, p []byte) (n int, err error)

ReadBinary reads binary data from the network connection without terminator interpretation.

func (*Device) Write

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

Write writes the given data to the network connection.

func (*Device) WriteBinary added in v0.16.0

func (d *Device) WriteBinary(ctx context.Context, p []byte) (n int, err error)

WriteBinary writes binary data to the network connection without adding a terminator.

func (*Device) WriteString

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

WriteString writes a string to the underlying network connection. An endmark character, such as a newline, is not automatically added to the end of the string.

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.

Example
package main

import (
	"fmt"
	"log"

	"github.com/gotmc/lxi"
)

func main() {
	resource, err := lxi.NewVisaResource("TCPIP0::192.168.1.100::5025::SOCKET")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(resource)
}
Output:
TCPIP0::192.168.1.100::5025::SOCKET

func (*VisaResource) BoardIndex added in v0.12.0

func (v *VisaResource) BoardIndex() int

BoardIndex returns the VISA board index.

func (*VisaResource) HostAddress added in v0.12.0

func (v *VisaResource) HostAddress() string

HostAddress returns the hostname or IP address of the instrument.

func (*VisaResource) InterfaceType added in v0.12.0

func (v *VisaResource) InterfaceType() string

InterfaceType returns the VISA interface type (e.g., "TCPIP").

func (*VisaResource) Port added in v0.12.0

func (v *VisaResource) Port() int

Port returns the TCP port number of the instrument.

func (*VisaResource) ResourceClass added in v0.12.0

func (v *VisaResource) ResourceClass() string

ResourceClass returns the VISA resource class (e.g., "SOCKET").

func (*VisaResource) String added in v0.12.0

func (v *VisaResource) String() string

String returns the VISA resource string in canonical form.

Directories

Path Synopsis
examples
key33220 command

Jump to

Keyboard shortcuts

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