Hello All,

I am trying to get trace data from PNA using C# (Agilent visa32+SCPI)

My question is how to get complex data (including both real and imaginary part)? I made below codes and only receives real part.

/*io.Write()

{

command += "\n";

viError = visa32.viPrintf(session, command);

}*/

io.Write("CALCulate:PARameter:SELect 'Meas1'");

io.Write("calculate:format smith");

io.Write("format:data REAL,32");

io.Write("CALCulate:DATA? SDATA");

float[] data=new float[nop];);//int nop = number of points

/*---The following line saves trace data to a float array--*/

//if section =1; I get real part

//if section =0; I get ana array of all zeros

//Question:

//How to set section=?

//How to get both real and imaginary part?

viError = visa32.viScanf(section, "%#zb",ref nop, data);

Appreciate for any ideas!

Regards,

lgfcs

I am trying to get trace data from PNA using C# (Agilent visa32+SCPI)

My question is how to get complex data (including both real and imaginary part)? I made below codes and only receives real part.

/*io.Write()

{

command += "\n";

viError = visa32.viPrintf(session, command);

}*/

io.Write("CALCulate:PARameter:SELect 'Meas1'");

io.Write("calculate:format smith");

io.Write("format:data REAL,32");

io.Write("CALCulate:DATA? SDATA");

float[] data=new float[nop];);//int nop = number of points

/*---The following line saves trace data to a float array--*/

//if section =1; I get real part

//if section =0; I get ana array of all zeros

//Question:

//How to set section=?

//How to get both real and imaginary part?

viError = visa32.viScanf(section, "%#zb",ref nop, data);

Appreciate for any ideas!

Regards,

lgfcs

First read back the header which will be in the form of "#A43210";

The first two bytes, should be #A;

Then read back an 8 bit int which represents the number of digits to read back in the third command. In this case 4, which means that a 4 digit number, one byte at a time comes next.

Read the 4 bit number, "3210" a byte at a time, and you have the size of the binary read that follows.

Read the binary file, and the data will be the number of points, times 2, times 8 bytes, the data returns in 32 bits real, 32 bits imaginary, etc.

Finally read the end of file char. Now you read everything.

In seems in your code, you need to change the to read NOP*2, and remember to read the the header. If you do it as I say above, you don't need to know the NOP because the header tells you how many bytes to read. And remember the data is returned in the form of [Re1, Im1, Re2, Im2, ... ReN, ImN]

The data will be in the form of Re + jIm, so if you want mag data, you will have to compute it yourself.