Class: RbVisa::Session
- Inherits:
-
Object
- Object
- RbVisa::Session
- Defined in:
- lib/rb_visa/io.rb,
lib/rb_visa/session.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#rm ⇒ Object
readonly
Returns the value of attribute rm.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(command) ⇒ Object
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #buffer(params = {}) ⇒ Object
- #buffer_grow(size) ⇒ Object
- #check(status) ⇒ Object
- #clear ⇒ Object
- #close ⇒ Object
- #flush(mask_val = VISA::VI_READ_BUF_DISCARD) ⇒ Object
- #id? ⇒ Boolean
-
#initialize(address, &block) ⇒ Session
constructor
A new instance of Session.
- #mread_into(chunk, &next_buffer) ⇒ Object
- #mread_to(chunk, &handle_data) ⇒ Object
- #parse ⇒ Object
- #query(command) ⇒ Object
- #read(bytes = @string_buffer_length) ⇒ Object
- #status? ⇒ Boolean
- #write(command) ⇒ Object
Constructor Details
#initialize(address, &block) ⇒ Session
Returns a new instance of Session.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rb_visa/session.rb', line 7 def initialize address, &block mem = FFI::MemoryPointer.new :uint32, 1 check VISA::viOpenDefaultRM mem puts "ressource manager opened" @rm = mem.read_uint32 @address = address check VISA::viOpen( @rm, @address, VISA::VI_NULL, VISA::VI_NULL, mem) puts "session opened" @session = mem.read_uint32 @string_buffer_length = 126 @string_buffer = FFI::MemoryPointer.new :char, @string_buffer_length self.instance_eval &block if block self end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
5 6 7 |
# File 'lib/rb_visa/session.rb', line 5 def address @address end |
#rm ⇒ Object (readonly)
Returns the value of attribute rm.
5 6 7 |
# File 'lib/rb_visa/session.rb', line 5 def rm @rm end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
5 6 7 |
# File 'lib/rb_visa/session.rb', line 5 def session @session end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/rb_visa/session.rb', line 5 def status @status end |
Class Method Details
.release(object) ⇒ Object
29 30 31 |
# File 'lib/rb_visa/session.rb', line 29 def self.release object object.close end |
Instance Method Details
#<<(command) ⇒ Object
29 30 31 |
# File 'lib/rb_visa/io.rb', line 29 def << command self.write command end |
#[](name) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/rb_visa/session.rb', line 62 def [] name mem = FFI::MemoryPointer.new :uint32, 1 name = VISA.const_get(name) if name.is_a? Symbol check VISA::viGetAttribute( @session, name, mem ) return mem.read_uint32 end |
#[]=(name, value) ⇒ Object
69 70 71 72 73 |
# File 'lib/rb_visa/session.rb', line 69 def []= name, value name = VISA.const_get(name) if name.is_a? Symbol value = VISA.const_get(value) if value.is_a? Symbol check VISA::viSetAttribute( @session, name, value ) end |
#buffer(params = {}) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/rb_visa/session.rb', line 55 def buffer params = {} VISA::Buffer.each_pair{ |buf,mask| check VISA::viSetBuf( @session, mask, params[buf] ) if params[buf] && params[buf] > 0 } if params.is_a? Hash self end |
#buffer_grow(size) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/rb_visa/io.rb', line 5 def buffer_grow size if size > @string_buffer_length @string_buffer = FFI::MemoryPointer.new :char, size @string_buffer_length = size end end |
#check(status) ⇒ Object
33 34 35 36 |
# File 'lib/rb_visa/session.rb', line 33 def check status puts self.status? if 0 > (@status = status) self end |
#clear ⇒ Object
45 46 47 48 |
# File 'lib/rb_visa/session.rb', line 45 def clear check VISA::viClear @session self end |
#close ⇒ Object
24 25 26 27 |
# File 'lib/rb_visa/session.rb', line 24 def close check VISA::viClose @session check VISA::viClose @rm end |
#flush(mask_val = VISA::VI_READ_BUF_DISCARD) ⇒ Object
50 51 52 53 |
# File 'lib/rb_visa/session.rb', line 50 def flush mask_val = VISA::VI_READ_BUF_DISCARD check VISA::viFlush @session, mask_val self end |
#id? ⇒ Boolean
37 38 39 |
# File 'lib/rb_visa/io.rb', line 37 def id? query "*idn?" end |
#mread_into(chunk, &next_buffer) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/rb_visa/io.rb', line 67 def mread_into chunk, &next_buffer total = 0 (self.parse / chunk).times do VISA::viRead @session, next_buffer.call, chunk, @read_count puts "mread read count %i" % @read_count.read_uint32 total += @read_count.read_uint32 end total end |
#mread_to(chunk, &handle_data) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/rb_visa/io.rb', line 77 def mread_to chunk, &handle_data buffer_grow.chunk total = 0 (self.parse / chunk).times do VISA::viRead @session, @string_buffer, chunk, @read_count handle_data.call @string_buffer.read_array_of_char chunk total += @read_count.read_uint32 end end |
#parse ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rb_visa/io.rb', line 41 def parse @read_count ||= FFI::MemoryPointer.new :uint32, 1 comp = "#".bytes.first offset = '0'.bytes.first #find beginning of header while true check VISA::viRead @session, @string_buffer, 1, @read_count break if comp == @string_buffer.read_char end #read the size of the header tag check VISA::viRead @session, @string_buffer, 1, @read_count data_size_tag_size = @string_buffer.read_char - offset #puts "data_size_tag size: %i" % data_size_tag_size #read the header tag and parse into an int check VISA::viRead @session, @string_buffer, data_size_tag_size, @read_count size = @string_buffer.read_array_of_char(data_size_tag_size).map{ |c| c - offset }.join.to_i puts "data size: %i" % size size end |
#query(command) ⇒ Object
33 34 35 |
# File 'lib/rb_visa/io.rb', line 33 def query command self.write(command).read end |
#read(bytes = @string_buffer_length) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/rb_visa/io.rb', line 21 def read bytes = @string_buffer_length buffer_grow bytes @read_count ||= FFI::MemoryPointer.new :uint32, 1 check VISA::viRead @session, @string_buffer, bytes, @read_count #puts "read count %i" % @read_count.read_uint32 @string_buffer.read_string(@read_count.read_uint32).chomp end |
#status? ⇒ Boolean
38 39 40 41 42 43 |
# File 'lib/rb_visa/session.rb', line 38 def status? puts "error code #{@status} for #{@session ||@rm}" @error_buffer ||= FFI::MemoryPointer.new :char, 256 VISA::viStatusDesc @session||@rm, @status, @error_buffer @error_buffer.read_string end |
#write(command) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/rb_visa/io.rb', line 12 def write command buffer_grow command.length @string_buffer.write_string command @read_count ||= FFI::MemoryPointer.new :uint32, 1 check VISA::viWrite @session, @string_buffer, command.length, @read_count #puts "write count %i" % @read_count.read_uint32 self end |