Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

PNA - Getting Sweep data

Hi,

I'm an electronics student working for a electronic filters company over the summer programming.

 

I'm currently trying to writing a program in C for the PNA-L N5230C; that will set the start & stop frequency, set the number of sweep points, perform a single sweep and then get the result of sweep.

 

Everything is going well until I want to get the data from the Analyzer, as the text file made that should have the sweep data in doesn't have any.

I've looked Google to try and find a solution but not had much luck. I'm connecting to the analyzer via a USB B.

 

Any help would be much appreciated. Thanks.

 

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <visa.h>

#define PROG    "AgilentTest.c\0"
#define V       "0.02\0"

char pna[26][6] = {
          "pna1", "pna2", "pna3", "pna4", "pna5",
          "pna6", "pna7", "pna8", "pna9", "pna10",
          "pna11", "pna12", "pna13", "pna14", "pna15",
          "pna16", "pna17", "pna18", "pna19", "pna20",
          "pna21", "pna22", "pna23", "pna24", "pna25"
          };

int main( void )
{
    int h1 = 0;
    ViSession defaultRM, vi;
    ViStatus viStatus = 0;
    char buff[256] = {0};
    ViChar _VI_FAR cResult[2000] = {0};
    FILE *fTraceFile;
    static ViChar *cToken;
    int iNum = 0, lCount = 0;
    int iSwpPnts = 401;
    int addr = 0;
    double startF = 1e9, stopF = 5.2e9;
    int count1 = 0;

    /*Welcome statements*/
    printf("\n\nAgilent PNA test program %s %s \n\n", PROG, V);
    printf("----------------------------------------------------\n");
    printf("Do not use for actual measurements\nThis program is for testing\n\n");
    printf("Press any key to connect to an analyzer\n");
    h1 = getch();

    /*Special Skip Statement*/
    if(h1 == 104)
    {
      printf("Please enter an address:\n");
      scanf ("%d",&addr);
      viStatus = viOpenDefaultRM(&defaultRM);
      viStatus = viOpen(defaultRM, pna[addr] ,VI_NULL,VI_NULL, &vi);

      if(viStatus)
      {
        system("CLS");
        printf("Could not make a conection at this addr\n");
        getch();
        exit(1);
      }
        printf("\n\n\n\tSkipping search Connection as addr %d => %s \n\n\n\n",addr, pna[addr]);
        goto exit1;
    }

    /*Loop through ID strings to conect the analyzer*/
    for(addr = 0; addr < 25; addr++)
    {
      printf("addr = %d\n", addr );
      printf("Pna = %s\n", pna[addr] );

      /*Attempt to connect to analyzer*/
      viStatus = viOpenDefaultRM(&defaultRM);
      viStatus = viOpen(defaultRM, pna[addr] ,VI_NULL,VI_NULL, &vi);

      /*check opening session sucess*/
      if(viStatus)
      {
        /*If there are still more ID strings to check reset viStatus*/
        if( addr < 24)
          viStatus = 0;

        /*If all ID strings have been checked*/
        else
        {
  		    system("CLS");
          printf("Could not open a session to the device at any location, last check was at:\n\n\t%s\n\n", pna[addr]);
          printf("Press any key to exit program\n");
          getch();
          viClose(vi);
          viClose(defaultRM);

          /*exit 1 => failure*/
          exit(1);
        }
      }
      else
        goto exit1;
    }

exit1:
      system("CLS");
      /*Turn off automatic sweeps*/
      printf("continuous sweeps are off\n");
      viPrintf(vi, "INIT:CONT OFF \n");

      /*Set up the analyser with values*/
      printf("Setting strat frequancy\n");
      viPrintf(vi, "SENS:FREQ:START %f\n", startF);

      printf("Setting stop frequancy\n");
      viPrintf(vi, "SENS:FREQ:STOP %f\n", stopF);

      printf("Setting the number of points in a sweep\n");
      viPrintf(vi,"SENSe1:SWEep:POIN %d\n", iSwpPnts);

      /*Display Off*/
      /*Should help increase time it takes to complete sweep*/
      viPrintf(vi, "DISP:ENAB OFF\n");

      /*Set analyzer trace data format to ASCII Format*/
      viPrintf(vi,"FORM:DATA ASC \n");

      /*Preform one sweep*/
      printf("Running a single sweep\n");
      viPrintf(vi, "SENS:SWE:MODE SINGle\n*OPC?\n");

      /*Get the data frome trace1*/
      viQueryf(vi,"%s\n", "%#t","TRAC:DATA? TRACE1" , &iNum , cResult);
      cToken  = strtok(cResult,",");

      fTraceFile=fopen("SweepReadings.txt","w");

      while (cToken != NULL)
      {
        lCount++;
        cToken =strtok(NULL,",");
        if (lCount != iSwpPnts)
          fprintf(fTraceFile,"\tAmplitude of point[%d] = %s dBm\n",lCount+1, cToken);
      }

      fprintf(fTraceFile,"\nThe Total trace data points of the spectrum are :[%d] \n\n",lCount);
      fclose(fTraceFile);

      printf("Get data finished, press any key to disconnect from the analyzer\n");
      getch();
      /*Turn the display on, reset the analyzer and close the session*/
      viPrintf(vi, "DISP:ENAB ON\n");
      viPrintf(vi, "INIT:CONT ON\n");
      viPrintf(vi, "*RST\n");
      viPrintf(vi, "HCOPY:FILE PNATempImage.png \n");
      printf("Closing the session\n");
      viClose(vi);
      viClose(defaultRM);

      return 0;
}

 

0 Kudos
Message 1 of 2
(4,171 Views)

Hi Henry, welcome to the NI Discussion Forums,

 

It doesn't look like you're using any NI specific function or hardware, so you may have better luck trying Agilient's support network? Unfortuantely I have little experience with the device you are using but please let us know if you're still having trouble.

Regards,

Ben Clark
0 Kudos
Message 2 of 2
(4,104 Views)