Sha256: ee99d0964b3ba08d0450b2cae68f9708e5fe987342f1782ba6c482e03532532e

Contents?: true

Size: 993 Bytes

Versions: 4

Compression:

Stored size: 993 Bytes

Contents

module Lxi
  # Search for LXI-11 instruments on the network and return hash of instruments
  def self.discover_instruments(timeout: 1000, type: :vxi11)
    raise Error, 'LXI Library Initialisation Error' unless lxi_init == LXI_OK

    devices = []
    device_callback =
      FFI::Function.new(:void, %i[pointer pointer]) do |address, id|
        devices << { address: address.read_string, id: id.read_string }
      end

    info = FFIFunctions::LxiInfo.new
    info[:device] = device_callback

    lxi_discover_internal(info, timeout, type)
    sleep 0.1
    devices
  end

  # Discover LXI-11 devices on the LAN
  def self.search(timeout: 1000, type: :vxi11)
    Lxi.init_lxi_session

    info = FFIFunctions::LxiInfo.new
    info[:broadcast] = BroadcastCallback
    info[:device] = DeviceCallback

    puts "Searching for LXI devices - please wait...\n\n"

    result = lxi_discover_internal(info, timeout, type)

    puts "Error during discovery: #{result}" if result.negative?
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lxi_rb-0.4.8 lib/lxi/discovery.rb
lxi_rb-0.4.6 lib/lxi/discovery.rb
lxi_rb-0.4.1 lib/lxi/discovery.rb
lxi_rb-0.4.0 lib/lxi/discovery.rb