VectorStar™ MS4640A SeriesMicrowave Vector Network Analyzer : Appendix B — Programming with LabWindows/CVI : Example 5 ─ Acquiring Trace Data
 
Example 5 ─ Acquiring Trace Data
Here we get the final data from Trace 2 which is set to Log magnitude and Phase data. The data comes out in a one-dimensional interleaved array. We need to decimate the array to get the log mag and phase data into two separate arrays. The code snippet is below.
 
//==============================================================================
//
// Title: Example 5
// Purpose: Acquire Trace Data
//
// Created on: 11/30/2011 by David Judge.
// Copyright: Anritsu. All Rights Reserved.
//
//==============================================================================
 
//==============================================================================
// Include files
#include <ansi_c.h>
#include <visa.h>
#include <userint.h>
#include <formatio.h>
#include "au464x.h"
 
ViSession session;
ViStatus checkErr (ViStatus status);
#define CHECKERR(fCal) \
if (au464x_status = checkErr((fCal)), au464x_status < VI_SUCCESS) \
goto Error; else
 
 
int main (int argc, char *argv[])
{
ViInt32 retCount;
ViStatus status;
ViUInt32 read_count;
ViStatus au464x_status = VI_SUCCESS;
FILE* fp;
ViChar readBuffer[500000];
ViReal64 fdata[201];
ViReal64 chanData[402];
ViReal64 lmData[201];
ViReal64 phaseData[201];
int i, ii = 0;
// We configure the Trace to 2 Rows, 1 column with Trace 1 as LogMag and Phase.
// We get the Frequency data and then the Formatted Data.
// Note that we have 201 data points but we get 402 pieces of data.
// The data is interleaved so we decimate it in this loop.
CHECKERR(au464x_init ("VectorStar_Test", VI_FALSE, VI_FALSE, &session));
CHECKERR(au464x_SetSweepPoints (session, 1, 201));
CHECKERR(au464x_SetTraceCount (session, 1, 2));
CHECKERR(au464x_SetTraceFormat (session, 1, 1, AU464X_TRACEFORMAT_LOGPH));
CHECKERR(au464x_SetTracesLayout (session, 1, AU464X_DISPLAYLAYOUT_R2C1));
CHECKERR(au464x_GetFrequencyList (session, 1, fdata, 201 , &retCount));
CHECKERR(au464x_GetFormattedData (session, 1, chanData, 402,&retCount));
au464x_close(session);
fp = fopen(".\\chanData.txt","w") ;
for (i=0;i<201;i++)
{
lmData[i] = chanData[ii++];
phaseData[i] = chanData[ii++];
fprintf(fp,"%e %10.4f\t%10.4f\n",fdata[i],lmData[i],phaseData[i]);
}
fclose(fp);
Error:
printf("\n\nHit return to exit:");
getc(stdin);
return 0;
}
 
ViStatus checkErr (ViStatus status)
{
ViChar error_message [256];
ViUInt32 read_count;
ViChar error_buffer [1024];
ViInt32 my_error_code = 0;
ViInt32* error_code = &my_error_code;
ViUInt16 stb;
ViUInt16 VNA_ERROR = 4; //This means there is an error
ViUInt16 VNA_ERROR_MSG = 16; //This means there is a message in the error buffer(4+16)
if (status >= 0)
viReadSTB (session, &stb);
//check if stb & VNA_ERROR is set
if (status < VI_SUCCESS | | (((stb & VNA_ERROR) > 0) && ((stb & VNA_ERROR_MSG) > 0)))
{
au464x_writeInstrData (session, ":SYST:ERR?");
viRead (session, (ViPBuf)error_message, 256, &read_count);
SetWaitCursor (0);
sprintf (error_buffer, "Instrument Error: %s\n", error_message);
printf ("%s\n", error_buffer);
au464x_writeInstrData (session, "*CLS");
}
return status;
}
 
 
 
Figure 31─We print out the data into a 3 column format: frequency (Hz), Log Mag, Phase.