Sha256: 8c382ca23afc029851b60cbab6d87e157809dd7d2d353e27dbc9a8242322bafd

Contents?: true

Size: 1011 Bytes

Versions: 3

Compression:

Stored size: 1011 Bytes

Contents

# frozen_string_literal: true
module Lxi
  # Search for LXI-11 instruments on the network and return hash of instruments
  def self.discover(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

3 entries across 3 versions & 1 rubygems

Version Path
lxi_rb-0.7.0 lib/lxi/discovery.rb
lxi_rb-0.6.4 lib/lxi/discovery.rb
lxi_rb-0.6.3 lib/lxi/discovery.rb