beautypg.com

KEPCO KLR Series Developers Guide User Manual

Page 27

background image

KLR-DEV 060713

3-5

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This program demonstrates how to set a voltage and current
and measure the output voltage using the IVI-COM driver.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

#include
#include
#include
#include

#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
IKLRPtr driverPtr=NULL;
hr = driverPtr.CreateInstance(__uuidof(KepcoDCPwr));
if (FAILED(hr))

exit(1);

Once initialized, communication with the KLR 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 limit model, list and other advanced features of the KLR 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 KLR.
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
IKLROutputPtr outputPtr;
outputPtr = driverPtr->Outputs->GetItem(OLESTR("Output"));

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