Sha256: d3f0bb3921317998f40edea23e7fb5c3febae97f3c2c2e791e3422bf2fb73a94
Contents?: true
Size: 1.24 KB
Versions: 5
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true module Lxi class Device include FFI attr_accessor :id, :address, :port, :name, :timeout, :protocol def initialize(address, protocol) @address = address @port = 0 @name = nil @timeout = 1000 @protocol = protocol @id = -1 connect yield(self) if block_given? end def connect Lxi.init_lxi_session @id = Lxi.lxi_connect(@address, @port, @name, @timeout, @protocol) raise(Error, 'LXI Connection Error') if @id == LXI_ERROR true end alias open connect def disconnect Lxi.lxi_disconnect(@id) end alias close disconnect def write(message) bytes_sent = Lxi.lxi_send(@id, message, message.length, @timeout) raise(Error, 'LXI communications error') unless bytes_sent.positive? bytes_sent end alias scpi write alias send write def read(length) message = FFI::MemoryPointer.new(:char, length) bytes_received = Lxi.lxi_receive(@id, message, length, @timeout) raise(Error, 'LXI communications error') unless bytes_received.positive? message.read_string end alias gets read def query(message) write(message) read(10_000) end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
lxi_rb-0.8.1 | lib/lxi/device.rb |
lxi_rb-0.8.0 | lib/lxi/device.rb |
lxi_rb-0.7.3 | lib/lxi/device.rb |
lxi_rb-0.7.2 | lib/lxi/device.rb |
lxi_rb-0.7.1 | lib/lxi/device.rb |