KEPCO KLP Series Developer's Guide, Rev 1 User Manual

Page 27

Advertising
background image

KLP-DEV 031113

3-5

#include <conio.h>
#include <atlbase.h>

#import "IviDriverTypeLib.dll" no_namespace
#import "IviDCPwrTypeLib.dll" no_namespace
#import "KepcDCPwr.dll" no_namespace

The driver dll’s must be loaded and initialized to operate:

hr = CoInitialize(NULL);
if (FAILED(hr))

exit(1);

// create a safe pointer for interface access
IKlpPtr driverPtr=NULL;
hr = driverPtr.CreateInstance(__uuidof(KepcoDCPwr));
if (FAILED(hr))

exit(1);

Once initialized, communication with the KLP must be established. The following code shows
how to open the driver at GPIB address 6. The id query is set to true. Failure to id query to true
will reduce the functionality of the driver to the DCPWR class capabilities, preventing functions
such as setting the virtual model, list and other advanced features of the KLP from being
accessed.

// open the instrument for communication
hr = driverPtr->Initialize(
"GPIB0::6::INSTR", //Visa address,(not applicable if simulation=true)
VARIANT_TRUE, // ID query
VARIANT_TRUE, // Reset
LPCTSTR("Cache=true, InterchangeCheck=false, QueryInstrStatus=true,

Simulate=false")); //IVI options

The driver is a linked list of pointers to properties and functions. To read a property, it is neces-
sary to locate the property. The following shows how to read the firmware revision of the KLP.
To read this property the identification must be performed first.

bstrInstrFwRev = driverPtr->Identity->InstrumentFirmwareRevision;

Accessing properties requires many pointer operations. The examples below use pointer redi-
rection to make the operations a little clearer.

// get pointers to the needed interfaces
IKlpOutputPtr outputPtr;
outputPtr = driverPtr->Outputs->GetItem(OLESTR("Output"));

IKlpMeasurementPtr measurementPtr;
measurementPtr = driverPtr->Measurements->GetItem(OLESTR("Measurement"));

Advertising