module PrologixGpib::Usb::Commands

Public Instance Methods

address() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 103
def address
  device_query('++addr')
end
address=(addr) click to toggle source

In :controller mode, address refers to the GPIB address of the instrument being controlled. In :device mode, it is the address of the GPIB peripheral that Prologix GPIB-USB controller is emulating.

# File lib/prologix_gpib/usb/commands.rb, line 98
def address=(addr)
  write("++addr #{addr}")
end
Also aliased as: set_address
auto() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 91
def auto
  device_query('++auto')
end
Also aliased as: auto_read_after_write
auto=(auto_mode) click to toggle source

PrologixGPIB-USB controller can be configured to automatically address instruments to ‘talk’ after sending a command in order to read the response. *** Avaliable in Controller mode. When enabled can cause the prologix controller to lockup. ***

# File lib/prologix_gpib/usb/commands.rb, line 77
def auto=(auto_mode)
  mode =
    case auto_mode
    when :enable, 1, '1'
      1
    when :disable, 0, '0'
      0
    else
      ''
    end
  write("++auto #{mode}")
end
Also aliased as: set_auto_read_after_write
auto_read_after_write()
Alias for: auto
config() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 2
def config
  error_message = 'Error'
  device_version = version.split('version').map(&:strip)
  return { error: error_message } unless device_version.count == 2 && device_version[0].include?('Prologix')
  conf = {}
  conf[:device_name] = device_version[0]
  conf[:firmware] = device_version[1]
  conf[:mode] = { '1' => 'Controller', '0' => 'Device' }.fetch(mode, error_message)
  conf[:device_address] = address[/([1-9])/].nil? ? error_message : address[/([1-9])/]
  conf[:auto_read] = { '1' => 'Enabled', '0' => 'Disabled', 'Unrecognized command' => 'NA' }.fetch(auto, error_message)
  tmo = timeout
  conf[:read_timeout] =
    case tmo
    when 'Unrecognized command'
      'NA'
    when /([1-1000])/
      tmo
    else
      error_message
    end
  conf[:eoi_assertion] = { '1' => 'Enabled', '0' => 'Disabled' }.fetch(eoi, error_message)
  conf[:eos] =
    case eos
    when '0'
      'Append CR+LF'
    when '1'
      'Append CR to instrument commands'
    when '2'
      'Append LF to instrument commands'
    when '3'
      'Do not append anything to instrument commands'
    else
      error_message
    end
  conf[:eot] = { '1' => 'Enabled', '0' => 'Disabled' }.fetch(eot, error_message)
  eot_str = eot_char

  # conf[:eot_char] = eot_str.to_i.chr[/([ -~])/].nil? ? error_message : "'#{eot_str.to_i.chr}', ascii #{eot_str}"
  conf
end
eoi() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 122
def eoi
  device_query('++eoi')
end
eoi=(eoi_mode) click to toggle source

This command enables or disables the assertion of the EOI signal with the last character of any command sent over GPIB port. Some instruments require EOI signal to be asserted in order to properly detect the end of a command.

# File lib/prologix_gpib/usb/commands.rb, line 109
def eoi=(eoi_mode)
  mode =
    case eoi_mode
    when :disable, '0', 0
      0
    when :enable, '1', 1
      1
    else
      raise ArgumentError, "Invalid arg: '#{eoi_mode}'"
    end
  write("++eoi #{mode}")
end
eos() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 140
def eos
  device_query('++eos')
end
eos=(eos_mode) click to toggle source

This command specifies GPIB termination characters. When data from host is received over USB, all non-escaped LF, CR and ESC characters are removed and GPIB terminators, as specified by this command, are appended before sending the data to instruments. This command does not affect data from instruments received over GPIB port. EXAMPLES: 0 Append CR+LF 1 Append CR to instrument commands 2 Append LF to instrument commands 3 Do not append anything to instrument commands

# File lib/prologix_gpib/usb/commands.rb, line 133
def eos=(eos_mode)
  error_message = "Invalid arg: '#{eos_mode}'"
  raise ArgumentError, error_message unless [0, 1, 2, 3].include? eos_mode

  write("++eos #{eos_mode}")
end
eot() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 158
def eot
  device_query('++eot_enable')
end
eot=(eot_mode) click to toggle source

This command enables or disables the appending of a user specified character (see eot_char) to USB output whenever EOI is detected while reading a character from the GPIBport.

# File lib/prologix_gpib/usb/commands.rb, line 145
def eot=(eot_mode)
  mode =
    case eot_mode
    when 0, '0', false, :disable
      0
    when 1, '1', true, :enable
      1
    else
      raise ArgumentError, "Invalid arg: '#{eot_mode}'"
    end
  write("++eot_enable #{mode}")
end
eot_char() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 166
def eot_char
  device_query('++eot_char')
end
eot_char=(char) click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 162
def eot_char=(char)
  write("++eot_enable #{char}")
end
flush() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 190
def flush
  return unless connected?

  loop until serial_port.getbyte.nil?
end
mode() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 58
def mode
  device_query('++mode')
end
Also aliased as: operation_mode
mode=(op_mode) click to toggle source

This command configures the Prologix GPIB-USB controller to be a :controller or :device.

# File lib/prologix_gpib/usb/commands.rb, line 44
def mode=(op_mode)
  mode =
    case op_mode
    when :controller, 1, '1'
      1
    when :device, 0, '0'
      0
    else
      ''
    end
  write("++mode #{mode}")
end
Also aliased as: set_operation_mode
operation_mode()
Alias for: mode
reset() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 186
def reset
  write('++rst')
end
savecfg() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 174
def savecfg
  device_query('++savecfg')
end
set_address(addr)
Alias for: address=
set_auto_read_after_write(auto_mode)
Alias for: auto=
set_operation_mode(op_mode)
Alias for: mode=
spoll(address = nil) click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 178
def spoll(address = nil)
  device_query
end
timeout() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 71
def timeout
  device_query('++read_tmo_ms')
end
timeout=(milliseconds) click to toggle source

Timeout value, in milliseconds, used in the read command and spoll command. Any value between 1 and 3000 milliseconds.

# File lib/prologix_gpib/usb/commands.rb, line 65
def timeout=(milliseconds)
  return unless connected? || milliseconds.class != Integer

  write("++read_tmo_ms #{milliseconds}")
end
trigger(addr_list = []) click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 182
def trigger(addr_list = [])
  write("++trg #{addr_list.join(' ')}")
end
version() click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 170
def version
  device_query('++ver')
end

Private Instance Methods

device_query(command) click to toggle source
# File lib/prologix_gpib/usb/commands.rb, line 198
def device_query(command)
  flush
  write(command)
  readline
end