Git Product home page Git Product logo

lxi's Introduction

lxi

Go-based implementation of the LAN eXtensions for Instrumentation (LXI) standard.

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

Testing

Prior to submitting a pull request, please run the tests using either GNU Make:

$ make check
$ make lint

or you can use Just:

$ just check
$ just lint

To update and view the test coverage report using Make run:

$ make cover

or you can use Just:

$ just cover

License

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

lxi's People

Contributors

matthewrankin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lxi's Issues

make bufio.Reader a member of lxi.Device

Hello,

I would suggest to make the bufio.Reader instantiated in the Query method a member of the Device struct.

There are multiple potential problems with the existing code.

  1. The reader may read more data than the line, if possible. This data will be lost.
  2. The reader allocates buffers for buffering data and the reader object. This creates pressure on the GC.

By making the Reader a member of the Device struct, it becomes persistant as well as its buffers and the data it contains. Is it still possible to use the Read methods and even read bytes per bytes, but efficiently.

Change the Device into this:

type Device struct {
	conn net.Conn
	rdr *bufio.Reader
}

The NewDevice function becomes:

func NewDevice(address string) (*Device, error) {
	v, err := NewVisaResource(address)
	if err != nil {
		return nil, err
	}
	tcpAddress := fmt.Sprintf("%s:%d", v.hostAddress, v.port)
	c, err := net.Dial("tcp", tcpAddress)
	if err != nil {
		return nil, err
	}
	return &Device{conn: c, rdr: bufio.NewReader(c)}, nil
}

Note that the convention is to return a nil Device in case of error.

The Read function becomes:

// Read reads from the network connection into the given byte slice.
func (d *Device) Read(p []byte) (n int, err error) {
	return d.rdr.Read(p)
}

The Close function becomes:

// Close closes the underlying network connection.
func (d *Device) Close() error {
	d.rdr = nil
	c := d.conn
	d.conn = nil
	return c.Close()
}

And Query becomes:

func (d *Device) Query(cmd string) (string, error) {
	err := d.Command(cmd)
	if err != nil {
		return "", err
	}
	return d.rdr.ReadString('\n')
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.