scpi

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 7 Imported by: 0

README

go-scpi

MIT License

Forked from https://github.com/scizorman/go-scpi

Go library to control SCPI devices over TCP and serial interfaces.

Installation and usage

To install, run the following

go get github.com/autonomoosetech/go-scpi

To use, import as github.com/autonomoosetech/go-scpi like so

import (
	"github.com/autonomoosetech/go-scpi"
)

Example

// create a new TCP client
device, err := scpi.NewClient("tcp", "192.168.0.66:5025", time.Second)
if err != nil {
	fmt.Printf("could not create client: %v", err)
}

// query the device
response, err := device.Query("*IDN?")
if err != nil {
	fmt.Printf("failed to query device identification: %v", err)
}

// show the response
fmt.Printf("got response: %s", response)

Development

This project contains a makefile to aid in automating common tasks. You can run make help or just make to see the possible makefile targets.

Run unit tests
make test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Close closes the connection.
	Close() error

	// Exec executes a SCPI command.
	Exec(cmd string) error

	// ExecContext executes a SCPI command.
	ExecContext(ctx context.Context, cmd string) error

	// BulkExec executes multiple SCPI commands.
	BulkExec(cmds ...string) error

	// BulkExecContext executes multiple SCPI commands.
	BulkExecContext(ctx context.Context, cmds ...string) error

	// Ping verifies the connection to the device is still alive,
	// establishing a connection if necessary.
	Ping() error

	// PingContext verifies the connection to the device is still alive,
	// establishing a connection if necessary.
	PingContext(ctx context.Context) error

	// Query queries the device for the results of the specified command.
	Query(cmd string) (res string, err error)

	// QueryContext queries the device for the results of the specified command.
	QueryContext(ctx context.Context, cmd string) (res string, err error)
}

Client is a client of a device controlled using SCPI commands.

func NewClient

func NewClient(proto, addr string, timeout time.Duration) (Client, error)

NewClient returns a new client of a device controlled using SCPI commands.

type CommandError

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

CommandError is the error of SCPI commands.

func (*CommandError) Code

func (e *CommandError) Code() int

Code returns the error code of a SCPI device.

func (*CommandError) Error

func (e *CommandError) Error() string

type Handler

type Handler struct {
	Client
}

Handler is a handler for a device controlled using SCPI commands.

func NewHandler

func NewHandler(client Client) *Handler

NewHandler returns a new handler for a device controlled using SCPI commands.

func (*Handler) Identify

func (h *Handler) Identify(ctx context.Context) (id string, err error)

Identify returns the identification data.

The standards order is follows:

Manufacturer
Model number
Serial number (or 0)
Firmware version

func (*Handler) QueryEventStatusEnable

func (h *Handler) QueryEventStatusEnable(ctx context.Context) (bit uint8, err error)

QueryEventStatusEnable queries the event status enable.

func (*Handler) QueryEventStatusRegister

func (h *Handler) QueryEventStatusRegister(ctx context.Context) (bit uint8, err error)

QueryEventStatusRegister queries the event status register. The register is cleared when it is executed.

func (*Handler) QueryServiceRequestEnable

func (h *Handler) QueryServiceRequestEnable(ctx context.Context) (bit uint8, err error)

QueryServiceRequestEnable queries the Service Request Enable.

func (*Handler) QueryStatusByteRegister

func (h *Handler) QueryStatusByteRegister(ctx context.Context) (bit uint8, err error)

QueryStatusByteRegister queries the Status Byte Register.

func (*Handler) Recall

func (h *Handler) Recall(ctx context.Context, mem uint8) error

Recall restored the instrument to a state that was previously stored in locations 0 through 9 with the Save.

func (*Handler) Reset

func (h *Handler) Reset() error

Reset resets the instrument to a factory pre-defined condition and clears the error log.

func (*Handler) Save

func (h *Handler) Save(ctx context.Context, mem uint8) error

Save saves the instrument setting to one of the ten non-volatile memory locations.

func (*Handler) SetEventStatusEnable

func (h *Handler) SetEventStatusEnable(ctx context.Context, bit uint8) error

SetEventStatusEnable sets the value in the enable register for the Standard Event Status group. The selected bits are then reported to bit 5 of the Status Byte.

func (*Handler) SetServiceRequestEnable

func (h *Handler) SetServiceRequestEnable(ctx context.Context, bit uint8) error

SetServiceRequestEnable sets the value of the Service Request Enable register.

func (*Handler) Trigger

func (h *Handler) Trigger(ctx context.Context) error

Trigger triggers the device if, and only if, Bus Triggering is the type of trigger event selected. Otherwise, this command is ignored.

func (*Handler) WaitForComplete

func (h *Handler) WaitForComplete(ctx context.Context, timeout time.Duration) error

WaitForComplete waits for all queued operations to complete up to the specified timeout.

type InvalidFormatError

type InvalidFormatError string

InvalidFormatError occures if the format of the response is invalid.

func (InvalidFormatError) Error

func (e InvalidFormatError) Error() string

type InvalidProtocolError

type InvalidProtocolError string

InvalidProtocolError occures if the protocol is invalid.

func (InvalidProtocolError) Error

func (e InvalidProtocolError) Error() string

type TCPClient

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

TCPClient is an implementation of the Client interface for TCP network connections.

func NewTCPClient

func NewTCPClient(addr string, timeout time.Duration) (*TCPClient, error)

NewTCPClient returns a new TCP client of a device controlled using SCPI commands.

func (*TCPClient) BulkExec

func (c *TCPClient) BulkExec(cmds ...string) error

BulkExec implements the Client BulkExec method.

func (*TCPClient) BulkExecContext

func (c *TCPClient) BulkExecContext(ctx context.Context, cmds ...string) error

BulkExecContext implements the Client BulkExecContext method.

func (*TCPClient) Close

func (c *TCPClient) Close() error

Close implements the Client Close method.

func (*TCPClient) Exec

func (c *TCPClient) Exec(cmd string) error

Exec implements the Client Exec method.

func (*TCPClient) ExecContext

func (c *TCPClient) ExecContext(ctx context.Context, cmd string) error

ExecContext implements the Client ExecContext method.

func (*TCPClient) Ping

func (c *TCPClient) Ping() error

Ping implements the Client Ping method.

func (*TCPClient) PingContext

func (c *TCPClient) PingContext(ctx context.Context) error

PingContext implements the Client PingContext method.

func (*TCPClient) Query

func (c *TCPClient) Query(cmd string) (res string, err error)

Query implements the Client Query method.

func (*TCPClient) QueryContext

func (c *TCPClient) QueryContext(ctx context.Context, cmd string) (res string, err error)

QueryContext implements the Client QueryContext method.

Notes

Bugs

  • PingContext is not implemented yet.

Jump to

Keyboard shortcuts

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