module PrologixGpib::Usb
Constants
- EOL
Attributes
serial_port[R]
Public Class Methods
new(path, mode: :controller, address: 9) { |self| ... }
click to toggle source
# File lib/prologix_gpib/usb.rb, line 11 def initialize(path, mode: :controller, address: 9) paths = path.nil? ? PrologixGpib.controller_paths : [path] open_serial_port(paths) flush self.mode = mode self.address = address self.auto = :disable self.eos = 0 yield self if block_given? end
Public Instance Methods
close()
click to toggle source
# File lib/prologix_gpib/usb.rb, line 23 def close return unless connected? @serial_port.close @serial_port = nil @serial_port.nil? end
read(bytes)
click to toggle source
# File lib/prologix_gpib/usb.rb, line 37 def read(bytes) return unless connected? @serial_port.read(bytes) end
readline()
click to toggle source
# File lib/prologix_gpib/usb.rb, line 43 def readline return unless connected? t = Timeout.timeout(1, Timeout::Error, 'No response from Data Acquisistion') { getline } end
sr(register = nil)
click to toggle source
# File lib/prologix_gpib/usb.rb, line 49 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(str)
click to toggle source
# File lib/prologix_gpib/usb.rb, line 31 def write(str) return unless connected? @serial_port.write("#{str}#{EOL}") end
Private Instance Methods
connected?()
click to toggle source
# File lib/prologix_gpib/usb.rb, line 69 def connected? raise Error, 'ConnectionError: No open Prologix device connections.' if @serial_port.nil? true end
getline()
click to toggle source
This method will block until the EOL
terminator is received The lower level gets method is pure ruby, so can be safely used with Timeout.
# File lib/prologix_gpib/usb.rb, line 77 def getline return unless connected? @serial_port.gets(EOL).chomp end
open_serial_port(paths)
click to toggle source
# File lib/prologix_gpib/usb.rb, line 60 def open_serial_port(paths) paths.each do |path| @serial_port = Serial.new(path) write('++ver') return if getline.include? 'Prologix' end raise Error, 'No Prologix USB controllers found.' end