Programming with VISA

Other topics about Controlling Peripherals

Overview

The following figure shows the flow of controlling the instrument with VISA. When developing a VISA program in the Visual Basic language, a special programing notice (in the readme text file listed below) must be reviewed.

For details on the use of the VISA library and the programing notice for using the VISA library with the E5061B macro (E5061B VBA), refer to the following files contained in I/O library CD-ROM.

Preparation

Importing Definition Files

To use the VISA library in the E5061B macro (E5061B VBA), you need to import two definition files into your project with the Visual Basic editor to define the VISA functions and perform other tasks. The definition files are stored on the sample programs disk under the following filenames (for information on importing modules, refer to Saving a Module (Exporting).

Flow of instrument control with VISA

 

STEP 1. Starting VISA

The VISA system startup session is viOpenDefaultRM function in the sample program ctrl_ext.vba. VISA's viOpenDefaultRM function initializes and starts up the VISA system. The viOpenDefaultRM function must be executed before other VISA functions are called, and the parameter of this function has the startup information (Defrm in ctrl_ext.vba).

Syntax

viOpenDefaultRM(param)

Parameter

Parameter

(param)

Description

Startup information (output)

Data type

Long integer type

STEP 2. Connection

The connection session is viOpen function. VISA's viOpen function makes connection with the specified instrument. The viOpen function returns a value so that the VISA functions can apply it to the specified instrument. The parameters of this function contain the startup information (Defrm), the address information of the specified instrument ("GPIB0::17::INSTR" in ctrl_ext.vba), access mode (0 in ctrl_ext.vba), timeout (0 in ctrl_ext.vba), and connection information (Equip in ctrl_ext.vba).

Syntax

viOpen(param1, param2, param3, param4, param5)

Parameters

Parameter

(param1)

Description

Startup information (input)

Data type

Long integer type

 

Parameter

(param2)

Description

Address information of the specified instrument (input)

Data type

Character string type

Syntax

"GPIB0::gpib address::INSTR"

"USB0::manufacturer ID::model code::serial number::0::INSTR"
(ex. "USB0::2391::2312::MY12345678::0::INSTR")

"TCPIP0::IP address::inst0::INSTR"

 

Parameter

(param3)

Description

Access mode (Enter 0)

 

Parameter

(param4)

Description

Timeout (Enter 0)

 

Parameter

(param5)

Description

Connection information (output)

Data type

Long integer type

STEP 3. Communication

The communication session is viVPrintf function. VISA's viVPrintf function sends a program message (GPIB command) to the specified instrument. The parameters of this function contain the connection information (Equip), the program message (*IDN?), and the variable to be formatted (0 in ctrl_ext.vba).

Syntax

viVPrintf(param1, param2, param3)

Parameters

Parameter

(param1)

Description

Connection information (input)

Data type

Long integer type

 

Parameter

(param2)

Description

Program message (input) When sending a program message of the GPIB command, a message terminator is required at the end of the message (Chr$(10) in ctrl_ext.vba)

Data type

Character string type

 

Parameter

(param3)

Description

A variable to be formatted. If not applicable, enter 0.

Data type

Specified data type

 

 

The receiving session is viVScanf function. VISA's viVScanf function receives the result from the specified instrument and stores it in the output variable. The parameters of this function contain the connection information (Equip in ctrl_ext.vba), the format parameter for the output variable (%t in ctrl_ext.vba), and the output variable (Prod in ctrl_ext.vba).

Syntax

viVScanf(param1, param2, param3)

Parameters

Parameter

(param1)

Description

Connection information (input)

Data type

Long integer type

 

Parameter

(param2)

Description

Format parameter for the output variable

Data type

Character string type

 

Parameter

(param3)

Description

Output variable (output)

Data type

Character string type

 

STEP 4. Disconnection

The disconnection session is viClose function. VISA's viClose function disconnects communication and terminates the VISA system. The parameter of this function has startup information (Defrm in ctrl_ext.vba).

Syntax

viClose(param)

Parameter

Parameter

(param)

Description

Startup information (input)

Data type

Long integer type

 

 

 

Sample Program to Read Out the Product Information of Peripheral (Instrument)

The ctrl_ext.vba is a sample program that controls instruments connected through USB/GPIB interface cable using the E5061B as the system controller. This VBA program consists of the following modules.

Object name

Module type

Content

mdlCtrlExt

Standard module

Reads out the product information of external instrument.

Visa32

Standard module

Definition file to use VISA library (Visa32.bas)

 

 

Read out the product information (ctrl_ext.vba)

''''

' This program is sample of controlling peripherals.

''''

'

Sub Main()

    Dim status As Long

    Dim Defrm As Long

    Dim Equip As Long

    Dim Prod As String * 100

'

' Initializes and starts up the VISA system and outputs the startup information to the Defrm variable.

' During this process, if an error occurs, the program goes to the error handling routine.

'

    status = viOpenDefaultRM(Defrm)

    If (status <> VI_SUCCESS) Then GoTo VisaErrorHandler

'

' Establishes the connection to the external instrument (GPIB address: 17) connected via GPIB and

' outputs the connection information to the Equip variable. During this process, if an error occurs,

' the program goes to the error handling routine.

'

    status = viOpen(Defrm, "GPIB0::17::INSTR", 0, 0, Equip)

    If (status <> VI_SUCCESS) Then GoTo VisaErrorHandler

'

' Queries the product information of the external instrument connected via USB/GPIB interface cable

' using VISA. During this process, if an error occurs, the program goes to the error handling routine.

'

    status = viVPrintf(Equip, "*IDN?" & Chr$(10), 0)

    If (status <> VI_SUCCESS) Then GoTo VisaErrorHandler

'

' Retrieves the product information through VISA and outputs it into the Prod variable. Displays the

' read-out result in the message box. During this process, if an error occurs, the program goes to

' the error handling routine.

'

    status = viVScanf(Equip, "%t", Prod)

    If (status <> VI_SUCCESS) Then GoTo VisaErrorHandler

    MsgBox Prod

'

' Breaks the communication and terminates the VISA system.

'

    Call viClose(Defrm)

'

    GoTo Prog_end

'

' If an error occurs in a VISA function, displays the detail of the error and terminates the program.

'

VisaErrorHandler:

    Dim VisaErr As String * 200

    Call viStatusDesc(Defrm, status, VisaErr)

    MsgBox "Error : " & VisaErr, vbExclamation

    Exit Sub

'

Prog_end:

'

End Sub