Matlab connection through oscilloscope
Ältere Kommentare anzeigen
Hi,
I just trying to connect my oscilloscope with my matlab using this code via usb port but it is not working matlab recognises the device but won't execute the code below;
% Find a VISA-USB object.
os = instrfind('Type', 'visa-usb', 'RsrcName', 'USB0::0x0957::0x17A2::MY53510244::0::INSTR', 'Tag', '');
% Create the VISA-USB object if it does not exist
% otherwise use the object that was found.
if isempty(os)
os = visa('KEYSIGHT', 'USB0::0x0957::0x17A2::MY53510244::0::INSTR');
else
fclose(os);
os = os(1);
end
% Connect to instrument object, obj1.
fopen(os);
fprintf(os,'*RST');
fprintf(os,'SELECT:CONTROL CH');
Any suggestions or help maybe ?
Thank you.
13 Kommentare
Walter Roberson
am 24 Mai 2021
is there an error message?
Batuhan Istanbullu
am 24 Mai 2021
Walter Roberson
am 24 Mai 2021
The code you posted does not read or attempt to graph.
Batuhan Istanbullu
am 25 Mai 2021
Walter Roberson
am 25 Mai 2021
Is the issue showing up on the line
temppk2pk= fscanf(os,'%f'); %Read p2p value of the output signal. (1V per 100mm/s)
are you being told that no data is available?
I recommend using fgetl(os) and assigning to a variable, and examining what is in the variable, in case you fell out of synchronization. You can sscanf() a string that does turn out to be numeric in form.
Batuhan Istanbullu
am 25 Mai 2021
Batuhan Istanbullu
am 25 Mai 2021
Walter Roberson
am 26 Mai 2021
Bearbeitet: Walter Roberson
am 26 Mai 2021
success = false;
temp = fgets(os);
if isempty(temp)
%timed out, do something appropriate
else
temp = strtrim(temp);
if ~ismember(temp(1), ['0':'9', '+', '-'])
%response started with something that was not numeric
fprintf('Response not numeric, was: "%s"\n', temp);
else
temp2 = sscanf(temp, '%f');
if isempty(temp2)
fprintf('Response looked numeric at first, but was not. Was "%s"\n', temp);
elseif length(temp2) > 1
fprintf('Got %d numbers when only expected one. Ignoring rest. Response was "%s"\n', length(temp2), temp);
temp2 = temp2(1);
success = true;
else
success = true;
end
end
end
if success
temppk2pk(j) = temp2;
end
Batuhan Istanbullu
am 26 Mai 2021
Batuhan Istanbullu
am 27 Mai 2021
Bearbeitet: Walter Roberson
am 27 Mai 2021
Batuhan Istanbullu
am 27 Mai 2021
Walter Roberson
am 27 Mai 2021
I do not know.
If you are using National Instruments (NI) Visa drivers, then you might be able to trace I/O; see https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YHdrCAG&l=en-CA
Batuhan Istanbullu
am 28 Mai 2021
Antworten (0)
Kategorien
Mehr zu Oscilloscopes finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!