4 examples using visual basic, Examples using visual basic -13 – KEPCO KLP Series Developers Guide, Rev 3 User Manual
Page 35

KLP-DEV 041213
3-13
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 IKLPOutput
Public protectionPtr As IKLPProtection
Public measurementPtr As IKLPMeasurement
 
 Set driver = New KepcoDCPwr
 
Once the driver is initialized, the connection between host and KLP 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 KLP-specific features to be enabled, however in this example, no KLP-
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)
