1) We can also utilize Microsoft Visual C++ and debug our drivers

TYX Corporation

Productivity Enhancement Systems

Reference

TYX_0051_20

Revision

1.4

Document

IVI in PAWS Demo.doc

Date

January 10, 2007

 

 

 

IVI-COM in PAWS Studio Demo


Applications used:

TYX PAWS Studio 1.34.6

 

Agilent IO Libraries Suite 14.2.msi (IVI Shared Components v. 1.2.1)

 

Instrument driver 34401 IVI-COM 1.1.0.11

 

Microsoft Visual Studio C++ 6.0

 

Operating System Windows XP Pro SP2

 

Introduction:

This document will help to create a WCEM driver that will help interface the ATLAS code with an IVI-COM instrument driver using the TYX Paws Developer Studio.

As an example we use the IVI-COM driver for Agilent 34401A DMM.   

 

The assumption will be made that the user is familiar with the Paws Developer Studio.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


1         List of requirements

In the PAWS Project example presented in this document we set a goal to implement the following functionality related to the IVI-COM driver:

·        During the initialization, set the following:

o       Resource Name to GPIB address 23

o       IDQuery to false

o       Reset to true

o       Simulate to true

·        Configure the DCVoltage to a range of 1.5 with a resolution of 0.001.

·        Set the Delay property to 0.01.

·        Take a reading with a timeout of 1000.

·        Close the driver session. 

2         Creating the environment:

2.1           Creating PAWS Project

 

  • Open PAWS Studio application and navigate to File\New Project… You should see the following images:

 

Figure 1

 

Figure 2

 

  • You will need to enter the project name and the directory for your project. In this case, we can call the project IVI_COM_DMM. The directory can be anywhere that is convenient for you on your system.

 

Figure 3

 

  • At this point, you can click on OK.

 

  • Now you need to add and ATLAS file to your project and a device database description. The ATLAS file will be part of an ATLAS project module and the device database will be part of the device database project module. After creating a new PAWS project, you are given an ATLAS project module. You just need to add a new file to that module. You will then have to manually add a device database project module before adding a device database file to it.

2.2           Adding Paws Files to the project

 

  • Adding the ATLAS file to the ATLAS project module: We will chose to call this file atlas.atl. From the toolbar, you need to select File\New File…:

 

Figure 4

 

  • This will yield to the following window:

 

Figure 5

 

  • Check the option to add the file to the project
  • And enter the following File Name: atlas as shown below:

 

Figure 6

 

·        Copy the following source code and paste it into the atlas.atl file:

 

 

 001000 BEGIN, ATLAS PROGRAM 'IVI-COM DMM'                   $

 001010 REQUIRE, 'DMM-DC-VOLTS', SENSOR(VOLTAGE), DC SIGNAL,

            CONTROL, VOLTAGE RANGE -300 V TO 300 V,

            MAX-TIME RANGE 1 SEC TO 5 SEC,

            CNX HI LO                                       $

C$

 001110 DECLARE, VARIABLE, 'MEASURED' IS DECIMAL            $

C$

E02000 OUTPUT, C'\LF\ATLAS PROGRAM STARTS HERE\LF\'         $

C$

 002200 VERIFY, (VOLTAGE INTO 'MEASURED'),

                DC SIGNAL USING 'DMM-DC-VOLTS',

            NOM 0 V UL 0.5 V LL -0.5 V,

            VOLTAGE RANGE -0.5 V TO 0.5 V,

                MAX-TIME 5 SEC,

                CNX HI X20-2 LO X20-3                       $

 002300 OUTPUT, C'DC VOLT MEASUREMENT 1 = ', 'MEASURED', C' VDC'  $

C$

 999000 OUTPUT, C'\LF\ATLAS PROGRAM ENDS HERE\LF\'           $

C$

 999999 TERMINATE, ATLAS PROGRAM 'IVI-COM DMM'              $

 

 

 

 


·        This is what it will look like in your Paws Studio:

 

Figure 7

 

·        Now we are ready to add a device database module.

·        Go to File\New Module… Click on DEVICEDB and accept the selection with OK.

 

Figure 8

 

·        Then navigate to File\New File… and choose DEVICE file. Click OK.


·        You will see the following window:

 

Figure 9

 

  • You can now add the file to the project by checking Add to project:.
  • You also need to add the file name dmm to File Name:.

 

Figure 10

 

·        You can now click on OK.


·        You project environment now should look like this:

 

Figure 11

 

·        In the dmm device database file called dmm.ddb, copy the following source code and paste it into it:

 

 

begin dev DMM;

 

      cnx hi DMM-Hi, lo DMM-Lo;

 

      begin FNC = 101; ** DC Voltage Measurement

            sensor(voltage)dc signal;

            control

            {

                  voltage range -300 v to 300 v continuous;

           }

      end; ** DC Voltage Measurement

        

end; *end dmm

 

 

 

Note: To understand the content of this file, please refer to the Paws Studio online help.

 


·        The content of this file will look like this in the Paws Studio:

 

Figure 12

 

 


2.3           Adding the C++ WCEM interface and C++ files to the Paws project:

 

  • At this point you have the basic components for the project in place. You can now build the project by selecting Build\Rebuild All:

 

Figure 13

 

 

  • The next step would be to add the WCEM interface C++ functions invoked by the ATLAS code. Those C++ functions will include the IVI-COM calls to control the instrument. First we will need to add a WCEM project module. Then we will need to create a mapping between the ATLAS and the C++ functions. Finally, we will need to populate those C++ functions with the IVI-COM function calls.

 


  • In order to accomplish that we will take the following action:
    • Go to File\New Module… and click on CEM.
    • Then enter WCEM in Module Name:

 

Figure 14

 

·        You can now click on OK.

 

·        Now, in order to create the mapping between the ATLAS code and the C++ functions, go to View\CEM Wizard… You should see the following images:

 

Figure 15

 

  • In order to create the mapping between the ATLAS code and the C++ function calls, please follow the steps below:
    • This will lead to the following window:

 

Figure 16

 

o       Click on the Advanced tab and you will see the following window:

 

Figure 17

 

o       In order to deal with some of the environmental operations that are needed to connect to the IVI-COM driver, check Load, Unload and Disable CEM Logging check boxes.

 

Figure 18

 

    • You can now click on OK.

o       Back to the previous widow, right click on DMM label and click on Add Interface Function:

 

Figure 19

 

    • This will lead to the following window.

 

Figure 20

 

    • For a series of ATLAS actions, you will need to enter the C++ function name that you wish to invoke. For the Setup Action, please enter DMM_Setup for the User Function Name(s).

 

Figure 21

 

    • Press OK.

 

Note: To obtain more details on how to use CEM Wizard you can refer to the PAWS Studio Help System.

 

    • For Fetch, Init, and Reset, you need to enter the following names: DMM_Fetch, DMM_Init and DMM_Reset.
    • Once you have added the four function names, you can click on OK.
    • This will add several files to your WCEM module:
      • Ctrl.cpp
      • DMM.cpp
      • Error.cpp
      • Wrapper.cpp
      • Key.h

 

    • Ctrl.cpp will include the doOpen and doUnload functions. DMM.cpp will include the four DMM_ functions.
    • The paws project environment should look like this:

 

Figure 22

 

You are also required to add a new *.h file to the project to include some necessary code that we will see later in this tutorial.

In this example we will call this file DMM.h.

    • In order to do this, you will need to right-click on the WCEM module and select Add New File to Module…
    • This will give you the following window:

 

Figure 23

 

o       You need to check Add to project and, select CEM header file and enter DMM in File Name:

 

Figure 24

 

o       You can now press OK.

 


3         Connecting to the IVI-COM instrument driver

3.1           Connecting to the IVI-COM environment:

 

  • You will need to add the following code in your DMM.h file:

 

 

#ifndef __DMM_h__

#define __DMM_h__

 

#include <atlbase.h>

 

#include "Visacom_i.c"

#import "IviDriverTypeLib.dll" named_guids, raw_interfaces_only, raw_native_types no_namespace

#import "IviDmmTypeLib.dll" named_guids, raw_interfaces_only, raw_native_types no_namespace

#import "Agilent34401.dll" named_guids, raw_interfaces_only, raw_native_types no_namespace

 

#endif

 

 

  • Your DMM.h file in your PAWS project will look as follows:

 

Figure 25

 

Note: This header file allows to access to the COM environment, the IVI specific environment and the environment specific to the device, which is in our case an HP34401A instrument.

 

·        Summarizing the effort of adding the WCEM Interface functions you should have the following files generated in your WCEM module:

o       Key.h

o       DMM.h (manually added)

o       Ctlr.cpp with the doUnload() and doOpen() functions

o       DMM.cpp with the DMM_Setup(), DMM_Fetch(), DMM_Init() and DMM_Reset() functions

o       Error.cpp

o       Wrapper.cpp

 


·        The Paws Studio should now look like this:

 

Figure 26

 

·        Let us start with including all the declarations to the ctrl.cpp and DMM.cpp files.

 

·        In ctrl.cpp we need to add the following code:

 

#include "DMM.h"

 

extern CComPtr<IAgilent34401> driver;

extern CComPtr<IAgilent34401DCVoltage> pDMMDCVolt;

extern CComPtr<IAgilent34401Trigger> pDMMTrig;

extern CComPtr<IAgilent34401Measurement> pDMMData;

 

extern HRESULT hr;

 

 

 


  • The code will appear as follows in your Paws project:

 

Figure 27

 

·        In DMM.cpp, we need to add the following lines:

 

#include "DMM.h"

 

CComPtr<IAgilent34401> driver;

CComPtr<IAgilent34401DCVoltage> pDMMDCVolt;

CComPtr<IAgilent34401Trigger> pDMMTrig;

CComPtr<IAgilent34401Measurement> pDMMData;

 

HRESULT hr;

 

 

  • The code will appear as follows in your Paws project:

 

Figure 28

 

 


·        Next we will implement the code related to IVI-COM instrument driver. The code will be entered into the WCEM interface functions, which were generated in the previous steps.

 

·        Once all the required declarations are performed let’s focus on creating the driver object using CoCreateInstance and opening an I/O session to the instrument with Initialize method. Those actions will be implemented in ctrl.cpp file in doOpen() interface function. We will actually set the following values for the initialization procedure:

o       Resource Name to GPIB address 23

o       IDQuery to false

o       Reset to true

            To accomplish the above we need to add the following code:

 

 

hr = driver.CoCreateInstance(CLSID_Agilent34401);

if (FAILED(hr))

{

Display("\033[30;41m Bad return from CoCreateInstance() method\033[m\n");

}

  

hr = driver->Initialize(CComBSTR("GPIB0::23::INSTR"),

                        VARIANT_FALSE,

                        VARIANT_TRUE,

                        CComBSTR(""));  

if (FAILED(hr))

{

Display("\033[30;41m Bad return from Initialize()

method\033[m\n");

}    

 

 

  • The code will appear as follows in your Paws project:

 

Figure 29

 

Note: doOpen is called for the first time when the Paws project is loaded by the Run time system.

If you intend to use Non-ATLAS modules in your ATLAS code, subsequent calls to doOpen will be made and you will need to take care to execute the code above only once.

 


3.2           IVI-COM calls made for the measurements:

 

·        The next step would be to setup the DC Voltage measurement and configure it with the following options:

o       Range of 1.5

o       Resolution of 0.001

To do that we need to add the following code into the DMM.cpp file in the DMM_Setup() interface function:

 

 

hr = driver->put_Function(Agilent34401FunctionDCVolts);

if (FAILED(hr))

{

Display("\033[30;41m Bad return from

put_Function(Agilent34401FunctionDCVolts) method\033[m\n");           

}

hr = driver->get_DCVoltage(&pDMMDCVolt);    

if (FAILED(hr))

{

Display("\033[30;41m Bad return from get_DCVoltage(&pDMMDCVolt) method\033[m\n");           

}

hr = pDMMDCVolt->Configure(1.5, 0.001);

if (FAILED(hr))

{

Display("\033[30;41m Bad return from >Configure(1.5, 0.001) method\033[m\n");            

}   

 

  • The code will appear as follows in your Paws project:

 

Figure 30

 

 


·        In this step we set the trigger delay to 0.01 and we initiate the measurement implementing the following code in the DMM.cpp file in the DMM_Init() interface function:

 

 

hr = driver->get_Trigger(&pDMMTrig);

if (FAILED(hr))

{

Display("\033[30;41m Bad return from get_Trigger(&pDMMTrig)  method\033[m\n");           

}

hr = pDMMTrig->Configure(Agilent34401TriggerSourceImmediate, 0.01);

if (FAILED(hr))

{

Display("\033[30;41m Bad return from Configure(Agilent34401TriggerSourceImmediate, 0.01) method\033[m\n");           

}

hr = driver->get_Measurement(&pDMMData);

if (FAILED(hr))

{

Display("\033[30;41m Bad return from get_Measurement(&pDMMData) method\033[m\n");

}      

hr = pDMMData->Initiate();

if (FAILED(hr))

{

      Display("\033[30;41m Bad return from Initiate() method\033[m\n");           

} 

 

 

  • The code will appear as follows in your Paws project:

 

Figure 31

 


·        Now we implement the measurement reading with a timeout of 1000 ms using Fetch method. In addition we add the code, which will allow sending the reading value back to the PAWS Studio. We enter the code into the DMM.cpp file in the DMM_Fetch() interface function:

 

 

{

        double Data = 0;

        DATUM *fdat;

 

        hr = pDMMData->Fetch(1000, &Data);

        if (FAILED(hr))

        {

                        Display("\033[30;41m Bad return from Fetch(1000, &Data) method\033[m\n");

        }

 

        fdat = FthDat();

        DECDatVal(fdat, 0) = Data;

        FthCnt(1);

 

        return 0;

}

 

 

  • The code will appear as follows in your Paws project:

 

Figure 32

 

Note: The first argument in the Fetch method specifies how long to wait in the Fetch operation since it is possible that no data is available or the trigger event did not occur. The second parameter contains the actual reading or a value indicating that an over-range condition occurred.

According to the Agilent 34401A IVI documentation, if an over-range condition occurs, the value contains IEEE NaN and the method returns an over-range error.

 

 

 


  • In section 1.4 we added the DMM_Reset interface function to the project. For the purpose of this example, this function is not required to be implemented and remains therefore empty.

In general it would be proper to add some code to reset the instrument by calling the appropriate function(s) from DMM_Reset.

If we wanted to follow that rule we could use the following code:    

 

 

hr = driver->get_Utility(&pIVIDU);

if (FAILED(hr))

{

Display("\033[30;41m Bad return from get_Utility() method\033[m\n");

}    

pIVIDU->Reset();                                                                                                                                                 

 


3.3           Disconnecting from the IVI-COM environment:

·        The final step would be to close the I/O driver session. This will be performed in the ctrl.cpp file in the doUnload() interface function. Also we need to call Release method on each Com Pointer we declared:

 

hr = driver->Close();

if (FAILED(hr))

{

Display("\033[30;41m Bad return from Close() method\033[m\n");

}

 

driver.Release();

pDMMData.Release();

pDMMTrig.Release();

pDMMDCVolt.Release();

 

 

  • The code will appear as follows in your Paws project:

 

Figure 33

 

Note: The function doUnload gets called only once when the Paws project is unloaded from the Run time system.

 


4         Building the project

4.1           Building setting

 

  • Once the WCEM driver is implemented we need to adjust the CEM settings to allow the proper building environment. To accomplish that navigate to Options\CEM…

 

Figure 34

 

  • After clicking on CEM… you should see the following figure:

 

Figure 35

 

 

  • The settings under the Options tab should remain unchanged. The next step would be to invoke the settings under the Files tab, which would lead to the following image:

 

Figure 36

 

  • Next to the Include Path edit box you need to add the following path: C:\Program Files\IVI\Include. Click Apply.

 

Figure 37

 

Note: The path you just added is needed to include the Visacom_i.c file from the DMM.h header.

 

4.2           Building process

 

  • Now since all the settings are properly adjusted to successfully build the project, navigate to Build\Rebuild All.

 

Figure 38

 

  • As a result of this action you should see the following message in the Output area:

 

Figure 39

 

·        The message in the Output area indicates that the project was successfully built.

 


5         Running the project

5.1           Run Time system environment

 

  • The assumption at this point is that it is possible to talk to the device using the IVI driver, from any application designed to do so, which will have been installed along with all necessary IVI environments.
  • We are at a point where we built the project. Now we need to prepare the Run Time system to be ready for execution of this project.

In this effort it is crucial to edit the proper content of the Busconfi file, which is read by the Run Time system prior to loading the dll (WCEM driver).  Just go to the Project Workspace area and double click on the Busconfi.

 

Figure 40

 


  • As you can see on the Figure 40 the Edit Area presents the Busconfi text needed for the Run Time system to execute the project.
  • The DMM name has to correspond to the name defined in the dmm.ddb file with the “begin dev DMM; statement.
  • The Listen Address MLA and Talk Address MTA need to be set to the device address, which is 23 in this case.
  • Also the “BUS “number, which is “1 in this example needs to correspond to the “Channel” number. You will find the code for the Busconfi below:

 

;       IEEE-488 Bus Configuration File -

 

"Channel"        1              

 

DMM      BUS 1 MLA 23      MTA 23

 

5.2           Loading and running the project

 

  • At this point we are ready to load the project and execute it. To do so you need to navigate to Build\Execute Wrts or to go to the exclamation mark icon on the Tool Bar as presented on the images below:

 

Figure 41

 

 

 

 

 

 

 

 

  • The previous action may bring the following message before invoking the Run Time system interface:

 

Figure 42

 

Note: You need to have your project built before executing it. This message usually shows up when some changes occurred to the code without recompiling it. To stay on the safe side click Yes to let the project to be rebuilt before execution.

If you make any changes to the Busconfi file, you will not need to rebuilt the project as it is only used as a reference file at runtime and does not need to be incorporated in any binary file.

 

  • Assuming that the instrument is connected the station we should see the following image:

 

Figure 43

 

 

  • At this point the WCEM.dll is loaded and the project is ready to be executed. Now you need to press Run to proceed with the test. That will result yield to the following picture:

 

Figure 44

 

  • The test was concluded successfully.
  • Now to exit from the Run Time system go to File\Exit.

 

Figure 45