http://www.ivifoundation.org/Default.aspx
Programming with VISA-COM[url=]Other topics about Controlling Peripherals[/url] OverviewKeysight 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. 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
STEP 1. Starting VISA-COMThe VISA system startup session is processed from Line 20 to 80 in the sample program [url=]ctrl_ext_vc.vba[/url]. 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. SyntaxDim param1 As VisaComLib.ResourceManager Dim param2 As VisaComLib.FormattedIO488
Set param1 = New VisaComLib.ResourceManager Set param2 = New VisaComLib.FormattedIO488 Parameters | | | startup information - variable declaration and - acquiring memory area | | |
| | | connection information - variable declaration and - acquiring memory area | | |
STEP 2. ConnectionThe 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 [url=]WaitingForTrigger_OPC.vba[/url]). SyntaxSet param2.IO = param1.Open (param3) Parameters
| | | Address information of the specified instrument (input) | | Either character string or numeric type | | "GPIB0::[url=]gpib address[/url]::INSTR" "USB0::manufacturer ID::model code::serial number::0::INSTR"
(ex. "USB0::2391::2312::MY12345678::0::INSTR") "TCPIP0::IP address::inst0::INSTR" |
STEP 3. CommunicationThe 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).
Syntaxparam2.WriteString Parameters
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. Syntaxparam3 = param2.ReadString param3 = param2.ReadNumber Parameters
| | | | | Either character string or numeric type |
STEP 4. DisconnectionThe 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. Syntaxparam2.IO.Close Parameter
Sample Program to Read Out the Product Information of Peripheral (Instrument)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 commands 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.
Lines 20 to 80Initializes and starts up the VISA system and outputs the startup information to the param2 (Equip) variable. Lines 100Declare variable that will be used throughout the program. Lines 120 to 130Establishes 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. Lines 150Queries the product information of the external instrument connected via USB/GPIB interface cable using VISA-COM. Lines 160 to 190Retrieves the product information through VISA-COM and outputs it into the param3 (Prod) variable. Displays the read-out result in the message box. Line 210During this process, if an error occurs, the program goes to the error handling routine (Lines 260 to 340). Line 230Breaks the communication and terminates the VISA-COM system. Lines 260 to 340If 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
|