VectorStar™ MS4640A SeriesMicrowave Vector Network Analyzer : Appendix B — Programming with LabWindows/CVI : Example 2 – Sending the *IDN? Command and Dsplaying results
 
Example 2 – Sending the *IDN? Command and Dsplaying results
The previous example used only driver functions to get some information from the VNA. The GPIB command, “*IDN?” returns the Manufacturer, Model #, Serial Number and Firmware Version. We used this command previously in Figure: Using WGPIB with *IDN? Command above using the WGPIB utility. In this example we directly issue the “*IDN?” command and then parse the different parts of the response string. The code snippet is below.
 
//==============================================================================
//
// Title: Example 2
// Purpose: Sending the *IDN? command and displaying results
//
// 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 "au464x.h"
 
ViSession session;
ViStatus checkErr (ViStatus status);
#define CHECKERR(fCal) \
if (au464x_status = checkErr((fCal)), au464x_status < VI_SUCCESS) \
goto Error; else
// We’ll use this CHECKERR Macro above in all the examples from now on.
// It provides a convenient way to check every function for an error.
 
int main (int argc, char *argv[])
{
ViStatus status;
ViUInt32 read_count;
ViStatus au464x_status = VI_SUCCESS;
ViChar l_buffer[50];
ViChar* p2Manf = NULL;
ViChar* p2Model = NULL;
ViChar* p2Ser = NULL;
ViChar* p2Firm = NULL;
 
printf("Example 1: Using the *IDN? Query\n\n");
CHECKERR(au464x_init ("VectorStar_Test", VI_TRUE, VI_FALSE, &session));
CHECKERR(au464x_writeInstrData (session, "*IDN?"));
CHECKERR(viRead (session, (ViPBuf)l_buffer, 50, &read_count));
l_buffer[49] = '\0';
au464x_close(session);
p2Manf = strtok(l_buffer, ",");
p2Model = strtok(NULL, ",");
p2Ser = strtok(NULL, ",");
p2Firm = strtok(NULL, "\n");
// We use au464x_writeInstrData() above to directly send a GPIB command.
// Then we use viRead() to read the results.
 
printf("Manufacturer: %s\nModel: %s\nSer#: %s\nFirmware: %s\n",
p2Manf,p2Model,p2Ser,p2Firm);
printf("\n\nHit return to exit:");
getc(stdin);
return 0;
Error:
printf("\n\nDetected an Error--Hit return to exit:");
getc(stdin);
return 0;
}
 
 
ViStatus checkErr (ViStatus status)
// The checkErr() function is called from the MACRO code.
// We check the status of the driver function and report any errors.
 
{
ViChar error_message [256];
ViChar error_buffer [1024];
if (status < VI_SUCCESS)
{
au464x_errorMessage (session, status, error_message);
sprintf (error_buffer, "Primary Error: 0x%08X, %s\n", status, error_message);
MessagePopup ("Error", error_buffer);
au464x_errorQuery (session, error_code, error_message);
SetWaitCursor (0);
sprintf (error_buffer, "Instrument Error: %s\n", error_message);
MessagePopup ("Error", error_buffer);
au464x_close(session);
session = 0;
}
return status;
}
 
Example 2 – au464x_writeInstrData() and *IDN? – Output
Output from Example 2. We use the au464x_ writeInstrData() function to directly send GPIB commands. We then use the VISA function viRead() to read the results.