VectorStar™ MS4640A SeriesMicrowave Vector Network Analyzer : Appendix B — Programming with LabWindows/CVI : Example 8 – Output BMP File
 
Example 8 – Output BMP File
We can use a similar technique to get the bitmap data to a file. Here we use the Lightning commands “BMPC;OBMP” to output a bitmap file. BMPC selects color on white as the color scheme – this makes for better printouts. The au464x_readArbitraryBlock() function again is used to strip off the arbitrary block header and place the bitmap data into a file. If we didn’t strip off the header the bitmap file would be corrupt. The code snippet is below.
 
//==============================================================================
//
// Title: Example 8
// Purpose: Output BMP 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;
static ViChar readBuffer[600000];
CHECKERR(au464x_init ("VectorStar_Test", VI_FALSE, VI_TRUE, &session));
CHECKERR(au464x_writeInstrData(session,"LANG NATIVE"));
CHECKERR(au464x_writeInstrData(session,"BMPC;OBMP"));
CHECKERR(au464x_readArbitraryBlock(session, readBuffer, 1, 600000, VI_TRUE, &retCount));
au464x_close(session);
fileHandle = OpenFile (".\\dave.bmp", 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 8 – Trace Display Output Saved as a BMP File
When the VI runs it puts up a dialog to allow the user to select a file name. Make sure to save the file with a “.bmp” extension.