Module: PrologixGpib::Commands
- Included in:
- LanController, UsbController
- Defined in:
- lib/prologix_gpib/commands.rb
Instance Method Summary collapse
- #address ⇒ Object
-
#address=(addr) ⇒ Object
(also: #set_address)
In :controller mode, address refers to the GPIB address of the instrument being controlled.
- #auto ⇒ Object (also: #auto_read_after_write)
-
#auto=(auto_mode) ⇒ Object
(also: #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.
- #config ⇒ Object
- #eoi ⇒ Object
-
#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.
- #eos ⇒ Object
-
#eos=(eos_mode) ⇒ Object
This command specifies GPIB termination characters.
- #eot ⇒ Object
-
#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.
- #eot_char ⇒ Object
- #eot_char=(char) ⇒ Object
- #mode ⇒ Object (also: #operation_mode)
-
#mode=(op_mode) ⇒ Object
(also: #set_operation_mode)
This command configures the Prologix GPIB-USB controller to be a :controller or :device.
- #reset ⇒ Object
- #savecfg ⇒ Object
- #spoll(address = nil) ⇒ Object
- #timeout ⇒ Object
-
#timeout=(milliseconds) ⇒ Object
Timeout value, in milliseconds, used in the read command and spoll command.
- #trigger(addr_list = []) ⇒ Object
- #version ⇒ Object
Instance Method Details
#address ⇒ Object
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 |
#auto ⇒ Object 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 |
#config ⇒ Object
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' device_version = version.split('version').map(&:strip) return { error: } 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, ) conf[:device_address] = address[/([1-9])/].nil? ? : address[/([1-9])/] conf[:auto_read] = { '1' => 'Enabled', '0' => 'Disabled', 'Unrecognized command' => 'NA' }.fetch(auto, ) tmo = timeout conf[:read_timeout] = case tmo when 'Unrecognized command' 'NA' when /([1-1000])/ tmo else end conf[:eoi_assertion] = { '1' => 'Enabled', '0' => 'Disabled' }.fetch(eoi, ) 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 end conf[:eot] = { '1' => 'Enabled', '0' => 'Disabled' }.fetch(eot, ) 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 ⇒ Object
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 |
#eos ⇒ Object
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
133 134 135 136 137 138 |
# File 'lib/prologix_gpib/commands.rb', line 133 def eos=(eos_mode) = "Invalid arg: '#{eos_mode}'" raise ArgumentError, unless [0, 1, 2, 3].include? eos_mode write("++eos #{eos_mode}") end |
#eot ⇒ Object
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_char ⇒ Object
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 |
#mode ⇒ Object 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 |
#reset ⇒ Object
186 187 188 |
# File 'lib/prologix_gpib/commands.rb', line 186 def reset write('++rst') end |
#savecfg ⇒ Object
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 |
#timeout ⇒ Object
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 |
#version ⇒ Object
170 171 172 |
# File 'lib/prologix_gpib/commands.rb', line 170 def version device_query('++ver') end |