HP (Hewlett-Packard) Drive Network Card User Manual


 
Using IVI with Visual C++
21
Set the Reading Timeout/Display the Reading
Create a variable to represent the reading and make a reading with a timeout of 1
second (1000 milliseconds).
1 Type
double reading = dmm->Measurement->Read(1000);
2 To display the reading, use printf. Type
wprintf(L“Reading: %g\n”, reading);
Error Checking
To catch errors in the code, activate error checking.
1 Surround the preceding statements with a try block. Add the following lines as
shown in the illustration above:
try {
}
2 Process errors in a catch block. Type
catch (_com_error e) {
wprintf(L“Error: %s”, e.ErrorMessage());
}
Close the Session
To close out the instance of the driver and free resources, type
dmm->Close();
The final code should look like the following:
#include "stdafx.h"
#import "IviDriverTypeLib.dll" no_namespace
#import "IviDmmTypeLib.dll" no_namespace
#import "GlobMgr.dll" no_namespace
#import "Agilent34401.dll" no_namespace
int IVI_Demo()
{
HRESULT hr;
hr = CoInitialize(NULL);
if(FAILED(hr))