4 examples using visual basic, Examples using visual basic -12 – KEPCO KLR Series Developers Guide User Manual
Page 34

3-12
KLR-DEV 060713
The functions above used a function checkErr which is part of the project file KpDCPwrEr-
rorHandler.c. This file has calls to two functions: KpDCPwr_GetError and
KpDCPwr_error_query. These two functions check for errors and provide readable text of the
error messages.
 KpDCPwr_GetError(vi, &errorCode, bufferSize, pos);
 // Display the error from the instrument, if that is the source
 if (errorCode == KPDCPWR_ERROR_INSTRUMENT_STATUS)
 {
 KpDCPwr_error_query(vi, &errorCode, buffer);
 }
 MessagePopup("Error!", buffer);
3.4
EXAMPLES USING VISUAL BASIC
The following paragraphs are example of how to use code written in Visual Basic to set the out-
put and take a measurement, and how to use a list to perform as series of operations
3.4.1
SETTING THE OUTPUT TO A VALUE AND TAKING A MEASUREMENT
The following example, written in Visual Basic, sets the output to a value and then takes a mea-
surement. The filename for this example is VBOutputExample.txt, located in the ivi\driv-
ers\kepco\examples folder (see Figure 3-3 for complete code).
Note that Visual Basic has its own methods to support the IVI-COM driver.
Public driver As KepcoDCPwr
Public outputPtr As IKLROutput
Public protectionPtr As IKLRProtection
Public measurementPtr As IKLRMeasurement
 
 Set driver = New KepcoDCPwr
 
Once the driver is initialized, the connection between host and KLR is established using a stan-
dard VISA resource string. It is important that the initialize function be passed as true since its
second argument allows KLR-specific features to be enabled, however in this example, no KLR-
specific feature such as list is required.
 ' initialize the driver - note ID device is true
 driver.Initialize "GPIB0::6::INSTR", _
 True, _
 True, _
 "Cache=true,InterchangeCheck=false,Query-
InstrStatus=true,Simulate=false"
 
 Dim result As Boolean
 result = driver.Initialized
 
 Set outputPtr = driver.Outputs.Item(driver.Outputs)
 Set protectionPtr = driver.Protections.Item(driver.Protections)
 Set measurementPtr = driver.Measurements.Item(driver.Measurements)
