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!