forked from jpoirier/visa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisa.go
852 lines (727 loc) · 28.3 KB
/
visa.go
1
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
// Copyright (c) 2014 Joseph D Poirier
// Distributable under the terms of The simplified BSD License
// that can be found in the LICENSE file.
// Package visa wraps National Instruments VISA (Virtual Instrument Software
// Architecture) driver. The driver allows a client application to communicate
// with most instrumentation buses including GPIB, USB, Serial, and Ethernet.
// The Virtual Instrument Software Architecture (VISA) is a standard for
// configuring, programming, and troubleshooting instrumentation systems
// comprising GPIB, VXI, PXI, serial (RS232/RS485), Ethernet/LXI, and/or USB
// interfaces.
//
// The package is low level and, for the most part, is one-to-one with the
// exported C functions it wraps. Clients would typically build an instrument
// specific driver around the package but it can also be used directly.
//
// NI-VISA Drivers:
// http://www.ni.com/downloads/ni-drivers/
//
// NI-VISA Overview:
// http://www.ni.com/white-paper/3702/en/
//
// Operation specific sections:
// Resource Manager Functions and Operations
// Resource Template Operations
// Basic I/O Operations
// Formatted and Buffered I/O Operations (limited printf and scanf functionality)
// Memory I/O Operations
// Shared Memory Operations
// Interface Specific Operations
package visa
/*
#cgo linux LDFLAGS: -lvisa
#cgo darwin LDFLAGS: -framework VISA
#cgo windows LDFLAGS: -lvisa64 -L.
#cgo windows CFLAGS: -IC:/Program\ Files/IVI\ Foundation/VISA/Win64/Include
#cgo CFLAGS: -I.
#include <stdlib.h>
#include "visa.h"
extern void go_cb(ViSession, ViEventType, ViEvent, ViAddr);
ViHndlr get_go_cb(void) {
return (ViHndlr)go_cb;
}
ViStatus vi_printf(ViSession vi, ViString string) {
return viPrintf(vi, string);
}
ViStatus vi_sprintf(ViSession vi, ViPBuf buf, ViString string) {
return viSPrintf(vi, buf, string);
}
*/
import "C"
import (
"fmt"
"unsafe"
)
var PackageVersion string = "v0.2"
type Driver interface {
Close() Status
Read(cnt uint32) (buf []byte, retCnt uint32, status Status)
Write(buf []byte, cnt uint32) (retCnt uint32, status Status)
}
type Status int32
type Session uint32
type Object uint32
// Platform specific types, 32 or 64 bit, as determined at compile time.
type BusAddress C.ViBusAddress
type PBusAddress C.ViPBusAddress
type BusSize C.ViBusSize
type AttrState C.ViAttrState
type Bool C.ViBoolean
//
type UserCallback func(instr Object, etype, eventContext uint32)
type PUserCallback *UserCallback
// ----------------------------------------------------------------------------
// Resource Manager Functions and Operations
//
// OpenDefaultRM returns a session to the Default Resource Manager resource.
func OpenDefaultRM() (rm Session, status Status) {
status = Status(C.viOpenDefaultRM((*C.ViSession)(unsafe.Pointer(&rm))))
return rm, status
}
// legacy
var GetDefaultRM = OpenDefaultRM
// FindRsrc queries a VISA system to locate the resources
// associated with a specified interface.
func (rm Session) FindRsrc(expr string) (findList, retCnt uint32, desc string,
status Status) {
cexpr := (*C.ViChar)(C.CString(expr))
defer C.free(unsafe.Pointer(cexpr))
d := make([]byte, 257)
status = Status(C.viFindRsrc(C.ViSession(rm),
cexpr,
(*C.ViFindList)(unsafe.Pointer(&findList)),
(*C.ViUInt32)(unsafe.Pointer(&retCnt)),
(*C.ViChar)(unsafe.Pointer(&d[0]))))
return findList, retCnt, string(d), status
}
// FindNext gets the next resource from the list of resources found during a
// previous call to FindRsrc.
func FindNext(findList uint32) (string, Status) {
d := make([]byte, 257)
status := Status(C.viFindNext((C.ViFindList)(findList),
(*C.ViChar)(unsafe.Pointer(&d[0]))))
return string(d), status
}
// ParseRsrc parses a resource string to get the interface information.
func (rm Session) ParseRsrc(rsrcName string) (intfType, intfNum uint16, status Status) {
crsrcName := (*C.ViChar)(C.CString(rsrcName))
defer C.free(unsafe.Pointer(crsrcName))
status = Status(C.viParseRsrc(C.ViSession(rm),
crsrcName,
(*C.ViUInt16)(unsafe.Pointer(&intfType)),
(*C.ViUInt16)(unsafe.Pointer(&intfNum))))
return intfType, intfNum, status
}
// ParseRsrcEx parses a resource string to get extended interface information.
func (rm Session) ParseRsrcEx(rsrcName string) (intfType, intfNum uint16, rsrcClass,
expandedUnaliasedName, aliasIfExists string, status Status) {
crsrcName := (*C.ViChar)(C.CString(rsrcName))
defer C.free(unsafe.Pointer(crsrcName))
r := make([]byte, 257)
e := make([]byte, 257)
a := make([]byte, 257)
status = Status(C.viParseRsrcEx(C.ViSession(rm),
crsrcName,
(*C.ViUInt16)(unsafe.Pointer(&intfType)),
(*C.ViUInt16)(unsafe.Pointer(&intfNum)),
(*C.ViChar)(unsafe.Pointer(&r[0])),
(*C.ViChar)(unsafe.Pointer(&e[0])),
(*C.ViChar)(unsafe.Pointer(&a[0]))))
return intfType, intfNum, string(r), string(e), string(a), status
}
// Open opens a session to the specified resource.
func (rm Session) Open(name string, mode, timeout uint32) (instr Object,
status Status) {
cname := (*C.ViChar)(C.CString(name))
defer C.free(unsafe.Pointer(cname))
status = Status(C.viOpen(C.ViSession(rm),
cname,
(C.ViAccessMode)(mode),
(C.ViUInt32)(timeout),
(*C.ViSession)(unsafe.Pointer(&instr))))
return instr, status
}
// ----------------------------------------------------------------------------
// Resource Template Operations
//
// Close closes the specified session.
func (rm Session) Close() Status {
return Status(C.viClose((C.ViObject)(rm)))
}
// Close closes the specified instrument, or find list.
func (instr Object) Close() Status {
return Status(C.viClose((C.ViObject)(instr)))
}
// Close closes the specified find list.
func Close(list uint32) Status {
return Status(C.viClose((C.ViObject)(list)))
}
// SetAttribute sets the state of an attribute.
func (instr Object) SetAttribute(attribute, attrState uint32) Status {
return Status(C.viSetAttribute((C.ViObject)(instr),
(C.ViAttr)(attribute),
(C.ViAttrState)(attrState)))
}
// GetAttribute retrieves the state of an attribute.
func (instr Object) GetAttribute(attrName uint32, addr unsafe.Pointer) Status {
return Status(C.viGetAttribute((C.ViObject)(instr), (C.ViAttr)(attrName), addr))
}
// StatusDesc returns a user-readable description of the
// status code passed to the operation.
func (instr Object) StatusDesc(status_in Status) (string, Status) {
d := make([]byte, 257)
status := Status(C.viStatusDesc((C.ViObject)(instr),
(C.ViStatus)(status_in),
(*C.ViChar)(unsafe.Pointer(&d[0]))))
return string(d), status
}
// Terminate requests a VISA session to terminate normal
// execution of an operation.
func (instr Object) Terminate(degree, jobId uint16) Status {
return Status(C.viTerminate((C.ViObject)(instr),
(C.ViUInt16)(degree),
(C.ViJobId)(jobId)))
}
// Lock establishes an access mode to the specified resource.
func (instr Object) LockExclusive(lockType, timeout uint32) Status {
return Status(C.viLock((C.ViSession)(instr),
(C.ViAccessMode)(lockType),
(C.ViUInt32)(timeout),
(*C.ViChar)(nil),
(*C.ViChar)(nil)))
}
// Lock establishes an access mode to the specified resource.
func (instr Object) Lock(lockType, timeout uint32, requestedKey string) (string, Status) {
rk := (*C.ViChar)(C.CString(requestedKey))
defer C.free(unsafe.Pointer(rk))
a := make([]byte, 257)
status := Status(C.viLock((C.ViSession)(instr),
(C.ViAccessMode)(lockType),
(C.ViUInt32)(timeout),
rk,
(*C.ViChar)(unsafe.Pointer(&a[0]))))
return string(a), status
}
// Unlock relinquishes a lock for the specified resource.
func (instr Object) Unlock() Status {
return Status(C.viUnlock((C.ViSession)(instr)))
}
// EnableEvent enables notification of a specified event.
func (instr Object) EnableEvent(eventType uint32, mechanism uint16,
context uint32) Status {
return Status(C.viEnableEvent((C.ViSession)(instr),
(C.ViEventType)(eventType),
(C.ViUInt16)(mechanism),
(C.ViEventFilter)(context)))
}
// DisableEvent disables notification of the specified event type(s)
// via the specified mechanism(s).
func (instr Object) DisableEvent(eventType uint32, mechanism uint16) Status {
return Status(C.viDisableEvent((C.ViSession)(instr),
(C.ViEventType)(eventType),
(C.ViUInt16)(mechanism)))
}
// DiscardEvents discards event occurrences for specified event types
// and mechanisms in a session.
func (instr Object) DiscardEvents(eventType uint32, mechanism uint16) Status {
return Status(C.viDiscardEvents((C.ViSession)(instr),
(C.ViEventType)(eventType),
(C.ViUInt16)(mechanism)))
}
// WaitOnEvent waits for an occurrence of the specified
// event for a given session.
func (instr Object) WaitOnEvent(inEventType, timeout uint32) (outEventType,
outContext uint32, status Status) {
status = Status(C.viWaitOnEvent((C.ViSession)(instr),
(C.ViEventType)(inEventType),
(C.ViUInt32)(timeout),
(*C.ViEventType)(unsafe.Pointer(&outEventType)),
(*C.ViEvent)(unsafe.Pointer(&outContext))))
return outEventType, outContext, status
}
// InstallHandler installs handlers for event callbacks.
func (instr Object) InstallHandler(eventType uint32, userHandle UserCallback) Status {
return Status(C.viInstallHandler((C.ViSession)(instr),
(C.ViEventType)(eventType),
(C.ViHndlr)(C.get_go_cb()),
(C.ViAddr)(unsafe.Pointer(&userHandle))))
}
// UninstallHandler uninstalls handlers for events.
// Note that VISA identifies handlers uniquely using the userHandle reference.
func (instr Object) UninstallHandler(eventType uint32, userHandle UserCallback) Status {
return Status(C.viUninstallHandler((C.ViSession)(instr),
(C.ViEventType)(eventType),
(C.ViHndlr)(C.get_go_cb()),
(C.ViAddr)(unsafe.Pointer(&userHandle))))
}
// ----------------------------------------------------------------------------
// Basic I/O Operations
//
// Read reads data from device or interface synchronously.
func (instr Object) Read(cnt uint32) (buf []byte, retCnt uint32, status Status) {
buf = make([]byte, cnt)
status = Status(C.viRead((C.ViSession)(instr),
(*C.ViByte)(unsafe.Pointer(&buf[0])),
(C.ViUInt32)(cnt),
(*C.ViUInt32)(unsafe.Pointer(&retCnt))))
return buf, retCnt, status
}
// ReadAsync reads data from device or interface asynchronously.
func (instr Object) ReadAsync(cnt uint32) (buf []byte, jobId uint32, status Status) {
buf = make([]byte, cnt)
status = Status(C.viReadAsync((C.ViSession)(instr),
(*C.ViByte)(unsafe.Pointer(&buf[0])),
(C.ViUInt32)(cnt),
(*C.ViJobId)(unsafe.Pointer(&jobId))))
return buf, jobId, status
}
// ReadToFile reads data synchronously and stores the transferred data in a file.
func (instr Object) ReadToFile(filename string, cnt uint32) (retCnt uint32,
status Status) {
cfilename := (*C.ViChar)(C.CString(filename))
defer C.free(unsafe.Pointer(cfilename))
status = Status(C.viReadToFile((C.ViSession)(instr),
cfilename,
(C.ViUInt32)(cnt),
(*C.ViUInt32)(unsafe.Pointer(&retCnt))))
return retCnt, status
}
// Write writes data to a device or interface synchronously.
func (instr Object) Write(buf []byte, cnt uint32) (retCnt uint32, status Status) {
status = Status(C.viWrite((C.ViSession)(instr),
(C.ViBuf)(unsafe.Pointer(&buf[0])),
(C.ViUInt32)(cnt),
(*C.ViUInt32)(unsafe.Pointer(&retCnt))))
return retCnt, status
}
// WriteAsync writes data to a device or interface asynchronously.
func (instr Object) WriteAsync(buf []byte, cnt uint32) (jobId uint32, status Status) {
status = Status(C.viWriteAsync((C.ViSession)(instr),
(C.ViBuf)(unsafe.Pointer(&buf[0])),
(C.ViUInt32)(cnt),
(*C.ViJobId)(unsafe.Pointer(&jobId))))
return jobId, status
}
// WriteFromFile take data from a file and write it out synchronously.
func (instr Object) WriteFromFile(filename string, cnt uint32) (retCnt uint32,
status Status) {
cfilename := (*C.ViChar)(C.CString(filename))
defer C.free(unsafe.Pointer(cfilename))
status = Status(C.viWriteFromFile((C.ViSession)(instr),
cfilename,
(C.ViUInt32)(cnt),
(*C.ViUInt32)(unsafe.Pointer(&retCnt))))
return retCnt, status
}
// AssertTrigger asserts software or hardware trigger.
func (instr Object) AssertTrigger(protocol uint16) Status {
return Status(C.viAssertTrigger((C.ViSession)(instr),
(C.ViUInt16)(protocol)))
}
// ReadSTB reads a status byte of the service request.
func (instr Object) ReadSTB() (stb_stat uint16, status Status) {
status = Status(C.viReadSTB((C.ViSession)(instr),
(*C.ViUInt16)(unsafe.Pointer(&stb_stat))))
return stb_stat, status
}
// Clear clears a device.
func (instr Object) Clear() Status {
return Status(C.viClear((C.ViSession)(instr)))
}
// ----------------------------------------------------------------------------
// Formatted and Buffered I/O Operations
//
// ViSetBuf sets the size for the formatted I/O and/or low-level
// I/O communication buffer(s).
func (instr Object) SetBuf(mask uint16, size uint32) Status {
return Status(C.viSetBuf((C.ViSession)(instr),
(C.ViUInt16)(mask),
(C.ViUInt32)(size)))
}
// Flush manually flushes the specified buffers associated with
// formatted I/O operations and/or serial communication.
func (instr Object) Flush(mask uint16) Status {
return Status(C.viFlush((C.ViSession)(instr),
(C.ViUInt16)(mask)))
}
// BufWrite writes data to a formatted I/O write buffer synchronously.
func (instr Object) BufWrite(buf []byte, cnt uint32) (retCnt uint32, status Status) {
status = Status(C.viBufWrite((C.ViSession)(instr),
(C.ViBuf)(unsafe.Pointer(&buf[0])),
(C.ViUInt32)(cnt),
(*C.ViUInt32)(unsafe.Pointer(&retCnt))))
return retCnt, status
}
// BufRead reads data from a device or interface through the
// use of a formatted I/O read buffer.
func (instr Object) BufRead(cnt uint32) (buf []byte, retCnt uint32, status Status) {
buf = make([]byte, cnt)
status = Status(C.viBufRead((C.ViSession)(instr),
(C.ViBuf)(unsafe.Pointer(&buf[0])),
(C.ViUInt32)(cnt),
(*C.ViUInt32)(unsafe.Pointer(&retCnt))))
return buf, retCnt, status
}
// TODO: not all of these are feasible and/or worth the effort, but try
// to implement the basics of each operation
// Printf converts, formats, and sends the parameters (designated by args)
// to the device as specified by the format string.
func (instr Object) Printf(writeFmt string, args ...interface{}) Status {
cstr := (*C.ViChar)(C.CString(fmt.Sprintf(writeFmt, args...)))
defer C.free(unsafe.Pointer(cstr))
return Status(C.vi_printf((C.ViSession)(instr), cstr))
}
// SPrintf converts, formats, and sends the parameters (designated by args)
// to a user-specified buffer as specified by the format string.
func (instr Object) SPrintf(buf *uint8, writeFmt string, args ...interface{}) Status {
cstr := (*C.ViChar)(C.CString(fmt.Sprintf(writeFmt, args)))
defer C.free(unsafe.Pointer(cstr))
return Status(C.vi_sprintf((C.ViSession)(instr),
(*C.ViByte)(unsafe.Pointer(buf)), cstr))
}
// Scanf reads, converts, and formats data using the format specifier.
// Stores the formatted data in the parameters (designated by ...).
// ViStatus _VI_FUNCC viScanf(ViSession vi, ViString readFmt, ...);
// VScanf reads, converts, and formats data using the format specifier.
// Stores the formatted data in the parameters designated by params.
// ViStatus _VI_FUNC viVScanf(ViSession vi, ViString readFmt, ViVAList params);
// SScanf reads, converts, and formats data from a user-specified buffer
// using the format specifier. Stores the formatted data in the parameters
// (designated by ...).
// ViStatus _VI_FUNCC viSScanf(ViSession vi, ViBuf buf, ViString readFmt, ...);
// VSScanf reads, converts, and formats data from a user-specified buffer
// using the format specifier. Stores the formatted data in the parameters
// designated by params.
// ViStatus _VI_FUNC viVSScanf(ViSession vi, ViBuf buf, ViString readFmt,
// ViVAList parms);
// Queryf performs a formatted write and read through a single call
// to an operation.
// ViStatus _VI_FUNCC viQueryf(ViSession vi, ViString writeFmt, ViString readFmt, ...);
// VQueryf performs a formatted write and read through a single call
// to an operation.
// ViStatus _VI_FUNC viVQueryf(ViSession vi, ViString writeFmt, ViString readFmt,
// ViVAList params);
// ----------------------------------------------------------------------------
// Memory I/O Operations
//
// In8 reads in an 8-bit value from the specified memory space and offset.
func (instr Object) In8(space uint16, offset BusAddress) (val uint8, status Status) {
status = Status(C.viIn8((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(*C.ViUInt8)(&val)))
return val, status
}
// Out8 writes an 8-bit value to the specified memory space and offset.
func (instr Object) Out8(space uint16, offset BusAddress, val uint8) Status {
return Status(C.viOut8((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(C.ViUInt8)(val)))
}
// In16 reads in an 16-bit value from the specified memory space and offset.
func (instr Object) In16(space uint16, offset BusAddress) (val uint16, status Status) {
status = Status(C.viIn16((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(*C.ViUInt16)(&val)))
return val, status
}
// Out16 writes an 16-bit value to the specified memory space and offset.
func (instr Object) Out16(space uint16, offset BusAddress, val uint16) Status {
return Status(C.viOut16((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(C.ViUInt16)(val)))
}
// In32 reads in an 32-bit value from the specified memory space and offset.
func (instr Object) In32(space uint16, offset BusAddress) (val uint32, status Status) {
status = Status(C.viIn32((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(*C.ViUInt32)(&val)))
return val, status
}
// Out32 writes an 32-bit value to the specified memory space and offset.
func (instr Object) Out32(space uint16, offset BusAddress, val uint32) Status {
return Status(C.viOut32((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(C.ViUInt32)(val)))
}
// MoveIn8 moves a block of data from the specified address
// space and offset to local memory.
func (instr Object) MoveIn8(space uint16, offset BusAddress,
length BusSize) ([]uint8, Status) {
buf := make([]uint8, length)
status := Status(C.viMoveIn8((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(C.ViBusSize)(length),
(C.ViAUInt8)(unsafe.Pointer(&buf[0]))))
return buf, status
}
// MoveOut8 moves a block of data from local memory to the specified
func (instr Object) MoveOut8(space uint16, offset BusAddress, length BusSize,
buf []uint8) Status {
return Status(C.viMoveOut8((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(C.ViBusSize)(length),
(C.ViAUInt8)(unsafe.Pointer(&buf[0]))))
}
// MoveIn16 moves a block of data from the specified
// address space and offset to local memory.
func (instr Object) MoveIn16(space uint16, offset BusAddress,
length BusSize) ([]uint16, Status) {
buf := make([]uint16, length)
status := Status(C.viMoveIn16((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(C.ViBusSize)(length),
(C.ViAUInt16)(unsafe.Pointer(&buf[0]))))
return buf, status
}
// MoveOut16 moves a block of data from local memory to
// the specified address space and offset.
func (instr Object) MoveOut16(space uint16, offset BusAddress, length BusSize,
buf []uint16) Status {
return Status(C.viMoveOut16((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(C.ViBusSize)(length),
(C.ViAUInt16)(unsafe.Pointer(&buf[0]))))
}
// MoveIn32 moves a block of data from the specified address
// space and offset to local memory.
func (instr Object) MoveIn32(space uint16, offset BusAddress,
length BusSize) ([]uint32, Status) {
buf := make([]uint32, length)
status := Status(C.viMoveIn32((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(C.ViBusSize)(length),
(C.ViAUInt32)(unsafe.Pointer(&buf[0]))))
return buf, status
}
// MoveOut32 moves a block of data from local memory to
// the specified address space and offset.
func (instr Object) MoveOut32(space uint16, offset BusAddress, length BusSize,
buf []uint32) Status {
return Status(C.viMoveOut32((C.ViSession)(instr),
(C.ViUInt16)(space),
(C.ViBusAddress)(offset),
(C.ViBusSize)(length),
(C.ViAUInt32)(unsafe.Pointer(&buf[0]))))
}
// Move moves a block of data.
func (instr Object) Move(srcSpace uint16, srcOffset BusAddress, srcWidth uint16,
destSpace uint16, destOffset BusAddress, destWidth uint16,
srcLength BusSize) Status {
return Status(C.viMove((C.ViSession)(instr),
(C.ViUInt16)(srcSpace),
(C.ViBusAddress)(srcOffset),
(C.ViUInt16)(srcWidth),
(C.ViUInt16)(destSpace),
(C.ViBusAddress)(destOffset),
(C.ViUInt16)(destWidth),
(C.ViBusSize)(srcLength)))
}
// MoveAsync moves a block of data asynchronously.
func (instr Object) MoveAsync(srcSpace uint16, srcOffset BusAddress, srcWidth,
destSpace uint16, destOffset BusAddress, destWidth uint16,
srcLength BusSize) (jobId uint32, status Status) {
status = Status(C.viMoveAsync((C.ViSession)(instr),
(C.ViUInt16)(srcSpace),
(C.ViBusAddress)(srcOffset),
(C.ViUInt16)(srcWidth),
(C.ViUInt16)(destSpace),
(C.ViBusAddress)(destOffset),
(C.ViUInt16)(destWidth),
(C.ViBusSize)(srcLength),
(*C.ViJobId)(unsafe.Pointer(&jobId))))
return jobId, status
}
// MapAddress maps the specified memory space into the process’s address space.
func (instr Object) MapAddress(mapSpace uint16, mapOffset BusAddress, mapSize BusSize,
access uint16, suggested *byte) (address *byte, status Status) {
status = Status(C.viMapAddress((C.ViSession)(instr),
(C.ViUInt16)(mapSpace),
(C.ViBusAddress)(mapOffset),
(C.ViBusSize)(mapSize),
(C.ViBoolean)(access),
(C.ViAddr)(unsafe.Pointer(suggested)),
(*C.ViAddr)(unsafe.Pointer(&address))))
return address, status
}
// UnmapAddress unmaps memory space previously mapped by ViMapAddress.
func (instr Object) UnmapAddress() Status {
return Status(C.viUnmapAddress((C.ViSession)(instr)))
}
// Peek8 reads an 8-bit value from the specified address.
func (instr Object) Peek8(address unsafe.Pointer) (val uint8) {
C.viPeek8((C.ViSession)(instr), (C.ViAddr)(address), (*C.ViUInt8)(&val))
return val
}
// Poke8 writes an 8-bit value to the specified address.
func (instr Object) Poke8(address unsafe.Pointer, val uint8) {
C.viPoke8((C.ViSession)(instr), (C.ViAddr)(address), (C.ViUInt8)(val))
}
// Peek16 reads an 16-bit value from the specified address.
func (instr Object) Peek16(address unsafe.Pointer) (val uint16) {
C.viPeek16((C.ViSession)(instr), (C.ViAddr)(address), (*C.ViUInt16)(&val))
return val
}
// Poke16 writes an 16-bit value to the specified address.
func (instr Object) Poke16(address unsafe.Pointer, val uint16) {
C.viPoke16((C.ViSession)(instr), (C.ViAddr)(address), (C.ViUInt16)(val))
}
// Peek32 reads an 32-bit value from the specified address.
func (instr Object) Peek32(address unsafe.Pointer) (val uint32) {
C.viPeek32((C.ViSession)(instr), (C.ViAddr)(address), (*C.ViUInt32)(&val))
return val
}
// Poke32 writes an 32-bit value to the specified address.
func (instr Object) Poke32(address unsafe.Pointer, val uint32) {
C.viPoke32((C.ViSession)(instr), (C.ViAddr)(address), (C.ViUInt32)(val))
}
// ----------------------------------------------------------------------------
// Shared Memory Operations
//
// MemAlloc allocates memory from a device’s memory region.
func (instr Object) MemAlloc(size BusSize) (offset BusAddress, status Status) {
status = Status(C.viMemAlloc((C.ViSession)(instr),
(C.ViBusSize)(size),
(*C.ViBusAddress)(&offset)))
return offset, status
}
// MemFree frees memory previously allocated using the viMemAlloc() operation.
func (instr Object) MemFree(offset BusAddress) Status {
return Status(C.viMemFree((C.ViSession)(instr), (C.ViBusAddress)(offset)))
}
// ----------------------------------------------------------------------------
// Interface Specific Operations
//
// GpibControlREN controls the state of the GPIB Remote Enable (REN)
// interface line, and optionally the remote/local state of the device.
func (instr Object) GpibControlREN(mode uint16) Status {
return Status(C.viGpibControlREN((C.ViSession)(instr),
(C.ViUInt16)(mode)))
}
// GpibControlATN specifies the state of the ATN line and the local
// active controller state.
func (instr Object) GpibControlATN(mode uint16) Status {
return Status(C.viGpibControlATN((C.ViSession)(instr),
(C.ViUInt16)(mode)))
}
// GpibSendIFC pulses the interface clear line (IFC) for at least 100 microseconds.
func (instr Object) GpibSendIFC() Status {
return Status(C.viGpibSendIFC((C.ViSession)(instr)))
}
// GpibCommand writes GPIB command bytes on the bus.
// ViStatus _VI_FUNC viGpibCommand (ViSession vi, ViBuf cmd, ViUInt32 cnt, ViPUInt32 retCnt);
func (instr Object) GpibCommand(cmd []byte, cnt uint32) (retCnt uint32, status Status) {
status = Status(C.viGpibCommand((C.ViSession)(instr),
(C.ViBuf)(unsafe.Pointer(&cmd[0])),
(C.ViUInt32)(cnt),
(*C.ViUInt32)(&retCnt)))
return retCnt, status
}
// GpibPassControl tells the GPIB device at the specified address to
// become controller in charge (CIC).
func (instr Object) GpibPassControl(primAddr, secAddr uint16) Status {
return Status(C.viGpibPassControl((C.ViSession)(instr),
(C.ViUInt16)(primAddr),
(C.ViUInt16)(secAddr)))
}
// VxiCommandQuery sends the device a miscellaneous command or query and/or
// retrieves the response to a previous query.
func (instr Object) VxiCommandQuery(mode uint16, cmd uint32) (response uint32, status Status) {
status = Status(C.viVxiCommandQuery((C.ViSession)(instr),
(C.ViUInt16)(mode),
(C.ViUInt32)(cmd),
(*C.ViUInt32)(&response)))
return response, status
}
// AssertUtilSignal asserts or deasserts the specified utility bus signal.
func (instr Object) AssertUtilSignal(line uint16) Status {
return Status(C.viAssertUtilSignal((C.ViSession)(instr),
(C.ViUInt16)(line)))
}
// AssertIntrSignal asserts the specified interrupt or signal.
func (instr Object) AssertIntrSignal(mode int16, statusID uint16) Status {
return Status(C.viAssertIntrSignal((C.ViSession)(instr),
(C.ViInt16)(mode),
(C.ViUInt32)(statusID)))
}
// MapTrigger maps the specified trigger source line to the specified
// destination line.
func (instr Object) MapTrigger(trigSrc, trigDest int16, mode uint16) Status {
return Status(C.viMapTrigger((C.ViSession)(instr),
(C.ViInt16)(trigSrc),
(C.ViInt16)(trigDest),
(C.ViUInt16)(mode)))
}
// UnmapTrigger undoes a previous map from the specified trigger source
// line to the specified destination line.
func (instr Object) UnmapTrigger(trigSrc, trigDest int16) Status {
return Status(C.viUnmapTrigger((C.ViSession)(instr),
(C.ViInt16)(trigSrc),
(C.ViInt16)(trigDest)))
}
// UsbControlOut performs a USB control pipe transfer to the device.
func (instr Object) UsbControlOut(bmRequestType, bRequest int16, wValue, wIndex,
wLength uint16, buf []byte) Status {
return Status(C.viUsbControlOut((C.ViSession)(instr),
(C.ViInt16)(bmRequestType),
(C.ViInt16)(bRequest),
(C.ViUInt16)(wValue),
(C.ViUInt16)(wIndex),
(C.ViUInt16)(wLength),
(*C.ViByte)(unsafe.Pointer(&buf[0]))))
}
// UsbControlIn performs a USB control pipe transfer from the device.
func (instr Object) UsbControlIn(bmRequestType, bRequest int16, wValue, wIndex,
wLength uint16) (buf []byte, retCnt uint16, status Status) {
buf = make([]byte, wLength)
status = Status(C.viUsbControlIn((C.ViSession)(instr),
(C.ViInt16)(bmRequestType),
(C.ViInt16)(bRequest),
(C.ViUInt16)(wValue),
(C.ViUInt16)(wIndex),
(C.ViUInt16)(wLength),
(*C.ViByte)(unsafe.Pointer(&buf[0])),
(*C.ViUInt16)(&retCnt)))
return buf, retCnt, status
}
// Version returns the unformatted resource version number.
func Version() uint32 {
return uint32(C.VI_SPEC_VERSION)
}
// VersMajor returns the major resource version number.
func VersMajor() uint32 {
return uint32((Version() & 0xFFF00000) >> 20)
}
// VersMinor returns the minor resource version number.
func VersMinor() uint32 {
return uint32((Version() & 0x000FFF00) >> 8)
}
// VersSubMinor returns the sub-minor resource version number.
func VersSubMinor() uint32 {
return uint32((Version() & 0x000000FF))
}
// PxiReserveTriggers reserves multiple trigger lines that the caller can then map and/or assert.
func (instr Object) PxiReserveTriggers(cnt int16, trigBuses, trigLines *int16) (failureIndex int16, status Status) {
status = Status(C.viPxiReserveTriggers((C.ViSession)(instr),
(C.ViInt16)(cnt),
(*C.ViInt16)(trigBuses),
(*C.ViInt16)(trigLines),
(*C.ViInt16)(&failureIndex)))
return failureIndex, status
}
// VxiServantResponse ?
//func (instr Object) VxiServantResponse(mode int16, resp uint32) Status {
// return Status(C.viVxiServantResponse((C.ViSession)(instr),
// (C.ViInt16)(mode),
// (C.ViUInt32)(resp)))
//}