The virtual instrument software architecture (VISA) is a multi-vendor standard, ensuring a high degree of interoperability among instrumentation vendors. VISA supports a wide variety of operating systems and instrument interfaces. This guide describes how to use the Keysight VISA COM I/O Library in Visual Basic. There are three basic steps to communicate with an instrument in Visual Basic:

  1. Include the appropriate VISA COM libraries.
  2. Connect to the instrument by finding the I/O address of the instrument you are using.
  3. Use the connection to the instrument to do something and read the result.

Start Visual Basic and open a new Standard EXE project. A new project containing a blank form will appear.

Step 1: Include the appropriate references

From Visual Basic, go to Project > References. This brings up a dialog box of available references as seen below.

Scroll down until you see the VISA COM 1.0 Type Library, check the box and then click the OK button. This adds the reference for the Keysight I/O Utilities library. Having these references gives you benefits such as typing aids for program lines involving VISA COM commands. The Keysight IO Libraries Suite 14 uses VISA COM 3.0. Only in VB 6.0 and the Excel VBA environment can you call the VISA COM 1.0 Type Library and automatically get access to the VISA COM 3.0 Type Library.

Place a command button on the form. Double-clicking on the command button in design mode will bring you to the Form Code window. Alternately, from the menu bar, you may click View > Code.

 

Step 2: Connect to the instrument

The Keysight IO Libraries Suite provides a Global Resource Manager (GRM), which can create any VISA COM resource installed on the system. Create an instance of the VisaComLib.ResourceManager object and use it to create an object that provides communication to an instrument.

Dim ioMgr As VisaComLib.ResourceManager
Set ioMgr = New VisaComLib.ResourceManager

The easiest way to get a VisaCom object for a specific instrument is to use the Open method.  The Open method is from the interface IMessage that is indirectly referred to from the FormattedIO488 class through the IO property.  For example:

Dim instrument As VisaComLib.FormattedIO488 Set instrument = New VisaComLib.FormattedIO488 Set instrument.IO = ioMgr.Open("GPIB0::10") ' 10 is the instr. address

The above example sets the instrument to a VisaComLib.FormattedIO488 object that can communicate with the instrument on the GPIB0 bus at instrument address 10. Notice that instantiating the instrument is necessary before using the Open method from the IO property. Also notice the syntax used to specify the interface and bus address.

Step 3: Talk to your instrument

The session object (VisaComLib.FormattedIO488) has several mechanisms for sending and receiving data from an instrument. Two of those mechanisms are WriteString and ReadString. The following example shows how to send the instrument identification query and display the instrument's response query in a message box.

Dim idn As String
instrument.WriteString "*IDN?"
idn = instrument.ReadString()
MsgBox "The IDN String is: " & idn, vbOKOnly, "IDN Result"

Press F5 to run the program.  From the menu bar, you may also click on Run > Start.