Filter löschen
Filter löschen

visa to visadev issue (visadev not getting all data sent)

7 Ansichten (letzte 30 Tage)
Scott
Scott am 8 Jun. 2022
Beantwortet: Scott am 30 Jun. 2022
Grabbing data from a R&S ZNB network analyzer. I have code that works well for grabbing data when the netan is defined as a visa object, however, when trying to rewrite as a visadev object, I cannot grab all of the trace data. I realize a lot of the formatting data, etc, can be done a lot cleaner, forgive me for that right now (wrote this function a LONG time ago).
Function that works (visa object):
function data_to_save = rhode_netan_save_trace_data(ip_addr, channel, trace_name, file_name)
%rhode_netan_save_trace_data('192.168.10.103',2,'Trc2','clever_name_for_file');
dev_name = [ 'TCPIP::' ip_addr '::INSTR'];
netan = visa('ni', dev_name);
netan.InputBufferSize = 1000000;
fopen(netan);
fprintf(netan,'sense:sweep:step?');
freq_step = str2num(fscanf(netan));
fprintf(netan,'sense:freq:start?');
start_freq = str2num(fscanf(netan));
fprintf(netan,'sense:freq:stop?');
stop_freq = str2num(fscanf(netan));
fprintf(netan,'sense:sweep:step?');
freq_step = str2num(fscanf(netan));
freqs = transpose(start_freq:freq_step:stop_freq);
command = [ 'calc' num2str(channel) ':parameter:select ' '''' trace_name ''''];
fprintf(netan,command);
%formatted data
fprintf(netan,':form:dexp:sour fdat');
%get data from the selected trace
%fprintf(netan,'trac? ch1data');
fprintf(netan,['trac? ch' num2str(channel) 'data']);
raw_data = fscanf(netan);
formatted_dB_only_data = sscanf(blah, '%f,');
fclose(netan);
raw_data in the above function returns as a 1x22248 char. formatted_dB_only_data is a 1601x1 double (which is what I expect as I have the network analyzer set to 1601 points).
Now, let's try this with the netan as a visadev object:
function data_to_save = rhode_netan_save_trace_data(ip_addr, channel, trace_name, file_name)
%rhode_netan_save_trace_data('192.168.10.103',2,'Trc2','clever_name_for_file');
dev_name = [ 'TCPIP::' ip_addr '::hislip0'];
netan = visadev(dev_name);
% configureTerminator(netan,"LF")
freq_step = str2double(writeread(netan, "sense:sweep:step?"));
start_freq = str2double(writeread(netan, "sense:freq:start?"));
stop_freq = str2double(writeread(netan, "sense:freq:stop?"));
freqs = transpose(start_freq:freq_step:stop_freq);
%select the trace you want to grab data from
command = [ 'calc' num2str(channel) ':parameter:select ' '''' trace_name ''''];
writeline(netan, command);
%formatted data
writeline(netan, ":form:dexp:sour fdat");
%get data from the selected trace
data = writeread(netan, ['trac? ch' num2str(channel) 'data']);
% write(netan, ['trac? ch' num2str(channel) 'data']);
% data = read(netan, 1601, "double");
formatted_dB_only_data = str2double(strsplit(data,','));
When using 'writeread' to populate data, it comes back as a string of length (according to strlength(data)) 10898. If I run that command a second time, it comes back with garbage binary data of strlength() == 7, and every time I run it (breakpoint set at 'data = ...'), it will keep returning garbage data of various length. I should also note that if I stop the script and run again, the size of data according to strlength() changes every time (3 runs come back with a strlength of 22247, 22224, and 5355). Obviously this should be returning trace data for 1601 points every time. If I use the write and then read (1601, "double"), I do get a 1x1601 matrix back, but the data is garbage (6.22e-38, 6.54e-43).
Anyone have any thoughts on this? I was really hoping that converting a lot of my functions from visa objects to visadev objects would be more trivial, but I suppose as long as I understand how this works in this example, I can figure it out for other scripts / devices.
Thanks.
  2 Kommentare
Andrei
Andrei am 14 Jun. 2022
What MATLAB release are you using? A number of issues with visadev were resolved in MATLAB R2022a. If you are not able to upgrade to this release, contact MathWorks technical support for a workaround.
Scott
Scott am 14 Jun. 2022
R2022a.
I should note, as shown in the code above, I am not doing "periodic polling" of the instrument that could interupt a concurrent data transfer as mentioned in that bug report. I am simply trying to do reads once I issue a command.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Scott
Scott am 30 Jun. 2022
Closing the loop on this:
It seems the bug mentioned by @Andrei Ursache was a good working theory, however this bug was not resolved in the original release of MATLAB R2022a, it was fixed in R2022a_Update_3. After filing a service ticket, I was instructed to download update_3 manually since it is not officially released as of the writing of this post. This is the process to download and install the update. Once I ran the update, MATLAB sucessfully grabbed all of the data from the ZNB.

Weitere Antworten (0)

Produkte


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by