rb_visa 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,31 @@
1
+ ##
2
+ # RbVisa
3
+ #
4
+ # Ruby wrapper around National Instrument implementation of the visa API
5
+ # Allows easy scripting for control of your favorite oscilloscopes
6
+ #
7
+ # author hugo benichi
8
+ # email hugo.benichi@m4x.org
9
+ # copyright 2012 hugo benichi
10
+ # homepage http://github.com/hugobenichi/rb_visa
11
+ #
12
+ #
13
+ ##
14
+
15
+
16
+ installation:
17
+
18
+ run "rake gem_install" a the /rb_visa root directory
19
+
20
+ usage:
21
+
22
+ see examples scripts in /rb_visa/test/
23
+
24
+ to_do
25
+
26
+ error handling
27
+ differneces between viRead and viBufRead
28
+ attributes list ?
29
+ reimplement parse and read in C for better efficiency
30
+
31
+ https://dl.dropbox.com/u/26864813/mingw-get-inst-20120426.exe
@@ -0,0 +1,130 @@
1
+ Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
2
+ Copyright (C) Microsoft Corporation. All rights reserved.
3
+
4
+
5
+ Dump of file C:\windows\system32\visa32.dll
6
+
7
+ File Type: DLL
8
+
9
+ Section contains the following exports for visa32.dll
10
+
11
+ 00000000 characteristics
12
+ 4A244942 time date stamp Tue Jun 02 06:33:54 2009
13
+ 0.00 version
14
+ 128 ordinal base
15
+ 167 number of functions
16
+ 106 number of names
17
+
18
+ ordinal hint RVA name
19
+
20
+ 215 0 viAssertIntrSignal (forwarded to visa64.viAssertIntrSignal)
21
+ 258 1 viAssertTrigger (forwarded to visa64.viAssertTrigger)
22
+ 214 2 viAssertUtilSignal (forwarded to visa64.viAssertUtilSignal)
23
+ 203 3 viBufRead (forwarded to visa64.viBufRead)
24
+ 202 4 viBufWrite (forwarded to visa64.viBufWrite)
25
+ 260 5 viClear (forwarded to visa64.viClear)
26
+ 132 6 viClose (forwarded to visa64.viClose)
27
+ 136 7 viDisableEvent (forwarded to visa64.viDisableEvent)
28
+ 137 8 viDiscardEvents (forwarded to visa64.viDiscardEvents)
29
+ 135 9 viEnableEvent (forwarded to visa64.viEnableEvent)
30
+ 130 A viFindNext (forwarded to visa64.viFindNext)
31
+ 129 B viFindRsrc (forwarded to visa64.viFindRsrc)
32
+ 268 C viFlush (forwarded to visa64.viFlush)
33
+ 133 D viGetAttribute (forwarded to visa64.viGetAttribute)
34
+ 128 E viGetDefaultRM (forwarded to visa64.viGetDefaultRM)
35
+ 212 F viGpibCommand (forwarded to visa64.viGpibCommand)
36
+ 210 10 viGpibControlATN (forwarded to visa64.viGpibControlATN)
37
+ 208 11 viGpibControlREN (forwarded to visa64.viGpibControlREN)
38
+ 213 12 viGpibPassControl (forwarded to visa64.viGpibPassControl)
39
+ 211 13 viGpibSendIFC (forwarded to visa64.viGpibSendIFC)
40
+ 261 14 viIn16 (forwarded to visa64.viIn16)
41
+ 224 15 viIn16Ex (forwarded to visa64.viIn16Ex)
42
+ 281 16 viIn32 (forwarded to visa64.viIn32)
43
+ 226 17 viIn32Ex (forwarded to visa64.viIn32Ex)
44
+ 220 18 viIn64 (forwarded to visa64.viIn64)
45
+ 228 19 viIn64Ex (forwarded to visa64.viIn64Ex)
46
+ 273 1A viIn8 (forwarded to visa64.viIn8)
47
+ 222 1B viIn8Ex (forwarded to visa64.viIn8Ex)
48
+ 139 1C viInstallHandler (forwarded to visa64.viInstallHandler)
49
+ 144 1D viLock (forwarded to visa64.viLock)
50
+ 263 1E viMapAddress (forwarded to visa64.viMapAddress)
51
+ 242 1F viMapAddressEx (forwarded to visa64.viMapAddressEx)
52
+ 216 20 viMapTrigger (forwarded to visa64.viMapTrigger)
53
+ 291 21 viMemAlloc (forwarded to visa64.viMemAlloc)
54
+ 243 22 viMemAllocEx (forwarded to visa64.viMemAllocEx)
55
+ 292 23 viMemFree (forwarded to visa64.viMemFree)
56
+ 244 24 viMemFreeEx (forwarded to visa64.viMemFreeEx)
57
+ 200 25 viMove (forwarded to visa64.viMove)
58
+ 201 26 viMoveAsync (forwarded to visa64.viMoveAsync)
59
+ 241 27 viMoveAsyncEx (forwarded to visa64.viMoveAsyncEx)
60
+ 240 28 viMoveEx (forwarded to visa64.viMoveEx)
61
+ 285 29 viMoveIn16 (forwarded to visa64.viMoveIn16)
62
+ 234 2A viMoveIn16Ex (forwarded to visa64.viMoveIn16Ex)
63
+ 287 2B viMoveIn32 (forwarded to visa64.viMoveIn32)
64
+ 236 2C viMoveIn32Ex (forwarded to visa64.viMoveIn32Ex)
65
+ 230 2D viMoveIn64 (forwarded to visa64.viMoveIn64)
66
+ 238 2E viMoveIn64Ex (forwarded to visa64.viMoveIn64Ex)
67
+ 283 2F viMoveIn8 (forwarded to visa64.viMoveIn8)
68
+ 232 30 viMoveIn8Ex (forwarded to visa64.viMoveIn8Ex)
69
+ 286 31 viMoveOut16 (forwarded to visa64.viMoveOut16)
70
+ 235 32 viMoveOut16Ex (forwarded to visa64.viMoveOut16Ex)
71
+ 288 33 viMoveOut32 (forwarded to visa64.viMoveOut32)
72
+ 237 34 viMoveOut32Ex (forwarded to visa64.viMoveOut32Ex)
73
+ 231 35 viMoveOut64 (forwarded to visa64.viMoveOut64)
74
+ 239 36 viMoveOut64Ex (forwarded to visa64.viMoveOut64Ex)
75
+ 284 37 viMoveOut8 (forwarded to visa64.viMoveOut8)
76
+ 233 38 viMoveOut8Ex (forwarded to visa64.viMoveOut8Ex)
77
+ 131 39 viOpen (forwarded to visa64.viOpen)
78
+ 141 3A viOpenDefaultRM (forwarded to visa64.viOpenDefaultRM)
79
+ 262 3B viOut16 (forwarded to visa64.viOut16)
80
+ 225 3C viOut16Ex (forwarded to visa64.viOut16Ex)
81
+ 282 3D viOut32 (forwarded to visa64.viOut32)
82
+ 227 3E viOut32Ex (forwarded to visa64.viOut32Ex)
83
+ 221 3F viOut64 (forwarded to visa64.viOut64)
84
+ 229 40 viOut64Ex (forwarded to visa64.viOut64Ex)
85
+ 274 41 viOut8 (forwarded to visa64.viOut8)
86
+ 223 42 viOut8Ex (forwarded to visa64.viOut8Ex)
87
+ 146 43 viParseRsrc (forwarded to visa64.viParseRsrc)
88
+ 147 44 viParseRsrcEx (forwarded to visa64.viParseRsrcEx)
89
+ 265 45 viPeek16 (forwarded to visa64.viPeek16)
90
+ 289 46 viPeek32 (forwarded to visa64.viPeek32)
91
+ 245 47 viPeek64 (forwarded to visa64.viPeek64)
92
+ 275 48 viPeek8 (forwarded to visa64.viPeek8)
93
+ 266 49 viPoke16 (forwarded to visa64.viPoke16)
94
+ 290 4A viPoke32 (forwarded to visa64.viPoke32)
95
+ 246 4B viPoke64 (forwarded to visa64.viPoke64)
96
+ 276 4C viPoke8 (forwarded to visa64.viPoke8)
97
+ 269 4D viPrintf (forwarded to visa64.viPrintf)
98
+ 279 4E viQueryf (forwarded to visa64.viQueryf)
99
+ 256 4F viRead (forwarded to visa64.viRead)
100
+ 277 50 viReadAsync (forwarded to visa64.viReadAsync)
101
+ 259 51 viReadSTB (forwarded to visa64.viReadSTB)
102
+ 219 52 viReadToFile (forwarded to visa64.viReadToFile)
103
+ 204 53 viSPrintf (forwarded to visa64.viSPrintf)
104
+ 206 54 viSScanf (forwarded to visa64.viSScanf)
105
+ 271 55 viScanf (forwarded to visa64.viScanf)
106
+ 134 56 viSetAttribute (forwarded to visa64.viSetAttribute)
107
+ 267 57 viSetBuf (forwarded to visa64.viSetBuf)
108
+ 142 58 viStatusDesc (forwarded to visa64.viStatusDesc)
109
+ 143 59 viTerminate (forwarded to visa64.viTerminate)
110
+ 140 5A viUninstallHandler (forwarded to visa64.viUninstallHandler)
111
+ 145 5B viUnlock (forwarded to visa64.viUnlock)
112
+ 264 5C viUnmapAddress (forwarded to visa64.viUnmapAddress)
113
+ 217 5D viUnmapTrigger (forwarded to visa64.viUnmapTrigger)
114
+ 294 5E viUsbControlIn (forwarded to visa64.viUsbControlIn)
115
+ 293 5F viUsbControlOut (forwarded to visa64.viUsbControlOut)
116
+ 270 60 viVPrintf (forwarded to visa64.viVPrintf)
117
+ 280 61 viVQueryf (forwarded to visa64.viVQueryf)
118
+ 205 62 viVSPrintf (forwarded to visa64.viVSPrintf)
119
+ 207 63 viVSScanf (forwarded to visa64.viVSScanf)
120
+ 272 64 viVScanf (forwarded to visa64.viVScanf)
121
+ 209 65 viVxiCommandQuery (forwarded to visa64.viVxiCommandQuery)
122
+ 138 66 viWaitOnEvent (forwarded to visa64.viWaitOnEvent)
123
+ 257 67 viWrite (forwarded to visa64.viWrite)
124
+ 278 68 viWriteAsync (forwarded to visa64.viWriteAsync)
125
+ 218 69 viWriteFromFile (forwarded to visa64.viWriteFromFile)
126
+
127
+ Summary
128
+
129
+ 2000 .rdata
130
+ 1000 .rsrc
@@ -0,0 +1,134 @@
1
+ Microsoft (R) COFF/PE Dumper Version 10.00.30319.01
2
+ Copyright (C) Microsoft Corporation. All rights reserved.
3
+
4
+
5
+ Dump of file visa64.dll
6
+
7
+ File Type: DLL
8
+
9
+ Section contains the following exports for visa64.dll
10
+
11
+ 00000000 characteristics
12
+ 4A244941 time date stamp Tue Jun 02 06:33:53 2009
13
+ 0.00 version
14
+ 128 ordinal base
15
+ 167 number of functions
16
+ 106 number of names
17
+
18
+ ordinal hint RVA name
19
+
20
+ 215 0 00008300 viAssertIntrSignal
21
+ 258 1 00006A30 viAssertTrigger
22
+ 214 2 000082B0 viAssertUtilSignal
23
+ 203 3 00006740 viBufRead
24
+ 202 4 000068C0 viBufWrite
25
+ 260 5 00006AD0 viClear
26
+ 132 6 000061B0 viClose
27
+ 136 7 00006450 viDisableEvent
28
+ 137 8 000064C0 viDiscardEvents
29
+ 135 9 000063D0 viEnableEvent
30
+ 130 A 00005B50 viFindNext
31
+ 129 B 00005AA0 viFindRsrc
32
+ 268 C 00006B90 viFlush
33
+ 133 D 00006360 viGetAttribute
34
+ 128 E 00005A80 viGetDefaultRM
35
+ 212 F 000081C0 viGpibCommand
36
+ 210 10 00008120 viGpibControlATN
37
+ 208 11 00007E20 viGpibControlREN
38
+ 213 12 00008240 viGpibPassControl
39
+ 211 13 00008170 viGpibSendIFC
40
+ 261 14 00007180 viIn16
41
+ 224 15 00008940 viIn16Ex
42
+ 281 16 00007290 viIn32
43
+ 226 17 000089C0 viIn32Ex
44
+ 220 18 000087B0 viIn64
45
+ 228 19 00008A40 viIn64Ex
46
+ 273 1A 00007070 viIn8
47
+ 222 1B 000088C0 viIn8Ex
48
+ 139 1C 000065E0 viInstallHandler
49
+ 144 1D 00007C80 viLock
50
+ 263 1E 000078C0 viMapAddress
51
+ 242 1F 00008D00 viMapAddressEx
52
+ 216 20 00008370 viMapTrigger
53
+ 291 21 00007D60 viMemAlloc
54
+ 243 22 00008DD0 viMemAllocEx
55
+ 292 23 00007DD0 viMemFree
56
+ 244 24 00008E40 viMemFreeEx
57
+ 200 25 000073A0 viMove
58
+ 201 26 00007490 viMoveAsync
59
+ 241 27 00008F80 viMoveAsyncEx
60
+ 240 28 00008E90 viMoveEx
61
+ 285 29 00007200 viMoveIn16
62
+ 234 2A 00008B50 viMoveIn16Ex
63
+ 287 2B 00007310 viMoveIn32
64
+ 236 2C 00008BE0 viMoveIn32Ex
65
+ 230 2D 00008830 viMoveIn64
66
+ 238 2E 00008C70 viMoveIn64Ex
67
+ 283 2F 000070F0 viMoveIn8
68
+ 232 30 00008AC0 viMoveIn8Ex
69
+ 286 31 00007720 viMoveOut16
70
+ 235 32 000093A0 viMoveOut16Ex
71
+ 288 33 00007830 viMoveOut32
72
+ 237 34 00009430 viMoveOut32Ex
73
+ 231 35 00009080 viMoveOut64
74
+ 239 36 000094C0 viMoveOut64Ex
75
+ 284 37 00007610 viMoveOut8
76
+ 233 38 00009310 viMoveOut8Ex
77
+ 131 39 00005C30 viOpen
78
+ 141 3A 00005A80 viOpenDefaultRM
79
+ 262 3B 000076A0 viOut16
80
+ 225 3C 00009190 viOut16Ex
81
+ 282 3D 000077B0 viOut32
82
+ 227 3E 00009210 viOut32Ex
83
+ 221 3F 00009550 viOut64
84
+ 229 40 00009290 viOut64Ex
85
+ 274 41 00007590 viOut8
86
+ 223 42 00009110 viOut8Ex
87
+ 146 43 00007EF0 viParseRsrc
88
+ 147 44 00008460 viParseRsrcEx
89
+ 265 45 00007A50 viPeek16
90
+ 289 46 00007AC0 viPeek32
91
+ 245 47 000095D0 viPeek64
92
+ 275 48 000079E0 viPeek8
93
+ 266 49 00007BA0 viPoke16
94
+ 290 4A 00007C10 viPoke32
95
+ 246 4B 00009640 viPoke64
96
+ 276 4C 00007B30 viPoke8
97
+ 269 4D 00006BE0 viPrintf
98
+ 279 4E 00006F80 viQueryf
99
+ 256 4F 000066C0 viRead
100
+ 277 50 000067C0 viReadAsync
101
+ 259 51 00006A80 viReadSTB
102
+ 219 52 00008020 viReadToFile
103
+ 204 53 00006CC0 viSPrintf
104
+ 206 54 00006E90 viSScanf
105
+ 271 55 00006DB0 viScanf
106
+ 134 56 000062F0 viSetAttribute
107
+ 267 57 00006B20 viSetBuf
108
+ 142 58 00006210 viStatusDesc
109
+ 143 59 000069C0 viTerminate
110
+ 140 5A 00006650 viUninstallHandler
111
+ 145 5B 00007D10 viUnlock
112
+ 264 5C 00007990 viUnmapAddress
113
+ 217 5D 000083F0 viUnmapTrigger
114
+ 294 5E 000086C0 viUsbControlIn
115
+ 293 5F 000085F0 viUsbControlOut
116
+ 270 60 00006C50 viVPrintf
117
+ 280 61 00006FF0 viVQueryf
118
+ 205 62 00006D30 viVSPrintf
119
+ 207 63 00006F00 viVSScanf
120
+ 272 64 00006E20 viVScanf
121
+ 209 65 00007E70 viVxiCommandQuery
122
+ 138 66 00006530 viWaitOnEvent
123
+ 257 67 00006840 viWrite
124
+ 278 68 00006940 viWriteAsync
125
+ 218 69 000080A0 viWriteFromFile
126
+
127
+ Summary
128
+
129
+ 2000 .data
130
+ 1000 .pdata
131
+ 5000 .rdata
132
+ 1000 .reloc
133
+ 1000 .rsrc
134
+ B000 .text
@@ -0,0 +1,7 @@
1
+ module RbVisa
2
+
3
+ require "ffi"
4
+ require "rb_visa/visa"
5
+ require "rb_visa/session"
6
+
7
+ end
@@ -0,0 +1,89 @@
1
+ module RbVisa
2
+
3
+ class Session
4
+
5
+ def buffer_grow size
6
+ if size > @string_buffer_length
7
+ @string_buffer = FFI::MemoryPointer.new :char, size
8
+ @string_buffer_length = size
9
+ end
10
+ end
11
+
12
+ def write command
13
+ buffer_grow command.length
14
+ @string_buffer.write_string command
15
+ @read_count ||= FFI::MemoryPointer.new :uint32, 1
16
+ check VISA::viWrite @session, @string_buffer, command.length, @read_count
17
+ #puts "write count %i" % @read_count.read_uint32
18
+ self
19
+ end
20
+
21
+ def read bytes = @string_buffer_length
22
+ buffer_grow bytes
23
+ @read_count ||= FFI::MemoryPointer.new :uint32, 1
24
+ check VISA::viRead @session, @string_buffer, bytes, @read_count
25
+ #puts "read count %i" % @read_count.read_uint32
26
+ @string_buffer.read_string(@read_count.read_uint32).chomp
27
+ end
28
+
29
+ def << command
30
+ self.write command
31
+ end
32
+
33
+ def query command
34
+ self.write(command).read
35
+ end
36
+
37
+ def id?
38
+ query "*idn?"
39
+ end
40
+
41
+ def parse
42
+ @read_count ||= FFI::MemoryPointer.new :uint32, 1
43
+
44
+ comp = "#".bytes.first
45
+ offset = '0'.bytes.first
46
+
47
+ #find beginning of header
48
+ while true
49
+ check VISA::viRead @session, @string_buffer, 1, @read_count
50
+ break if comp == @string_buffer.read_char
51
+ end
52
+
53
+ #read the size of the header tag
54
+ check VISA::viRead @session, @string_buffer, 1, @read_count
55
+ data_size_tag_size = @string_buffer.read_char - offset
56
+ #puts "data_size_tag size: %i" % data_size_tag_size
57
+
58
+ #read the header tag and parse into an int
59
+ check VISA::viRead @session, @string_buffer, data_size_tag_size, @read_count
60
+ size = @string_buffer.read_array_of_char(data_size_tag_size).map{ |c|
61
+ c - offset
62
+ }.join.to_i
63
+ puts "data size: %i" % size
64
+ size
65
+ end
66
+
67
+ def mread_into chunk, &next_buffer
68
+ total = 0
69
+ (self.parse / chunk).times do
70
+ VISA::viRead @session, next_buffer.call, chunk, @read_count
71
+ puts "mread read count %i" % @read_count.read_uint32
72
+ total += @read_count.read_uint32
73
+ end
74
+ total
75
+ end
76
+
77
+ def mread_to chunk, &handle_data
78
+ buffer_grow.chunk
79
+ total = 0
80
+ (self.parse / chunk).times do
81
+ VISA::viRead @session, @string_buffer, chunk, @read_count
82
+ handle_data.call @string_buffer.read_array_of_char chunk
83
+ total += @read_count.read_uint32
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,79 @@
1
+ module RbVisa
2
+
3
+ class Session
4
+
5
+ attr_reader :session, :rm, :status, :address
6
+
7
+ def initialize address, &block
8
+ mem = FFI::MemoryPointer.new :uint32, 1
9
+ check VISA::viOpenDefaultRM mem
10
+ puts "ressource manager opened"
11
+ @rm = mem.read_uint32
12
+ @address = address
13
+ check VISA::viOpen( @rm, @address, VISA::VI_NULL, VISA::VI_NULL, mem)
14
+ puts "session opened"
15
+ @session = mem.read_uint32
16
+
17
+ @string_buffer_length = 126
18
+ @string_buffer = FFI::MemoryPointer.new :char, @string_buffer_length
19
+
20
+ self.instance_eval &block if block
21
+ self
22
+ end
23
+
24
+ def close
25
+ check VISA::viClose @session
26
+ check VISA::viClose @rm
27
+ end
28
+
29
+ def self.release object
30
+ object.close
31
+ end
32
+
33
+ def check status
34
+ puts self.status? if 0 > (@status = status)
35
+ self
36
+ end
37
+
38
+ def status?
39
+ puts "error code #{@status} for #{@session ||@rm}"
40
+ @error_buffer ||= FFI::MemoryPointer.new :char, 256
41
+ VISA::viStatusDesc @session||@rm, @status, @error_buffer
42
+ @error_buffer.read_string
43
+ end
44
+
45
+ def clear
46
+ check VISA::viClear @session
47
+ self
48
+ end
49
+
50
+ def flush mask_val = VISA::VI_READ_BUF_DISCARD
51
+ check VISA::viFlush @session, mask_val
52
+ self
53
+ end
54
+
55
+ def buffer params = {}
56
+ VISA::Buffer.each_pair{ |buf,mask|
57
+ check VISA::viSetBuf( @session, mask, params[buf] ) if params[buf] && params[buf] > 0
58
+ } if params.is_a? Hash
59
+ self
60
+ end
61
+
62
+ def [] name
63
+ mem = FFI::MemoryPointer.new :uint32, 1
64
+ name = VISA.const_get(name) if name.is_a? Symbol
65
+ check VISA::viGetAttribute( @session, name, mem )
66
+ return mem.read_uint32
67
+ end
68
+
69
+ def []= name, value
70
+ name = VISA.const_get(name) if name.is_a? Symbol
71
+ value = VISA.const_get(value) if value.is_a? Symbol
72
+ check VISA::viSetAttribute( @session, name, value )
73
+ end
74
+
75
+ require 'rb_visa/io'
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,38 @@
1
+ module RbVisa
2
+
3
+ module VISA
4
+ path='C:\Windows\System32\visa32.dll' # <TO_DO> read path from configuration file
5
+ extend FFI::Library
6
+ ffi_lib path
7
+
8
+ require 'rb_visa/visa/template'
9
+ Template.each{ |sig| attach_function *sig }
10
+
11
+ VI_NULL = 0
12
+ VI_FALSE = 0
13
+ VI_TRUE = 1
14
+
15
+ # buffer settings
16
+ VI_READ_BUF = 1
17
+ VI_WRITE_BUF = 2
18
+ VI_READ_BUF_DISCARD = 4
19
+ VI_WRITE_BUF_DISCARD = 8
20
+ VI_ASRL_IN_BUF = 16 # VI_IO_IN_BUF
21
+ VI_ASRL_OUT_BUF = 32 # VI_IO_out_BUF
22
+ VI_ASRL_IN_BUF_DISCARD = 64 # VI_IO_IN_BUF_DISCARD
23
+ VI_ASRL_OUT_BUF_DISCARD = 128 # VI_IO_OUT_BUF_DISCARD
24
+
25
+ Buffer = {
26
+ read: VI_READ_BUF,
27
+ write: VI_WRITE_BUF,
28
+ asrl_in: VI_ASRL_IN_BUF,
29
+ asrl_out: VI_ASRL_OUT_BUF,
30
+ }
31
+
32
+ # other attributes
33
+ VI_ATTR_TMO_VALUE = "3fff001a".hex
34
+ VI_TMO_INFINITE = "FFFFFFFF".hex
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,79 @@
1
+ module RbVisa
2
+
3
+ module VISA
4
+
5
+ Template = [
6
+ [ :viOpenDefaultRM,
7
+ [ :pointer], # :uint32* which stores the ressource manager handle
8
+ :int32],
9
+
10
+ [ :viOpen,
11
+ [ :uint32, # ressource manager handle
12
+ :pointer, # device address
13
+ :uint32, # access mode
14
+ :uint32, # timeout
15
+ :pointer], # :uint32* which stores the session handle
16
+ :int32],
17
+
18
+ [ :viClose,
19
+ [:uint32], # session/ressource manager handle
20
+ :int32],
21
+
22
+ [ :viClear,
23
+ [:uint32], # session/ressource manager handle
24
+ :int32],
25
+
26
+ [ :viStatusDesc,
27
+ [ :uint32, # session handle
28
+ :int32, # status code
29
+ :pointer], # char* output description of the status code
30
+ :int32],
31
+
32
+ [ :viSetAttribute,
33
+ [ :uint32, # session handle
34
+ :uint32, # attribute name
35
+ :uint32], # attribute state (can be 64bits, need to check !)
36
+ :int32],
37
+
38
+ [ :viGetAttribute,
39
+ [ :uint32, # session handle
40
+ :uint32, # attribute name
41
+ :pointer], # uint32* attribute state outpout (can be 64bits, need to check !)
42
+ :int32],
43
+
44
+ [ :viSetBuf,
45
+ [ :uint32, # session handle
46
+ :uint16, # mask
47
+ :uint32], # size
48
+ :int32],
49
+
50
+ [ :viWrite,
51
+ [ :uint32, # session handle
52
+ :pointer, # uint8* buffer for input data
53
+ :uint32, # buffer size
54
+ :pointer], # uint32* which stores the number of bytes written to the device
55
+ :int32],
56
+
57
+ [ :viRead,
58
+ [ :uint32, # session handle
59
+ :pointer, # char* pointer to output buffer
60
+ :uint32, # number of bytes to read
61
+ :pointer], # uint32* which stores the number of bytes written to the buffer
62
+ :int32],
63
+
64
+ [ :viBufRead,
65
+ [ :uint32, # session handle
66
+ :pointer, # char* pointer to output buffer
67
+ :uint32, # number of bytes to read
68
+ :pointer], # uint32* which stores the number of bytes written to the buffer
69
+ :int32],
70
+
71
+ [ :viFlush,
72
+ [ :uint32, # session handle
73
+ :uint16], # mask
74
+ :int32],
75
+ ]
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,20 @@
1
+ require 'rake/clean'
2
+
3
+ name = 'rb_visa'
4
+
5
+ task :test_local do
6
+ ruby "-I./lib test/test_rbvisa.rb"
7
+ end
8
+
9
+ task :test_global do
10
+ ruby "test/test_rbvisa.rb"
11
+ end
12
+
13
+ task :gem_install => :gem_build do
14
+ gemfile = Dir.new("./").entries.select{ |f| f =~ /rb_visa-[\d]+\.[\d]+\.[\d]+.gem/ }[0]
15
+ sh "gem install %s" % gemfile
16
+ end
17
+
18
+ task :gem_build do
19
+ sh "gem build %s.gemspec" % name
20
+ end
@@ -0,0 +1,101 @@
1
+ puts "-- TES voltage measurement script --","",
2
+ "send complains to hugo.benichi@m4x.org",
3
+ "loading modules..."
4
+
5
+ require 'rb_visa'
6
+ require 'fileutils'
7
+ require 'cbuffer'
8
+ require 'highline/system_extensions'
9
+
10
+ data_dir = ""
11
+ date = Time.new
12
+ base_dir = "%s/%i-%i-%i" % [data_dir, date.year, date.month, date.day]
13
+ FileUtils::mkdir_p base_dir
14
+ data_path = "%s/%ih%imin" [base_dir, data.hour, data.min]
15
+ data_path += "_%s" % ARGV[0] if ARGV[0]
16
+
17
+
18
+ size = 1000 # size of one frame
19
+ ff_count = 5000 # ff frames chunk
20
+ frm_tot = 100000 # total frames
21
+ chunk = 100000 # bytes
22
+ repet = 20 # number of curve? cycles
23
+ scale = 1E-6
24
+ sample = 100E6
25
+
26
+ puts "datapath: %s" % data_path,
27
+ "samplerate: %s MHz" % (sample / 100000),
28
+ "scale/div: %s ms" % (scale * 1000),
29
+ "frame size: %i bytes" % (sample*scale*10),
30
+ "recording %i FastFrame chunks of %i frames each" % [repet, ff_count],
31
+ "transferring %i bytes at a time (= %i frames)" % [chunk, chunk / (sample*scale*10)]
32
+
33
+
34
+ buffer = CBuffer.new( path: data_path, chunk: chunk, length: chunk*126 )
35
+
36
+
37
+ tek = RbVisa::Session.new 'TCPIP0::133.243.104.179::inst0::INSTR'
38
+ tek[:VI_ATTR_TMO_VALUE] = :VI_TMO_INFINITE
39
+ puts tek.id?
40
+
41
+ [
42
+ "*CLS",
43
+ "HEADER OFF",
44
+ "DISPLAY:WAVEFORM:OFF",
45
+ "SELECT:CH1 ON;CH2 OFF;CH3 OFF;CH4 ON",
46
+
47
+ "TRIGGER:A:TYPE EDGE",
48
+ "TRIGGER:MODE NORMAL",
49
+ "TRIGGER:LEVEL 1.0",
50
+ "TRIGGER:A:EDGE:SOURCE CH4",
51
+ "TRIGGER:SLOPE RISE",
52
+
53
+ "HORIZONTAL:FASTFRAME:STATE ON",
54
+ "HORIZONTAL:FASTFRAME:COUNT #{ff_count}",
55
+ "HORIZONTAL:FASTFRAME:SEQUENCE FIRST",
56
+ "HORIZONTAL:MODE:SCALE 1E-6",
57
+ "HORIZONTAL:MODE:SAMPLERATE 100E6",
58
+ "HORIZONTAL:MAIN:POSITION 50",
59
+
60
+ "DATA:START 1;STOP 1000",
61
+ "DATA:FRAMESTART 1",
62
+ "DATA:FRAMESTOP #{frm_tot}",
63
+ "DATA:SOURCE CH1",
64
+ "DATA:ENCDG FASTEST",
65
+ "WFMOUTPRE:BYT_NR 1",
66
+
67
+ "ACQUIRE:SAMPLINGMODE RT",
68
+ "ACQUIRE:MODE SAMPLE",
69
+ "ACQUIRE:STOPAFTER RUNSTOP",
70
+ ].each{ |c| tek.write c }
71
+
72
+
73
+ buffer = FFI::MemoryPointer.new :char, 1000000
74
+
75
+
76
+
77
+ puts "Tektronix oscillo ready for acquisition",
78
+ " press return to start"
79
+ $stdin.gets
80
+
81
+ buffer.write{ |count| puts "wrote #{count} chunks of data" }
82
+ tek.write "ACQUIRE:STATE RUN"
83
+
84
+ time_start = Time.new
85
+ repet.times do |i|
86
+ puts "chunk number %i" % i
87
+ tek.write "CURVE?"
88
+ read = tek.mread_into(chunk) { buffer.next }
89
+ puts "total read: %i" % read
90
+ end
91
+ puts "measurement time: %is" % (Time.new-time_start),
92
+
93
+ buffer.stop
94
+ puts "transfer time to HD: %is" % (Time.new-time_start),
95
+
96
+ tek.write "*CLS"
97
+
98
+ puts "measurement script over",
99
+ "press any key to close this window"
100
+
101
+ HighLine::SystemExtensions::get_character.chr
@@ -0,0 +1,3 @@
1
+ :: batch script for starting TES_measurement (double-click friendly)
2
+
3
+ start ruby TES_measurement.rb
@@ -0,0 +1,26 @@
1
+ @echo off
2
+ setlocal enableDelayedExpansion
3
+ set NL=^
4
+
5
+
6
+ rem two empty line required
7
+ set program=require 'rb_visa'
8
+ set program=!program!!NL!require 'highline/system_extensions'
9
+ set program=!program!!NL!include HighLine::SystemExtensions
10
+ set program=!program!!NL!address = 'TCPIP0::133.243.104.179::inst0::INSTR'
11
+ set program=!program!!NL!puts '', 'default parameters for ' + address
12
+ set program=!program!!NL!tek = RbVisa::Session.new address
13
+ set program=!program!!NL!puts tek.id?
14
+ set program=!program!!NL!tek.write 'HORIZONTAL:FASTFRAME:STATE OFF'
15
+ set program=!program!!NL!tek.write 'SELECT:CH1 ON;CH2 OFF;CH3 OFF;CH4 OFF'
16
+ set program=!program!!NL!tek.write 'TRIGGER:A:TYPE EDGE;MODE NORMAL;LEVEL 1.0'
17
+ set program=!program!!NL!tek.write 'TRIGGER:A:MODE AUTO'
18
+ set program=!program!!NL!tek.write 'HORIZONTAL:MODE:SCALE 2E-3;SAMPLERATE 500E3'
19
+ set program=!program!!NL!tek.write 'HORIZONTAL:MAIN:POSITION 50'
20
+ set program=!program!!NL!tek.write 'DISPLAY:WAVEFORM ON'
21
+ set program=!program!!NL!tek.write 'ACQUIRE:STOPAFTER RUNSTOP'
22
+ set program=!program!!NL!tek.write 'ACQUIRE:STATE RUN'
23
+ set program=!program!!NL!puts 'press any key to close this window'
24
+ set program=!program!!NL!get_character.chr
25
+
26
+ ruby -e "!program!"
@@ -0,0 +1,5 @@
1
+ require 'rb_visa'
2
+
3
+ tek = RbVisa::Session.new("TCPIP0::133.243.104.179::inst0::INSTR")
4
+
5
+ puts tek.id?
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb_visa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hugo Benichi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A Ruby layer wrapping around the Ni-VISA calls. Based on the ffi gem
15
+ email: hugo.benichi@m4x.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/rb_visa.rb
21
+ - lib/rb_visa/visa/template.rb
22
+ - lib/rb_visa/visa.rb
23
+ - lib/rb_visa/session.rb
24
+ - lib/rb_visa/io.rb
25
+ - ext/rb_visa/visa32.def
26
+ - ext/rb_visa/visa64.def
27
+ - test/test_rbvisa.rb
28
+ - test/TES_measurement.rb
29
+ - test/reset.bat
30
+ - test/measurement_starter.bat
31
+ - rakefile.rb
32
+ - README
33
+ homepage: http://github.com/hugobenichi/rb_visa
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.11
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Ruby wrapper to NI-VISA API for measurement devices automation
57
+ test_files: []