Using the TekScope IVI-COM Driver from LabWindows/CVI
Introduction
LabWindows/CVI is a popular test-automation package from National
Instruments. LabWindows uses the powerful C language to build Virtual
Instruments. This document describes the step-by-step procedure for using the
TekScope IVI-COM driver from LabWindows/CVI environment.
LabWindows/CVI version 6.0 and higher support using Microsoft COM
components.
In this simple exercise, you will learn how to import the TekScope IVI-COM
driver from LabWindows environment using its Create ActiveX Controller
feature. You will also learn how to use these wrappers to build a simple UI to
connect to an oscilloscope and get current record length.
Requirements
The following software must be installed on your oscilloscope.
Using the TekScope IVI-COM Driver from LabWindows/CVI
Figure 1: Select Create ActiveX Controller
Step 2: Select the TekScope IVI-COM driver
Step 1 will bring up the ActiveX Controller Wizard – Welcome dialog. Click on
the Next button in this dialog. The ActiveX Controller Wizard – Choose Server
dialog box then comes up. This dialog lists all the ActiveX servers registered in
the machine. From the list, select the TekScope IVI-COM driver, as shown in
Figure 2, and click on Next.
Using the TekScope IVI-COM Driver from LabWindows/CVI
Figure 2: The ActiveX Controller Wizard – Choose Server
Step 3: Create the file
In the ActiveX Controller Wizard – Configure dialog, specify a .fp file name (Ex:
TekScope.fp) and path using the Browse button, as shown in Figure 3. This file
will be created by the wizard, and all the wrappers for properties/methods of IVI
driver are stored in this file. Click Next with other setting as defaults.
Using the TekScope IVI-COM Driver from LabWindows/CVI
Figure 3: The ActiveX Controller Wizard - Configure
Step 4: Advanced options
Step 3 brings up the ActiveX Controller Wizard – Advanced Option dialog, as
shown in Figure 4. Use this ActiveX Controller Advanced Options dialog box to
select the objects you want to include in the instrument driver and to change the
names of the functions and properties that the wizard generates. You can also
browse through all the interfaces, methods and properties of driver, as shown in
Figure 5.
In this exercise, do not change anything in Advanced Options so that a wrapper is
generated for the whole driver. Click Next to generate the wrapper FPs.
Generating wrappers may take some time because the wizard also compiles all
the wrappers during this process. After successful completion, you will get a
message.
Using the TekScope IVI-COM Driver from LabWindows/CVI
Step 5: Save
Once the wrapper generation is complete, TekScope.fp file is automatically added
to LabWindows default Untitled.prj project. Save this project in the name of
CVISample.prj.
Testing the Wrapper FPs
Step 1: Display the Select Function Panel window
Double click on the TekScope.fp file in the LabWindows environment to display
the Select Function Panel window, as shown in Figure 6.
Figure 6: The Select Functions Panel window
Step 2: List all driver top level functions
6
Double click on the ITekScope… to list all top level functions of driver, as shown
in Figure 7.
Using the TekScope IVI-COM Driver from LabWindows/CVI
Figure 7: Top Level Functions
Step 3: Run the FP
Double click on the New ITekScope to open the FP, as shown in Figure 8. This
function is used to create a new ITekScope object, and obtain a handle to the
object. The obtained handle is used to call other functions of the driver. Declare a
variable named objTekScope for the Object Handle control by first clicking on
this control and then using Code > Declare Variable…. Run the FP.
Using the TekScope IVI-COM Driver from LabWindows/CVI
Figure 9: The FP Run
Step 5: Test driver functionality
To test the driver functionality, run a simple function Get Instrument Model.
Open this function from the IviDriverIdentity class, specify the same object
handle and run it. After running successfully the instrument model is returned. In
the example shown in Figure 10, the model returned is TDS7104.
Using the TekScope IVI-COM Driver from LabWindows/CVI
Figure 10: The Model Returned is TDS7104
Step 6: Close the oscilloscope connection
Similarly, open the Close function panel and run it to terminate the connection to
the oscilloscope.
Developing a Simple CVI Application
Step 1: Create a new UI
From File menu select New > User Interface (*.uir)… to create a new user
interface. Add to command buttons to the UI and change the captions of the
buttons to Record Length? and Exit, as shown in Figure 11. Save the file as
CVIClient.uir.
Using the TekScope IVI-COM Driver from LabWindows/CVI
Figure 11: Changed Button Captions
Step 2: Create Skeleton Code
From the CVIClient.uir window select Code > Generate > All Code…. In the
Generate all Code window, select the Add To Current Project option of the
Target files drop down list and then press OK to generate a cviclient.c file. This
C file will have skeleton code ready for main and command button callbacks.
Double click on this file in the project window to explore the code.
Step 3: More Code
The code is given in the following table. The code in blue are added to the
default codes (in black) generated by the LabWindows. You can copy these blue
colored codes to your existing .C file.
Note:
If you want to add additional driver functions to your C file, place your cursor in
the C file where you want to add a function call and click. Open the function
panel of that function. From the function panel window select Code > Insert Function Call.
int CVICALLBACK GetRecordLength (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
long nRecLen;
char strMsg[256];
switch (event)
{
case EVENT_COMMIT:
//Get the current record length of the oscilloscope