Class: Lxi::Device
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#port ⇒ Object
Returns the value of attribute port.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #connect ⇒ Object (also: #open)
- #disconnect ⇒ Object (also: #close)
-
#initialize(address, protocol = :vxi11) {|_self| ... } ⇒ Device
constructor
A new instance of Device.
- #query(message, bytes = 512, resp_delay: 0.02) ⇒ Object
- #read(length) ⇒ Object (also: #gets)
- #write(message) ⇒ Object (also: #scpi, #send)
Constructor Details
#initialize(address, protocol = :vxi11) {|_self| ... } ⇒ Device
Returns a new instance of Device.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lxi/device.rb', line 9 def initialize(address, protocol = :vxi11) @address = address @port = 0 @name = nil @timeout = 1000 @protocol = protocol @id = -1 connect yield(self) if block_given? end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
7 8 9 |
# File 'lib/lxi/device.rb', line 7 def address @address end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/lxi/device.rb', line 7 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/lxi/device.rb', line 7 def name @name end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/lxi/device.rb', line 7 def port @port end |
#protocol ⇒ Object
Returns the value of attribute protocol.
7 8 9 |
# File 'lib/lxi/device.rb', line 7 def protocol @protocol end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/lxi/device.rb', line 7 def timeout @timeout end |
Instance Method Details
#connect ⇒ Object Also known as: open
22 23 24 25 26 27 28 29 |
# File 'lib/lxi/device.rb', line 22 def connect Lxi.init_session @id = Lxi.connect(@address, @port, @name, @timeout, @protocol) raise(Error, 'LXI Connection Error') if @id == LXI_ERROR true end |
#disconnect ⇒ Object Also known as: close
32 33 34 |
# File 'lib/lxi/device.rb', line 32 def disconnect Lxi.disconnect(@id) end |
#query(message, bytes = 512, resp_delay: 0.02) ⇒ Object
55 56 57 58 59 |
# File 'lib/lxi/device.rb', line 55 def query(, bytes = 512, resp_delay: 0.02) write() sleep :resp_delay read(bytes) end |
#read(length) ⇒ Object Also known as: gets
46 47 48 49 50 51 52 |
# File 'lib/lxi/device.rb', line 46 def read(length) = FFI::MemoryPointer.new(:char, length) bytes_received = Lxi.receive(@id, , length, @timeout) raise(Error, 'LXI communications error') unless bytes_received.positive? .read_string end |
#write(message) ⇒ Object Also known as: scpi, send
37 38 39 40 41 42 |
# File 'lib/lxi/device.rb', line 37 def write() bytes_sent = Lxi.__send(@id, , .length, @timeout) raise(Error, 'LXI communications error') unless bytes_sent.positive? bytes_sent end |