Getting Started Using Visual Basic

This section contains information specific to the Windows product.

This section provides guidelines to getting started programming applications in Visual Basic 6.0 (VB 6.0). The subtopics are:

Visual Basic Program Sample Code

This section describes a sample program called idn that queries a GPIB instrument for its identification string. This sample builds a console application using the Microsoft Visual Basic 6.0 programming environment.

NOTE: Be sure to include the sicl32.bas file in your Visual Basic project. This file contains the necessary SICL definitions, function prototypes, and support procedures to allow you to call SICL functions from Visual Basic.

The default install location for the Keysight IO Libraries Suite is C:\Program Files\Agilent\IO Libraries Suite. Sample Visual Basic programs for SICL are located at http://www.keysight.com/find/iosuite. Each sample program implemented in Visual Basic 6 contains a project file (.vbp) that you can open from Visual Basic 6.0.

The idn sample files include the Visual Basic module, idn.bas. This module is listed on the following pages (some comments are not listed). An explanation of the function calls in the sample follows the program listing.

Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''
' idn.bas
' The following subroutine queries *IDN? on a
'  GPIB instrument and prints out the result. No '  SICL error handling is set up in this
example, but should be as good programming
practice
'''''''''''''''''''''''''''''''''''''''''''''''

Sub Main()
 Dim id As Integer
  Dim strres As String * 80 ‘ Fixed-length
‘ String
 Dim actual As Long
  ' Open the instrument session
  ‘"gpib0" is the SICL Interface name as
‘ defined in the Connection Expert
  ' "22" is the instrument gpib address on the   ' bus
  ' Change these to the SICL Name and gpib
‘ address for your instrument

id = iopen("gpib0,22")
Call itimeout(id, 5000)

  ' Query device's *IDN? string
Call iwrite(id, "*IDN?" + Chr$(10), 6, 1, 0&)

' Read result
Call iread(id, strres, 80, 0&, actual)

' Display the results
MsgBox "Result is: " + strres, vbOKOnly,
"*IDN? Result"

' Close the instrument session
Call iclose(id)

End Sub

Visual Basic Sample Code Description

id

Notice the declaration of id at the beginning of Sub Main(). The integer id is used to represent a unique identifier that will describe the specific device or interface that you are communicating with. The id is set by the return value of the SICL iopen call and will be set to 0 if iopen fails for any reason.

iopen

When an iopen call is made, the parameter string “gpib0,22” passed to iopen specifies the GPIB interface followed by the bus address of the instrument. The interface name “gpib0” is the name given to the interface during execution of Connection Expert. The bus (primary) address of the instrument follows (“22” in this case) and is typically set with switches on the instrument or from the front panel of the instrument.

NOTE: To modify the program to set the interface name and instrument address to those applicable for your setup, see Programming with SICL for information on using SICL's addressing capabilities.

NOTE: You can view error messages by running the Event Viewer. To launch Event viewer, first open the Keysight IO Control application from Application Finder and then selectEvent Viewer.

itimeout

itimeout is called to set the length of time (in milliseconds) that SICL will wait for an instrument to respond. The specified value will depend on the needs of your configuration. Different timeout values can be set for different sessions as needed.

iwrite and iread

The SICL I/O iwrite function sends a block of data to an interface or device and iread reads raw data from the device or interface. The iwrite call sends the Standard Commands for Programmable Instruments (SCPI) command *IDN? to the instrument that asks for its identification string.

The fixed-length string strres is read back into buf with iread and this is then displayed in a Message Box. SICL automatically handles all addressing and GPIB bus management necessary to perform these reads and writes to the instrument.

iclose

The iclose function closes the device session to this instrument (idis no longer valid after this point).

Building and Running the VB Sample Program

The idn sample includes these files, which you can use to build and run the sample program:

  • idn.bas Microsoft Visual Basic 6.0 Module file
  • idn.vbp  Microsoft Visual Basic 6.0 Project file
  • idn.vbw   Microsoft Visual Basic 6.0 Workspace file

The steps to build and run the idnsample program follow.

  1. Connect an instrument to a GPIB interface that is compatible with IEEE 488.2.

  2. Start the Visual Basic 6.0 application.

NOTE: This example assumes you are building a new project (no .vbp file exists for the project). If you do not want to build the project from scratch, from the menu select File > Open Project..., select and open the idn.vbp file, and skip to Step 7.

  1. Start a new Visual Basic (VB 6.0) Standard EXE project. VB 6.0 will open up a new Project1 project with a blank Form, Form1.

  2. From the menu, select Project > Add Module, select the Existing tab, and browse to the directory where you have downloaded the sample code. Select the file idn.bas and click Open.

  3. (Optional) Since the Main() subroutine is executed when the program is run without requiring user interaction with a Form, you may choose to deleteForm1. To do this, right-click Form1 in the Project Explorer window and select Remove Form1.

  4. SICL applications in Visual Basic require that the SICL Visual Basic declaration file sicl32.bas module be added to your VB project. This file contains the SICL function definitions and constant declarations needed to make SICL calls from Visual Basic. To add this module to your project, from the menu select Project > Add Module, select the Existing tab, browse to the include directory under the Keysight IO Libraries Suite install directory (by default, this is C:\Program Files\Agilent\ IO Libraries Suite\include), select sicl32.bas, and click Open.

  5. At this point, you can run and debug the Visual Basic project.

  6. The program assumes the SICL interface ID is gpib0 (set using Connection Expert) and the instrument is at bus address 22. If necessary, modify the interface name and instrument address.

  7. If the program runs correctly, an example of the output if connected to a Keysight 34401A multimeter would be:
    AGILENT TECHNOLOGIES,34401A,123456789,A.01.01

  8. If you want to make an executable file, from the menu select File > Make idn.exe... and click Open. This will create idn.exe in the idn directory.

  9. If the program does not run, see the message logger for a list of run-time errors and see Troubleshooting SICL Programs for guidelines to correct the problem.

Where to Go Next

In addition, see the chapter(s) that describe how to use SICL with your specific interface(s):

You may also want to familiarize yourself with SICL functions, which are defined in the reference information provided elsewhere in the SICL online Help. If you have any problems, see Troubleshooting SICL Programs for more information.