293
Chapter 8 Application Programs
Visual BASIC Example Program
4
8
Visual BASIC Example Program
This example program is written in Visual BASIC 6.0 and has been
tested on a PC running WIN95/NT. The example uses the SCPI com-
mands. As the example is currently written, the program requirements
are:
•
GPIB interface selected and set to the address of 09 from the front-
panel;
•
Any one of the relay modules installed in Slot 1 of the mainframe;
•
A GPIB interface card installed in your PC with the VISA library.
To program a 3499A/B/C using the RS-232 interface, you will need to
modify the code at the top of the program. Change the line
Const USING_RS232 =0 to Const USING_RS232 =1.
On the 3499A/B/C, select the RS-232 interface and set its parameters to:
BAUD RATE (9600), PARITY (NONE, 8 BITS), and FLOW (FLOW
NONE). A GPIB card in your PC is not necessary if you are using
RS-232.
Const USING_RS232 =0' Change 0 to 1 if RS-232 interface is to be used.
' Sleep( ) function declaration.
Declare Sub Sleep Lib "Kernel32" (ByVal s As Long)
Sub main()
Dim drm As Long ' Session to default resource manager.
Dim vi As Long ' Session to instrument.
Dim status As Long ' VISA function status return code
Dim retStr As String * 128' String returned from the instrument.
Dim str As String ' String for individual channel number.
On Error GoTo ErrorHandler
' Open default resource manager.
drm = -1
status = viOpenDefaultRM(drm)
If (status < VI_SUCCESS) Then GoTo VisaErrorHandler
' Select an interface for 3499A/B/C.
' GPIB interface is used when USING_RS232 = 0,
' or RS-232 interface is used when USING_RS232 = 1.
If USING_RS232 Then
INST_ADDR = "ASRL1::INSTR"
Else
INST_ADDR = "GPIB0::9::INSTR"
Endif
' Open a session to 3499A/B/C.
status = viOpen(drm, INST_ADDR, 0, 0, vi)
If (status < VI_SUCCESS) Then GoTo VisaErrorHandler