Matlab connection through oscilloscope
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 24 Mag 2021
is there an error message?
Batuhan Istanbullu
il 24 Mag 2021
Walter Roberson
il 24 Mag 2021
The code you posted does not read or attempt to graph.
Batuhan Istanbullu
il 25 Mag 2021
Walter Roberson
il 25 Mag 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
il 25 Mag 2021
Batuhan Istanbullu
il 25 Mag 2021
Walter Roberson
il 26 Mag 2021
Modificato: Walter Roberson
il 26 Mag 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
il 26 Mag 2021
Batuhan Istanbullu
il 27 Mag 2021
Modificato: Walter Roberson
il 27 Mag 2021
Batuhan Istanbullu
il 27 Mag 2021
Walter Roberson
il 27 Mag 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
il 28 Mag 2021
Risposte (0)
Categorie
Scopri di più su Oscilloscopes in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!