Project

lxi_rb

0.0
No release in over a year
The gem includes methods required for discovering and communicating with LXI compliant devices
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.15
 Project Readme

lxi_rb

Gem Version Ruby Ruby

Ruby wrapper for the liblxi library, which offers a simple API for communicating with LXI compatible instruments.

Installation

The gem requires the liblxi library to be installed on the system. The library can be installed and macOS or Linux using Homebrew

brew install liblxi

Install the gem and add to the application's Gemfile by executing:

bundle add lxi_rb

If bundler is not being used to manage dependencies, install the gem by executing:

gem install lxi_rb

Usage

Lxi::Device.new('192.168.10.107') do |multimeter|
    multimeter.send 'MEAS:VOLT:DC?'
    sleep 0.05
    result = multimeter.read 512
    puts Float(result)
end
=> -0.000478767775E-04

NetFinder

The Lxi module provides a NetFinder class for searching for LXI devices on the network and a Device class for communicating with LXI devices.

NetFinder will broadcast a UDP packet to the network and wait for responses from LXI devices. The search method will return an array of hashes containing the IP address and identification string of each device found. By default, the search method will use the VXI-11 UDP broadcast method, but can be configured to use mDNS with the :mdns option.

net = Lxi::NetFinder.new
=> <Lxi::NetFinder:0x00000001047fc538>

net.search
=> [{:address=>"192.168.10.197", :id=>"RIGOL TECHNOLOGIES,M300,MM3A250200001,04.02.00.08.00"}]

irb(main):003:0> net.search :mdns
=> [{:address=>"192.168.10.109", :id=>"dummy-scope LXI", :service=>"lxi", :port=>12345}]

Device API

The Lxi module provides a Device class for communicating with LXI devices. The Device class can be initialized with an IP address. The Device class will attempt to connect to the device when initialized and will raise an exception if the connection fails. The Device class can also be initialized with a block, which will yield the Device object to the block and close the connection when the block exits.

new(address, protocol = :vxi11)

You can create a new instance of the Lxi::Device class by providing a device IP address and an optional protocol (default is :vxi11). It initializes a new instance, initialises the LXI library and attempts to connect to the device.

device = Lxi::Device.new('192.168.10.197')

Attributes

device.id = 0 # The device id (default is -1).
deivice.address = '192.168.10.197' # The IP address for the device.
deivice.port = 1234 # The port for the device (default is 0).
device.name = 'SDM3055 Multimeter' # The name of the device (default is nil).
device.timeout = 500 # The communication timeout in milliseconds (default is 1000).
device.protocol = :vxi11 # The communication protocol (default is :vxi11).

write(message)

The write method will send a string to the device and return the number of bytes written.

device.write 'MEAS:VOLT:DC?'
=> 13

read(512)

The read method will read the specified number of bytes from the device and return a string.

device.read 512
=> "-4.90147020E-04\n"

query(message, bytes = 512, resp_delay: 0.02)

The query method will send a string to the device, read the optional number of bytes from the device and return a string. It also accepts an optional :resp_delay parameter, which will delay the read operation by the specified number of seconds.

device.query 'MEAS:VOLT:DC?', 512, resp_delay: 0.05
=> "-4.97235730E-04\n"

disconnect

The disconnect method will close the connection to the device.

device.disconnect

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/robcarruthers/lxi_rb.

License

The gem is available as open source under the terms of the MIT License.