Example. Program Written in C
The following program shows the control over the Analyzer using the C language with the VISA library.
The Analyzer address is passed as a parameter in the command line at the start of the program. For more detail on VISA Resource Name, see the VISA library documentation.
Program description:
1. Sets up communication with the Analyzer.
2. Reads out and displays the Analyzer information string.
3. Sets some parameters for the Analyzer.
4. Triggers the measurement and waits for sweep completion.
5. Reads out the measurement data and the frequency values at the measurement points.
6. Displays the measurement data
// Example.cpp // // VISA Header: visa.h (must be included) // VISA Library: visa32.lib (must be linked with) #include "stdafx.h" #include "visa.h" int main(int argc, char* argv[]) { ViStatus status; // Error checking ViSession defaultRM, instr; // Communication channels ViUInt32 retCount; // Return count from string I/O ViByte buffer[255]; // Buffer for string I/O ViUInt32 temp; int NOP = 21; // Number of measurement points const int maxCnt = 100; // Maximum reading count double Data[maxCnt*2]; // Measurement data array double Freq[maxCnt]; // Frequency array if (argc < 2) { printf("\nUsage: Example <VISA address>\n\n"); printf("VISA address examples:\n"); printf(" TCPIP::nnn.nnn.nnn.nnn::5025::SOCKET\n"); printf(" TCPIP::hostname::5025::SOCKET\n"); return –1; } status = viOpenDefaultRM(&defaultRM); if (status < VI_SUCCESS) { printf("Can't initialize VISA\n"); return –1; } status = viOpen(defaultRM, argv[1], VI_NULL, VI_NULL, &instr); if (status < VI_SUCCESS) { printf("Can't open VISA address: %s\n", argv[1]); return –1; } // // Set the answer timeout // viSetAttribute(instr, VI_ATTR_TMO_VALUE, 5000); // // Enable the terminal character // viSetAttribute(instr, VI_ATTR_TERMCHAR_EN, VI_TRUE); viSetAttribute(instr, VI_ATTR_TERMCHAR, '\n'); // // Read ID string from Analyzer // viPrintf(instr, "*IDN?\n"); viRead(instr, buffer, sizeof(buffer), &retCount); printf("*IDN? Returned %d bytes: %.*s\n\n", retCount, retCount, buffer); // // Set up the Analyzer // viPrintf(instr, "SYST:PRES\n"); viPrintf(instr, "SENS:SWE:POIN %d\n", NOP); viPrintf(instr, "CALC:PAR1:DEF S21\n"); viPrintf(instr, "CALC:PAR1:SEL\n"); viPrintf(instr, "CALC:FORM MLOG\n"); viPrintf(instr, "SENS:BAND 10\n"); // // Trigger measurement and wait for completion // viPrintf(instr, ":TRIG:SOUR BUS\n"); viPrintf(instr, ":TRIG:SING\n"); viQueryf(instr, "*OPC?\n", "%d", &temp); // // Read out measurement data // retCount = maxCnt * 2; viQueryf(instr, "CALC:DATA:FDAT?\n", "%,#lf", &retCount, Data); retCount = maxCnt; viQueryf(instr, "SENS:FREQ:DATA?\n", "%,#lf", &retCount, Freq); // // Display measurement data // printf("%20s %20s %20s\n", "Frequency", "Data1", "Data2"); for (int i = 0; i < NOP; i++) { printf("%20f %20f %20f\n", Freq[i], Data[i*2], Data[i*2+1]); } status = viClose(instr); status = viClose(defaultRM); return 0; } |
Example. Program Written in LabView
The following program shows the control over the Analyzer using LabView language with the VISA library.
Seen below is the block diagram of the program and front panel of the program with the program execution result.
The front panel contains the entry field for the Analyzer name "VISA Resource Name". For more detail on VISA Resource Name see the VISA library documentation.
The user must enter the Analyzer address, select the trace format in the "Format" field, and click the "Run" button. As the result of the program, the Analyzer information string will be displayed, and the measurement trace will be plotted.
Program description:
1. Sets up communication with the Analyzer.
2. Reads out and displays the Analyzer information string.
3. Sets some parameters of the Analyzer.
4. Generates the trigger and waits for the sweep completion.
5. Sets the trace format to the format entered by the user in the "Format" field.
6. Reads out the measurement data.
7. Displays the measurement data.