6241A/6242 DC Voltage Current Source/Monitor Operation Manual
6.8.2 Programming Examples with USB
6-48
6.8.2 Programming Examples with USB
A basic program example to operate the 6241A/6242 from a computer via USB connection is introduced
below.
Operating Environment
Computer: DELL OPTIPLEX 170L (Pentium 4 CPU 2.80GHz)
Module : asub.bas (Software supplied with USB driver for ADC measuring instruments.)
Language: Microsoft Excel Visual Basic for Application
Conducts the same operations as the GPIB sample program in “6.8.1.1 Programming Example 1: DC
Measurement” using the USB interface.
NOTE: The USB.Id is set to 1 for the 6241A/6242.
6.8.2.1 Programming Example: DC Measurement
Option Explicit ’ Explicit declaration for all variables
Private Const OK As Integer = 0 ’ Definition of OK
Private Sub Sampl1_USB_Click() ’ Event procedure for the command button
Dim vig As Long ’ USB handle
Dim myID As Long ’ Declares the 6241A/6242 USB.Id variable.
Dim ret As Long ’ Declares the driver return value variable.
Dim dt As String ’ Declares the USB data reception buffer variable.
myID = 1 ’ USB.Id No. "1"
ret = ausb_start(10) ’ Initialize USB, Timeout:10 s
If ret <> OK Then ’ If USB initialization is NG
MsgBox "USB Initialization Error", vbExclamation
GoTo err_exit
End If
Call mSecSleep(100) ’ USB initialization wait time (100 ms)
ret = ausb_open(vig, myID) ’ Open VIG for MyID: No.1, acquire USB handle
If ret <> OK Then ’ If opening device is NG
MsgBox "Device Open Error", vbExclamation
GoTo err_exit
End If
Call ausbwrt(vig, "*RST") ’ Initialize parameter
Call ausbwrt(vig, "OH1") ’ Header ON
Call ausbwrt(vig, "M1") ’ Trigger mode hold
Call ausbwrt(vig, "VF") ’ Voltage source function
Call ausbwrt(vig, "F2") ’ Current measurement function
Call ausbwrt(vig, "SOV1,LMI0.003") ’ DC source value 1 V, limiter value 3 mA
Call ausbwrt(vig, "OPR") ’ Output ON
Call SUBmeas(vig, dt) ’ Measurement trigger & Measurement data recall
R