Use fscanf to Read Binary Data from Keysight Power Analyzer with Unknown Length
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Christopher Saltonstall
le 10 Nov 2021
Réponse apportée : Christopher Saltonstall
le 18 Nov 2021
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);
0 commentaires
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 10 Nov 2021
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 commentaire
Christopher Saltonstall
le 10 Nov 2021
Modifié(e) : Christopher Saltonstall
le 10 Nov 2021
Voir également
Catégories
En savoir plus sur Application Deployment dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!