LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Power spectral density measurement in CVI with GPIB and Agilent N9020A Signal Analyzer

I'm trying to measure power spectral density (PSD - dBm/Hz) in CVI through GPIB with the Agilent N9020A spectrum analyzer and have my GUI display its value in a numeric box.  On my GUI, a "Get PSD" button calls the CVI callback GetPSDCallback (code below) which then calls the function AnalyzerGetDensity (code below).  AnalyzerGetDensity then tells the N9020A to measure PSD, return its value, and store that value in a numeric box on the GUI panel with variable name PRESENTP.

 

When I run the program I get a "QUERY INTERRUPTED" error on the N9020A display and the PSD value isn't recorded. Could someone tell me why this is happening and how I can fix it to make my program work?

 

Thanks for your help.

 

===CVI Callback: ====

 

int CVICALLBACK GetPSDCallback (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event)
    {
        case EVENT_COMMIT:     
        AnalyzerGetDensity(panel);
            break;
    }
    return 0;
}

 

=== PSD Measurement Function: ===

 

float AnalyzerGetDensity (int panel)         

{                                              
    char *stringinput;
    float *floatoutput;
    
    stringinput = (char *)calloc(sizeof(char),256);
    floatoutput = (float *)malloc(sizeof(float)*2);
    strcpy(stringinput,":INIT:CHP;");   
    ibwrt(N9020A, stringinput, strlen(stringinput));
    strcpy(stringinput,":FETC:CHP:DENS?;");             
    ibwrt(N9020A, stringinput, strlen(stringinput));
    ibrd(N9020A, floatoutput, sizeof(floatoutput));;    
    free(stringinput);
    
    SetCtrlVal (panel, PANEL_PRESENTP, *floatoutput);
    return *floatoutput;    
}

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

Without knowing (and without GPIB and scope at home) just few guesses:

- the device might expect the command string including the terminating null character - you might try ibwrt(N9020A, stringinput, strlen(stringinput)+1);

- the device might expect a linefeed with EOI as terminator - you would need to properly configure the GPIB so it sends a linefeed automatically (the same for listening)

- the device might be busy with a previous command - make sure the device is read before sending a new query / command

- the device might need more time, so possibly insert a delay between ibwrt and ibrd

- GPIB might suffer from a timeout, so possibly increase the timeout value

0 Kudos
Message 2 of 4
(4,424 Views)

Two other things:

For a new program I would prefer the VISA libraries to talk with the instrument instead of plain GPIB.  With VISA you can also use the analyzers network- or USB-interface  for remote control by only changing one argument in viOpen(). 

 

You are expecting, that the analyzer returns a binary float as result. I haven't checked in the manual  but I would expect returns a string containing the floating point number and you have to convert the result with sscanf to binary format. And since sizeof(Float *) is either 4 (32bits) or 8 ( 64 bits) chars long you aren't  reading enough characters for reading the complete result.

 

If you need example code you could look into one of the existing instrument drivers for that device. Or even build your code onto that driver.

 

 

 

 

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

@mkossmann wrote:

Two other things:

For a new program I would prefer the VISA libraries to talk with the instrument instead of plain GPIB.


That's definitely a very good idea.

 

Another: you can use the test panel of NI-MAX to test your communication. This is a quick test to check connection and command syntax; once your NI-MAX test panel commands are understood by your instrument you can take the next step and put them in a C program.

 

May be this is also useful.

0 Kudos
Message 4 of 4
(4,387 Views)