Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

i have

I have a E4440a spectrum analyzer. I am trying to take a screen shot of the instrument and save it to a file in my program using a GPIB connection. This program allows me to do a *IDN? query and save it to a file on the C drive in a .txt file. I am trying to do this for my screen shot save it to the instrument flash drive  MMEM:STOR:SCR 'C:\logfile.GIF' and retrieving it  MMEM:DATA? 'C:\logfile.GIF'  but this is not working in my program below. All the highlights in Bold was the changes i made in the original program from .txt to GIF

 

 

 

#include <stdio.h>
#include <string.h>
#include <visa.h>
#include <stdarg.h>
// This example opens a specific GPIB device, sets the data start
// and stop locations and logs the command sent to c:\logfile.txt
int main(int argc, char* argv[])
{
ViSession rm = VI_NULL, vi = VI_NULL;
ViStatus status;
ViChar buffer[256];
ViUInt32 retCnt;

 


const long start = 1;
const long stop = 500;
FILE* log = fopen("C:\\logfile.GIF", "w");
// Open a default Session
status = viOpenDefaultRM(&rm);
if (status < VI_SUCCESS) goto error;
// Open the gpib device at primary address 1, gpib board 8
status = viOpen(rm, "GPIB0::16::INSTR", VI_NULL, VI_NULL,&vi);


if (status < VI_SUCCESS) goto error;
 
 status = viWrite(vi, (ViBuf) "*idn?'C:\\logfile.GIF'",5,&retCnt);
//  status = viWrite(vi, (ViBuf) "MMEM:STOR:SCR 'C:\\logfile.GIF'",5,&retCnt);

// status = viRead(vi, (ViBuf) "*MMEM:DATA? 'C:\\logfile.txt'",5,&retCnt);

// ViStatus viReadToFile (ViSession vi, ViString logfile, ViUInt32 count, ViUInt32 retCount);

 status = viSPrintf(vi, (ViBuf) buffer, "data:start %d;data:stop %d", start, stop);
 
 memset(buffer, 0, sizeof(buffer));
 status = viRead(vi, (ViBuf) buffer, sizeof(buffer), &retCnt);

 if (status < VI_SUCCESS) goto error;

if (log != NULL)
fprintf(log, "%s’n", buffer);
status = viWrite(vi, (ViBuf) buffer, strlen(buffer),
VI_NULL);
if (status < VI_SUCCESS) goto error;
// Clean up
if (log != NULL)
fclose(log);
viClose(vi); // Not needed, but makes things a bit more
// understandable
viClose(rm);
return 0;
error:
// Report error and clean up
viStatusDesc(vi, status, buffer);
fprintf(stderr, "failure: %s\n", buffer);
if (rm != VI_NULL) {   
viClose(rm);
}
return 1;
}

0 Kudos
Message 1 of 4
(4,608 Views)

Hi *E*

 

I would give these commands a try instead:

 

Store the current screen image on flash as C: PICTURE.GIF

status = viVPrintf(vi, ":MMEM:STOR:SCR ’C: PICTURE.GIF’" + Chr$(10), 0)If (status < 0) Then GoTo VisaErrorHandler 

 

Grab the screen image file from the instrument

status = viVQueryf(vi, ":MMEM: DATA? ’C: PICTURE.GIF’" + Chr$(10), _"%#y", ArrayPtr(0))  

 

Delete the tempory file on the flash named C: PICTURE.GIF

status = viVPrintf(vi, ":MMEM: DEL ’C: PICTURE.GIF’" + Chr$(10), 0)If (status < 0) Then GoTo VisaErrorHandler

 

I found them in the following manual for the E4440A:

 

http://cp.literature.agilent.com/litweb/pdf/E4401-90482.pdf

 

 

Message Edited by Ryan T on 04-09-2010 05:00 PM
Message Edited by Ryan T on 04-09-2010 05:00 PM
Ryan T
National Instruments
Applications Engineer
0 Kudos
Message 2 of 4
(4,574 Views)

Thanks Ryan I tried the code but i still wasnt able to get it to work I looked in the manual and i was trying to find were exactly in the manual did you find that example? below is the code and my errors.

 

 

 

 


#include <stdio.h>
#include <string.h>
#include <visa.h>
#include <stdarg.h>
// This example opens a specific GPIB device, sets the data start
// and stop locations and logs the command sent to c:\logfile.txt
int main(int argc, char* argv[])
{
ViSession rm = VI_NULL, vi = VI_NULL;
ViStatus status;
ViChar buffer[256];
ViUInt32 retCnt;
//char Chr$;

 


const long start = 1;
const long stop = 500;
FILE* log = fopen("C:\\logfile.txt", "w");
// Open a default Session
status = viOpenDefaultRM(&rm);
if (status < VI_SUCCESS) goto error;
// Open the gpib device at primary address 1, gpib board 8
status = viOpen(rm, "GPIB0::16::INSTR", VI_NULL, VI_NULL,&vi);


if (status < VI_SUCCESS) goto error;
 
 status = viWrite(vi, (ViBuf) "*idn?'C:\\PICTURE.gif'",5,&retCnt);
//  status = viWrite(vi, (ViBuf) "MMEM:STOR:SCR 'C:\\logfile.txt'",5,&retCnt);


 /* Query the instrument for Operation complete */                                          
// viQueryf(vi, (ViBuf) "MMEM:STOR:SCR 'C:\\logfile.txt'",5,&retCnt);
 /* fetch the spectrum trace data*/
// viPrintf(vi, (ViBuf) "MMEM:DATA? 'C:\\logfile.txt'",5,&retCnt);

 


// status = viRead(vi, (ViBuf) "*idn? 'C:\\logfile.txt'",5,&retCnt);

// ViStatus viReadToFile (ViSession vi, ViString logfile, ViUInt32 count, ViUInt32 retCount);

// status = viSPrintf(vi, (ViBuf) buffer, "data:start %d;data:stop %d", start, stop);


//***************************************************
 //Store the current screen image on flash as c: PICTURE.GIF

 status = viVPrintf( vi, ":MMEM:STOR:SCR 'C: PICTURE.GIF' " + Chr$(10),0);
  if(status < 0) goto error;
  if(log!= NULL);

 //Grab the screen image file from the instrument
 status = viVQueryf(vi, ":MMEM: DATA? 'C: PICTURE.GIF'" + Chr$(10), "%#y", ArrayPtr(0));


 //Delete the temporty file on the flast name C: picture.gif
 status = viVPrintf(vi, ":MMEM: DEL 'C: PICTURE.GIF': + Chr$(10), 0));
 if(status < 0) goto error;
//***************************************************

 memset(buffer, 0, sizeof(buffer));
 status = viRead(vi, (ViBuf) buffer, sizeof(buffer), &retCnt);

 if (status < VI_SUCCESS) goto error;

if (log != NULL)
fprintf(log, "%s’n", buffer);
status = viWrite(vi, (ViBuf) buffer, strlen(buffer),
VI_NULL);
if (status < VI_SUCCESS) goto error;
// Clean up
if (log != NULL)
fclose(log);
viClose(vi); // Not needed, but makes things a bit more
// understandable
viClose(rm);
return 0;
error:
// Report error and clean up
viStatusDesc(vi, status, buffer);
fprintf(stderr, "failure: %s\n", buffer);
if (rm != VI_NULL) {   
viClose(rm);
}
return 1;
}

 

 

 

 

 

 : error C2065: 'Chr$' : undeclared identifier
 : warning C4390: ';' : empty controlled statement found; is this the intent?
 : error C2065: 'ArrayPtr' : undeclared identifier
 : error C2001: newline in constant
 : syntax error : missing ')' before 'if'
 : error C2660: 'viVPrintf' : function does not take 2 parameters

 

 

 

 

0 Kudos
Message 3 of 4
(4,548 Views)

Hi *E*

 

The section that includes this code and other related code starts on page 188 in chapter 16 of the following manual:

 

http://cp.literature.agilent.com/litweb/pdf/E4401-90482.pdf

 

Thanks

Ryan T
National Instruments
Applications Engineer
0 Kudos
Message 4 of 4
(4,515 Views)