Thanks for the help, we have written the program and it works well. I include the core part (in C) below for anyone who might need something similar. Depending on the required BW/span/precision the speed is varying, for our application the fastest we can do is about 1 point/7 ms (without tracking the signal).
/*********************************************************************
- Program to perform a sweep and return the frequency and amplitude of the max, and track the signal
- 1. Perform a sweep
- 2. Write freq and amp of max into a file
- 3. Set centre frequency to freq of max
- Go to 1.
- 12/09/2012
**********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "visa.h"
#include <sys/timeb.h>
void main ()
{
/*program variables*/
ViSession defaultRM, viMXA;
ViStatus viStatus = 0;
double dMaxA = 0, dMaxf = 0, cfreq, BW, span, swetim;
int Nscan, i, swepoin;
struct timeb tmb;
int starts, startm, stops, stopm, tdiff, datatim;
char swetyp
10;
FILE *out;
/*open session to GPIB device at address 18 */
viStatus=viOpenDefaultRM (&defaultRM);
/* viStatus=viOpen (defaultRM, "GPIB0::18::INSTR", VI_NULL,VI_NULL,&viMXA); */
viStatus=viOpen (defaultRM, "TCPIP0::169.254.65.165::inst0::INSTR", VI_NULL,VI_NULL,&viMXA);
/*check opening session sucess*/
if(viStatus)
{
printf("Could not open a session!\n");
exit(0);
}
/*increase timeout to 60 sec*/
viSetAttribute(viMXA,VI_ATTR_TMO_VALUE,60000);
/*Clear the analyzer*/
viClear(viMXA);
/*Clear all event registers*/
viPrintf(viMXA, "*CLS\n");
/*Stop continuous sweep*/
viPrintf(viMXA, "INIT:CONT OFF\n");
/*Ask for number of scans*/
printf("Number of scans?\t");
scanf("%d", &Nscan);
/*open output file*/
out = fopen("output.txt","a");
/*Get and print system parameters*/
viQueryf(viMXA, "FREQ:CENT?\n", "%lf", &cfreq);
viQueryf(viMXA, "FREQ:SPAN?\n", "%lf", &span);
viQueryf(viMXA, "BAND?\n", "%lf", &BW);
viQueryf(viMXA, "SWEep:TIME?\n", "%lf", &swetim);
viQueryf(viMXA, "SWE:POIN?\n", "%ld", &swepoin);
viQueryf(viMXA, "SWE:TYPE?\n", "%s", &swetyp);
ftime(&tmb);
datatim = tmb.time;
fprintf(out, "Date (s): %ld\nCenter frequency (Hz): %lf\nSpan (Hz): %lf\nBandwidth (Hz): %lf\nSweep Time (s) %lf\nSweep Points: %ld\nSweep Type: %s\n"
, datatim, cfreq, span, BW, swetim, swepoin, swetyp);
/*Display Off*/
viPrintf(viMXA, "DISP:ENAB OFF\n");
/*Get start time*/
ftime(&tmb);
starts = tmb.time;
startm = tmb.millitm;
/*Loop of scans*/
for(i=1; i <= Nscan; i=i+1)
{
/* Initiate a sweep and wait for it to complete*/
viPrintf(viMXA, "INIT:IMM;*WAI\n");
/* Do a peak search */
viPrintf(viMXA, "CALC:MARK1:MAX\n");
/* Save frequency and amplitude of Mark1 into variables */
viQueryf(viMXA, "CALC:MARK1:Y?\n", "%lf", &dMaxA);
viQueryf(viMXA, "CALC:MARK1:X?\n", "%lf", &dMaxf);
/* Write the freq and amplitude at Marker 1*/
fprintf(out, "%lf\t %lf\n", dMaxf, dMaxA);
//printf("%lf\t %lf\n", dMaxf, dMaxA);
/* Center the display, only required if you need to track the signal*/
viPrintf(viMXA, "FREQ:CENT %lf Hz\n", dMaxf);
}
/*Get stop time, calculate time it took*/
ftime(&tmb);
stops = tmb.time;
stopm = tmb.millitm;
tdiff = (stops-starts)*1000 + (stopm - startm);
printf("timediff = %ld (milliseconds)\n", tdiff);
/*close output file*/
fclose(out);
/*Display On*/
viPrintf(viMXA, "DISP:ENAB ON\n");
viPrintf(viMXA, "INIT:CONT ON\n");
/* Close session */
viClose (viMXA);
viClose (defaultRM);
}