Module: PrologixGpib::Commands

Included in:
LanController, UsbController
Defined in:
lib/prologix_gpib/commands.rb

Instance Method Summary collapse

Instance Method Details

#addressObject



103
104
105
# File 'lib/prologix_gpib/commands.rb', line 103

def address
  device_query('++addr')
end

#address=(addr) ⇒ Object Also known as: set_address

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.



98
99
100
# File 'lib/prologix_gpib/commands.rb', line 98

def address=(addr)
  write("++addr #{addr}")
end

#autoObject Also known as: auto_read_after_write



91
92
93
# File 'lib/prologix_gpib/commands.rb', line 91

def auto
  device_query('++auto')
end

#auto=(auto_mode) ⇒ Object Also known as: set_auto_read_after_write

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. ***



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/prologix_gpib/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

#configObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/prologix_gpib/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

#eoiObject



122
123
124
# File 'lib/prologix_gpib/commands.rb', line 122

def eoi
  device_query('++eoi')
end

#eoi=(eoi_mode) ⇒ Object

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.



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/prologix_gpib/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

#eosObject



140
141
142
# File 'lib/prologix_gpib/commands.rb', line 140

def eos
  device_query('++eos')
end

#eos=(eos_mode) ⇒ Object

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

Raises:



133
134
135
136
137
138
# File 'lib/prologix_gpib/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

#eotObject



158
159
160
# File 'lib/prologix_gpib/commands.rb', line 158

def eot
  device_query('++eot_enable')
end

#eot=(eot_mode) ⇒ Object

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.



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/prologix_gpib/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_charObject



166
167
168
# File 'lib/prologix_gpib/commands.rb', line 166

def eot_char
  device_query('++eot_char')
end

#eot_char=(char) ⇒ Object



162
163
164
# File 'lib/prologix_gpib/commands.rb', line 162

def eot_char=(char)
  write("++eot_enable #{char}")
end

#modeObject Also known as: operation_mode



58
59
60
# File 'lib/prologix_gpib/commands.rb', line 58

def mode
  device_query('++mode')
end

#mode=(op_mode) ⇒ Object Also known as: set_operation_mode

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



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/prologix_gpib/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

#resetObject



186
187
188
# File 'lib/prologix_gpib/commands.rb', line 186

def reset
  write('++rst')
end

#savecfgObject



174
175
176
# File 'lib/prologix_gpib/commands.rb', line 174

def savecfg
  device_query('++savecfg')
end

#spoll(address = nil) ⇒ Object



178
179
180
# File 'lib/prologix_gpib/commands.rb', line 178

def spoll(address = nil)
  device_query
end

#timeoutObject



71
72
73
# File 'lib/prologix_gpib/commands.rb', line 71

def timeout
  device_query('++read_tmo_ms')
end

#timeout=(milliseconds) ⇒ Object

Timeout value, in milliseconds, used in the read command and spoll command.

Any value between 1 and 3000 milliseconds.



65
66
67
68
69
# File 'lib/prologix_gpib/commands.rb', line 65

def timeout=(milliseconds)
  return unless connected? || milliseconds.class != Integer

  write("++read_tmo_ms #{milliseconds}")
end

#trigger(addr_list = []) ⇒ Object



182
183
184
# File 'lib/prologix_gpib/commands.rb', line 182

def trigger(addr_list = [])
  write("++trg #{addr_list.join(' ')}")
end

#versionObject



170
171
172
# File 'lib/prologix_gpib/commands.rb', line 170

def version
  device_query('++ver')
end