Tektronix Using the TekScope IVI-COM Driver from LabWindows/CVI User manual

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.
TekVISA. IVI shared components. TekScope IVI-COM driver. LabWindows/CVI 6.0

Generating the wrapper FPs

Step 1: Start LabWindows

Start the LabWindows/CVI environment and select Create ActiveX Controller… from the Tools menu.
Tektronix OpenChoice Solutions Software Developers’ Kit – Articles (001137500)
1
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.
2
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
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.
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
3
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.
4
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
Using the TekScope IVI-COM Driver from LabWindows/CVI
Figure 4: ActiveX Controller Wizard – Advanced Options
Figure 5: All Driver Interfaces, Methods, and Properties
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
5
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.
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
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.
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
7
Using the TekScope IVI-COM Driver from LabWindows/CVI
Figure 8: The FP Opened

Step 4: Run the FP

Open the Initialize function panel. In the function panel specify the Object Handle as objTekScope and Resource Name as VISA resource name. Here we
have used GPIB8::1::INSTR as the resource name. Run the FP, as shown in Figure 9.
8
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
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.
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
9
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.
10
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
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.
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
11
Using the TekScope IVI-COM Driver from LabWindows/CVI
#include "TekScope.h" #include <ansi_c.h>
#include <cvirte.h> #include <userint.h> #include "CVIClient.h"
static int panelHandle;
//Declare the global variables static CAObjHandle TekScopeHandle; //for IVI-COM driver object static HRESULT hr; //for HRESULT value
int main (int argc, char *argv[]) { if (InitCVIRTE (0, argv, 0) == 0) return -1; /* out of memory */ if ((panelHandle = LoadPanel (0, "CVIClient.uir", PANEL)) < 0) return -1; DisplayPanel (panelHandle);
// Create an instance of the TekScope IVI-COM driver
hr = TekScopeTektronixLib_NewITekScope (NULL, 1, LOCALE_NEUTRAL, 0, &TekScopeHandle);
// if instance created successfully, initialize it if ( hr == S_OK)
hr = TekScopeTektronixLib_ITekScopeInitialize (TekScopeHandle, NULL,
"GPIB8::1::INSTR",
12
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
Using the TekScope IVI-COM Driver from LabWindows/CVI
VFALSE, VFALSE,"");
RunUserInterface (); DiscardPanel (panelHandle); return 0; }
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
if ( hr == S_OK)
hr = TekScopeTektronixLib_ITekScopeHorizontalGetRecordLength (TekScopeHandle, NULL,&nRecLen);
if ( hr == S_OK) {
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
13
Using the TekScope IVI-COM Driver from LabWindows/CVI
sprintf(strMsg,"Record Length is:%d",nRecLen); MessagePopup ("Tektronix", strMsg); }
break; } return 0; }
int CVICALLBACK OnExit (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) {
switch (event)
{ case EVENT_COMMIT: if ( hr == S_OK)
TekScopeTektronixLib_ITekScopeClose (TekScopeHandle, NULL); QuitUserInterface (0);
break; } return 0; }
14
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)

Conclusion

Using the TekScope IVI-COM Driver from LabWindows/CVI
Step 4: Run the application.
Similarly, you can use other driver functions from LabWindows/CVI.
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
15
Using the TekScope IVI-COM Driver from LabWindows/CVI
16
Tektronix OpenChoice Software Developers’ Kit – Articles (001137500)
Loading...