|
TYX Corporation Productivity Enhancement Systems
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 requirementsIn 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
Figure 2
Figure 3
2.2 Adding Paws Files to the project
Figure 4
Figure 5
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
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:
Figure 13
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
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
o Back to the previous widow, right click on DMM label and click on Add Interface Function:
Figure 19
Figure 20
Figure 21
Note: To obtain more details on how to use CEM Wizard you
can refer to the PAWS Studio Help System.
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.
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 driver3.1 Connecting to the IVI-COM environment:
#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
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;
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;
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");
}
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"); }
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");
}
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; }
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 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();
Figure 33 Note: The function doUnload
gets called only once when the Paws project is unloaded from the Run time
system. 4 Building the project4.1 Building setting
Figure 34
Figure
35
Figure 36
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
Figure 38
Figure 39 ·
The message in
the Output area indicates that the project was successfully built. 5 Running the project5.1 Run Time system environment
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
; IEEE-488 Bus Configuration File - "Channel" 1 DMM BUS 1 MLA
23 MTA 23 5.2 Loading and running the project
Figure 41
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.
Figure 43
Figure 44
Figure 45
|