Define Error Checking
1Next define error checking for your program. First you will define a macro to catch the errors. It is better to define it once at the beginning of the program that to add the logic to each of your program statements. After the #include statements, type the following lines:
#ifndef checkErr
#define checkErr(fCall) | \ |
| |
if (error = (fCall), | (error = | (error < 0) ? \ | |
error : VI_SUCCESS)) | \ |
|
|
{goto Error;} else error = error #endif
2Next you will type the following lines at the end of the program to handle any errors that occur:
Error:
if (error != VI_SUCCESS)
{
ViChar errStr[2048];
hp34401a_GetError (session, &error, 2048, errStr); printf ("Error!", errStr);
}
Note: Including error handling in your programs is good practice. This code checks for errors in your program.
Initialize the Instrument
1To initialize the instrument, add the following Initialize with Options function right after the variable declarations you added in the previous section
checkErr( hp34401a_InitWithOptions (“GPIB::23::INSTR”, VI_FALSE, VI_TRUE, “Simulate = 1”, &session));
This initializes the instrument with the following parameters:
•GPIB0::23::INSTR as the Resource Name (instrument at GPIB address 23)
•VI_FALSE Does not perform an ID Query
•VI_TRUE Resets the device
•
•
Using IVI with Visual C++ • 25
•
•
•