Matlab connection through oscilloscope
古いコメントを表示
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 件のコメント
Walter Roberson
2021 年 5 月 24 日
is there an error message?
Batuhan Istanbullu
2021 年 5 月 24 日
Walter Roberson
2021 年 5 月 24 日
The code you posted does not read or attempt to graph.
Batuhan Istanbullu
2021 年 5 月 25 日
Walter Roberson
2021 年 5 月 25 日
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
2021 年 5 月 25 日
Batuhan Istanbullu
2021 年 5 月 25 日
Walter Roberson
2021 年 5 月 26 日
編集済み: Walter Roberson
2021 年 5 月 26 日
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
2021 年 5 月 26 日
Batuhan Istanbullu
2021 年 5 月 27 日
編集済み: Walter Roberson
2021 年 5 月 27 日
Batuhan Istanbullu
2021 年 5 月 27 日
Walter Roberson
2021 年 5 月 27 日
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
2021 年 5 月 28 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Oscilloscopes についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!