5-34
Remote Operation
Example Programs
Example 1, Acquire Trace
Description
This program demonstrates how to use Visual Basic to take a measurement
and download a trace in ASCII format. The program also demonstrates how to
change several settings such as center wavelength, span, and input receiver
channel. It should be noted that the settings are not sent to the instrument
until the Acquire Trace button is pressed.
Program
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const OPC_TMO = 180
Private Const LZ_TMO = 360
Private Sub cmdAcquireTrace_Click
()
Dim TimeStart As Double
’-- VISA session variables
Dim DefRM As Long
’VISA session
Dim DevSessionNum As Long
’VISA session to device
Dim ReadBuffer As String * 65500
’Buffer to read back data
Dim STB As Integer
’Status byte
Dim Status As Long: Status = 0
Dim ErrMsg As String: ErrMsg = ""
On Error GoTo ErrorHandler
MousePointer = vbHourglass
’-- Create a VISA session
Status = viOpenDefaultRM(DefRM)
If Status <> 0 Then GoTo ErrorHandler
’-- Open a session to the WDCA
Status = viOpen(DefRM, "GPIB" & txtGPIB_IN.Text & "::" & txtGPIB_PA.Text, 0, 0, DevSessionNum)
If Status <> 0 Then GoTo ErrorHandler
’-- Clear the instrument
Status = viClear(DevSessionNum)
If Status <> 0 Then GoTo ErrorHandler
’-- Set write buffer to flush on access
Status = viSetAttribute(DevSessionNum, VI_ATTR_WR_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS)
If Status <> 0 Then GoTo ErrorHandler
’-- Set read buffer to flush on access
Status = viSetAttribute(DevSessionNum, VI_ATTR_RD_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS)
If Status <> 0 Then GoTo ErrorHandler
’-- Clear status registers
Status = viVPrintf(DevSessionNum, "*CLS" & Chr$(10), 0)
If Status <> 0 Then GoTo ErrorHandler
Artisan Technology Group - Quality Instrumentation ... Guaranteed | (888) 88-SOURCE | www.artisantg.com