Module: PrologixGpib::Usb
- Included in:
- UsbController
- Defined in:
- lib/prologix_gpib/usb.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- EOL =
"\r\n".freeze
Instance Attribute Summary collapse
-
#serial_port ⇒ Object
readonly
Returns the value of attribute serial_port.
Instance Method Summary collapse
- #close ⇒ Object
- #initialize(path, mode: :controller, address: 9) {|_self| ... } ⇒ Object
- #read(bytes) ⇒ Object
- #readline ⇒ Object
- #sr(register = nil) ⇒ Object
- #write(string) ⇒ Object
Instance Attribute Details
#serial_port ⇒ Object (readonly)
Returns the value of attribute serial_port.
9 10 11 |
# File 'lib/prologix_gpib/usb.rb', line 9 def serial_port @serial_port end |
Instance Method Details
#close ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/prologix_gpib/usb.rb', line 22 def close return unless connected? @serial_port.close @serial_port = nil @serial_port.nil? end |
#initialize(path, mode: :controller, address: 9) {|_self| ... } ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/prologix_gpib/usb.rb', line 11 def initialize(path, mode: :controller, address: 9) open_serial_port(path) flush self.mode = mode self.address = address self.auto = :disable self.eos = 0 yield self if block_given? end |
#read(bytes) ⇒ Object
36 37 38 39 40 |
# File 'lib/prologix_gpib/usb.rb', line 36 def read(bytes) return unless connected? @serial_port.read(bytes) end |
#readline ⇒ Object
42 43 44 45 46 |
# File 'lib/prologix_gpib/usb.rb', line 42 def readline return unless connected? t = Timeout.timeout(1, Timeout::Error, 'No response from device') { getline } end |
#sr(register = nil) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/prologix_gpib/usb.rb', line 48 def sr(register = nil) write 'SR' write '++read eoi' array = [] 24.times { array << readline } array.map! { |byte| '%08b' % byte.to_i } register.nil? ? array : array[register - 1] end |
#write(string) ⇒ Object
30 31 32 33 34 |
# File 'lib/prologix_gpib/usb.rb', line 30 def write(string) return unless connected? @serial_port.write("#{string}#{EOL}") end |