Other topics about Controlling Peripherals
Keysight VISA COM is a COM (Microsoft Complonent Object Model) implementation based on the Keysight VISA architecture and conforming to IVI Foundation standards.
If you are familiar with VISA, you should not have too much trouble adjusting to communication with VISA COM. One of the primary ways to communicate with resources on INSTR sessions is to use the I488FormattedIO interface for formatted I/O. VISA COM I/O comes with a basic Formatted I/O Component that provides 488.2-style formatted I/O capabilities. The component implements the IFormattedIO488 Interface.
The following figure shows the flow of controlling the instrument with VISA-COM. When developing a VISA-COM 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-COM library and the programing notice for using the VISA-COM library with the E5072A macro (E5072A VBA), refer to the following files contained in IO library CD-ROM.
visacom.chm (on-line help for the VISA library)
Prior to executing a VISA-COM, you must ensure that you include:
VISA COM 3.0 Type Library, which corresponds to the GlobMgr.dll file
Keysight VISA COM Resource Manager
Go to Tools -> References and check the selection. Click OK.
Flow of instrument control with VISA-COM
The VISA system startup session is processed from Line 20 to 80 in the sample program ctrl_ext_vc.vba. VISA-COM's Dim param1 As VisaComLib.ResourceManager and Dim param2 As VisaComLib.FormattedIO488 function declare the variables of the resource manager and the instrument I/O. Set param1 = New VisaComLib.ResourceManager and Set param2 = New VisaComLib.FormattedIO488 function acquire the memory area of the resource manager and the instrument I/O. These functions must be executed before other VISA-COM functions are called.
Dim param1 As VisaComLib.ResourceManager
Dim param2 As VisaComLib.FormattedIO488
Set param1 = New VisaComLib.ResourceManager
Set param2 = New VisaComLib.FormattedIO488
Parameter |
param1 |
Description |
startup information - variable declaration and - acquiring memory area |
Data type |
Resource Manager |
Parameter |
param2 |
Description |
connection information - variable declaration and - acquiring memory area |
Data type |
FormattedIO488 |
The connection session is handled in Line 120. VISA-COM's param1.Open function makes connection with the specified instrument and returns a value so that the VISA-COM functions can apply it to the specified instrument. The parameters of this function are the startup information and the address information of the specified instrument ("GPIB0::17::INSTR" in WaitingForTrigger_OPC.vba).
Set param2.IO = param1.Open (param3)
Parameter |
param1 |
Description |
startup information |
Data type |
Resource Manager |
Parameter |
param2 |
Description |
connection information |
Data type |
FormattedIO488 |
Parameter |
param3 |
Description |
Address information of the specified instrument (input) |
Data type |
Either character string or numeric type |
Syntax |
"GPIB0::gpib address::INSTR" "USB0::manufacturer ID::model code::serial number::0::INSTR" "TCPIP0::IP address::inst0::INSTR" |
The communication session is conducted in Line 150 to 190. VISA's param2.WriteString function sends a program message (SCPI command) to the specified instrument. The parameters of this function are connection information (param2) and the program message (*IDN?).
To input/output SCPI commands, the param2.WriteString function, param3 = param2.ReadString function and param3 = param2.ReadNumber function are mainly used, but other VISA-COM functions are also available. For more information, refer to visa.hlp (online help for the VISA library).
param2.WriteString
Parameter |
param2 |
Description |
connection information |
Data type |
FormattedIO488 |
The receiving session is controlled in Line 160. param3 = param2.ReadString function receives the result from the specified instrument and stores it in the output variable (param3). The parameters of this function are connection information (param2). If the result is a numeric value, param3 = param2.ReadNumber instead.
param3 = param2.ReadString
param3 = param2.ReadNumber
Parameter |
param2 |
Description |
connection information |
Data type |
FormattedIO488 |
Parameter |
param3 |
Description |
Output variable (output) |
Data type |
Either character string or numeric type |
The disconnection session is handled in Line 230. VISA-COM's param2.IO.Close function disconnects communication and terminates the VISA-COM system. The parameter of this function is connection information.
param2.IO.Close
Parameter |
param2 |
Description |
connection information |
Data type |
FormattedIO488 |
The ctrl_ext_vc.vba is a sample program to control instruments connected through USB/GPIB interface cable using the E5072A as the system controller.
When you control peripherals from E5072A VBA, use the SCPI comĀmands provided for the instrument to communicate over VISA. On the other hand, when you control the E5072A itself from E5072A VBA, use the COM objects provided for the E5072A to communicate.
Initializes and starts up the VISA system and outputs the startup information to the param2 (Equip) variable.
Declare variable that will be used throughout the program.
Establishes the connection to the external instrument (GPIB address: 17) connected via GPIB and outputs the connection information to the Age507x variable. Timeout time is set to 100000.
Queries the product information of the external instrument connected via USB/GPIB interface cable using VISA-COM.
Retrieves the product information through VISA-COM and outputs it into the param3 (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 (Lines 260 to 340).
Breaks the communication and terminates the VISA-COM system.
If an error occurs in a VISA-COM function, displays the detail of the error and terminates the program.
Read out the product information (ctrl_ext_vc.vba)
10| '*** The variables of the resource manager and the instrument I/O are declared
20| Dim ioMgr As VisaComLib.ResourceManager
30| Dim Equip As VisaComLib.FormattedIO488
40|
50| Sub Main()
60| '*** The memory area of the resource manager and the instrument I/O are acquired
70| Set ioMgr = New VisaComLib.ResourceManager
80| Set Equip = New VisaComLib.FormattedIO488
90| '*** Variable declaration
100| Dim Prod As String * 100 'String to receive the result
110| '*** Open the instrument
120| Set Equip.IO = ioMgr.Open("GPIB0::17::INSTR")
130| Equip.IO.timeout = 100000 ' TimeOut time should be greater than the measurement time.
140| '*** Asks for the instrument's product information.
150| Equip.WriteString "*IDN?", True
160| '*** Reads the result.
170| Prod = Equip.ReadString
180| '*** Displays the result.
190| MsgBox Prod
200| '***Checking the error.
210| Call ErrorCheck
220| '*** Closes the resource manager session (which closes everything)
230| Equip.IO.Close
240| End Sub
250|
260| Sub ErrorCheck()
270| Dim err As String * 50, ErrNo As Variant, Response As String
280| Equip.WriteString ":SYST:ERR?" 'Reads error message
290| err = Equip.ReadString
300| ErrNo = Split(err, ",") 'Gets the error code.
310| If Val(ErrNo(0)) <> 0 Then
320| Response = MsgBox(CStr(ErrNo(1)), vbOKOnly) 'Display the message box.
330| End If
340| End Sub