VectorStar™ MS4640A SeriesMicrowave Vector Network Analyzer : Appendix B — Programming with LabWindows/CVI : Example 7 – Output S2P File
 
Example 7 – Output S2P File
This is a good example that uses some au464x_writeInstrData() calls to accomplish some useful things. Specifically, we are going to send some Native VectorStar commands along with some Lightning commands to output an S2P file from the VNA to the PC. The code snippet is below.
 
//==============================================================================
//
// Title: Example 7
// Purpose: Output S2P file
//
// 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;
int fileHandle;
ViChar readBuffer[100000];
CHECKERR(au464x_init ("VectorStar_Test", VI_FALSE, VI_TRUE, &session));
CHECKERR(au464x_writeInstrData(session,"LANG NATIVE"));
CHECKERR(au464x_writeInstrData(session,":SENSE:SWEEP:POINTS 25"));
CHECKERR(au464x_writeInstrData(session,":FORM:SNP:FREQ HZ"));
CHECKERR(au464x_writeInstrData(session,":FORM:SNP:PAR REIM"));
CHECKERR(au464x_writeInstrData(session,"TRS;WFS;OS2P"));
CHECKERR(au464x_readArbitraryBlock(session, readBuffer, 1, 100000, VI_TRUE,
&retCount));
au464x_close(session);
fileHandle = OpenFile (".\\dave.s2p", VAL_WRITE_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);
WriteFile (fileHandle, readBuffer, retCount);
CloseFile (fileHandle);
 
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;
}
 
 
Example 7 – S2P Output File
Transfer of an S2P file to the PC.