My project is used to continuously save three GIF pictures from a spectrum analyzer. I can't save the sencond pictures and I am confused. Can anybody help me to figure it out? The relavant files are in the accessory.
my codes are as follows:
#include <windows.h>
#include <utility.h>
#include <ansi_c.h>
#include <visa.h>
#include <formatio.h>
#include <cvirte.h>
int hDefaultRM;
int hSpectrumInstr;
int status;
char *ptr;
int SaveSpectrumAnalyzerScreen(int hInstru, char * fileName)
{
ViInt32 totalPoints;
ViInt8 picArray[50000] = {0};
int hFile;
viPrintf(hInstru, "*OPC\n");
viSetAttribute (hInstru, VI_ATTR_TMO_VALUE, 6*1000000); //设置VISA的属性(延迟时间)
viPrintf(hInstru, ":MMEMTOR
CR 'C
ICTURE.GIF'\n");
viQueryf(hInstru, ":MMEMATA? 'C
ICTURE.GIF'\n", "%#b", &totalPoints, picArray);
viQueryf(hInstru, ":MMEMATA? 'C
ICTURE.GIF'\n", "%#y", &totalPoints, picArray);
// viPrintf(hInstru, ":MMEMATA? 'C
ICTURE.GIF'\n");
// viScanf (hInstru, "%#b", picArray);
viPrintf(hInstru, ":MMEMEL 'C
ICTURE.GIF'\n");
hFile = OpenFile (fileName, VAL_READ_WRITE, VAL_TRUNCATE, VAL_BINARY);
WriteFile (hFile, picArray, 50000);
CloseFile (hFile);
Sleep(1000);
return 0;
}
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
status = viOpenDefaultRM(&hDefaultRM);
status = viOpen (hDefaultRM, "GPIB0::11::INSTR", VI_NULL, VI_NULL, &hSpectrumInstr);
SaveSpectrumAnalyzerScreen(hSpectrumInstr, "C:\\Users\\Administrator.LC-PC\\Desktop\\pic\\01.gif");
SaveSpectrumAnalyzerScreen(hSpectrumInstr, "C:\\Users\\Administrator.LC-PC\\Desktop\\pic\\02.gif");
SaveSpectrumAnalyzerScreen(hSpectrumInstr, "C:\\Users\\Administrator.LC-PC\\Desktop\\pic\\03.gif");
viClose(hDefaultRM);
CloseCVIRTE ();
return 0;
}
Error1:
The first time to save picture from the spectrum analyzer it surely saved the correct picture in the specified folder. But the second time to save picture the program stoped at the line “viQueryf(hInstru, ":MMEMATA? 'C
ICTURE.GIF'\n", "%#b", &totalPoints, picArray); “ and for a long time it did not response. When NI I/O Trace was applied to the program, the second viQueryf was interpreted directly to viRead without viWrite. It must be wrong but how this error happene?
Error 2:
When I replace viQueryf with viPrintf and viScanf it can get the first picture correctly, but the second time to save picture viScanf got wrong content, the content in viScanf buffer is not like the correct one. but NI I/O Trace didn’t have any wrong.