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
- Visual Basic Sample Code Description
- Building and Running the VB Sample Program
- Where to Go Next
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 fromEvent 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
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 fileidn.vbp
Microsoft Visual Basic 6.0 Project fileidn.vbw
Microsoft Visual Basic 6.0 Workspace file
The steps to build and run the idnsample program follow.
-
Connect an instrument to a GPIB interface that is compatible with IEEE 488.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
> O
pen Project...
, select and open the idn.vbp
file, and skip to Step 7.
-
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
. -
From the menu, select
Project > Add Module
, select theExisting
tab, and browse to the directory where you have downloaded the sample code. Select the fileidn.bas
and clickOpen
. -
(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-clickForm1
in the Project Explorer window and selectRemove Form1
. -
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 selectProject > Add Module
, select theExisting
tab, browse to theinclude
directory under the Keysight IO Libraries Suite install directory (by default, this isC:\Program Files\Agilent\ IO Libraries Suite\include)
, selectsicl32.bas
, and clickOpen
. -
At this point, you can run and debug the Visual Basic project.
-
The program assumes the SICL interface ID is
gpib0
(set using Connection Expert) and the instrument is at bus address22
. If necessary, modify the interface name and instrument address. -
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
-
If you want to make an executable file, from the menu select
File
>
Make idn.exe...
and clickOpen
. This will createidn.exe
in theidn
directory. -
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
- Programming With SICL - For more detailed information about SICL programming
In addition, see the chapter(s) that describe how to use SICL with your specific interface(s):
- Using SICL with GPIB shows how to communicate over the GPIB interface.
- Using SICL with VXI shows how to communicate over the VXIbus interface.
- Using SICL with RS-232 shows how to communicate over the RS-232 interface.
- Using SICL with a LAN shows how to communicate over a Local Area Network (LAN).
- Using SICL with USB shows how to communicate over a USB interface.
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.