Use fscanf to Read Binary Data from Keysight Power Analyzer with Unknown Length
Show older comments
I am communicating with a Keysight N6705C Power analyzer and trying to read data from a buffer that is continuously collecting data. I use SCPI commands to query the buffer and fscanf to read the response. Currently, the analyzer is set to respond with the ASCII format. Therefore, the response is an character string of values of unknown length which I have to split and convert to doubles. The code used for this is shown below.
However, reading ASCII values is 4x slower than reading binary data. But if I set the output of the analyzer to binary it returns a string of binary data that looks like gibberish which I am having trouble converting to doubles. See attached file. The manual say that "Data is returned in binary IEEE single precision floating point". This data should be a sinusoidal curve.
How do I convert this binary/char string into an array of doubles?'
Alternatively, how do I read this data from the analyzer directly into double format?
%% ASCII Method
%query analyzer buffer and receive a response of upto 10000 values
fprintf(visaObj, 'FETC:ELOG? 10000,(@1)');
%read response
data_temp = fscanf(visaObj);
%split resulting char string at commas
datasplit = strsplit(data_temp,',');
%convert char array to double array
data_num = str2double(datasplit);
Accepted Answer
More Answers (1)
Walter Roberson
on 10 Nov 2021
0 votes
Your .mat file contains 38 bytes of char. uint8() the char and take the first 36 bytes (need a multiple of 4). uint8() that, and typecast() the result to 'single'; the swapbytes() the result.
The values are then in the range of 1.47 .
[though at the moment, I am not confident that the very first output is correct.)
1 Comment
Christopher Saltonstall
on 10 Nov 2021
Edited: Christopher Saltonstall
on 10 Nov 2021
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!