필터 지우기
필터 지우기

How to output analog signals after analog input voltage exceeds 5V?

조회 수: 2 (최근 30일)
W Joey
W Joey 2015년 7월 18일
편집: W Joey 2015년 7월 18일
Hello everyone, I am currently using the analog input and analog output channels of NI DAQ devices with session-based interface. Now i want to output a pulse for 2 seconds whenever the PC detects a input voltage exceeding 5V, and then input restarts. Here's my code,
si=daq.createSession(ni’);
si.Rate=10;
si.DurationInSeconds=10;
si.addAnalogInputChannel('Dev1','ai0','Voltage');
si.Chennels.InputType='SingleEnded';
lh=addlistener(si.'DataAvailable',@pulseoutput);
si.IsContinuous=true;
si.startBackground();
function pulseoutput(hObject,eventdata)
if any(eventdata.Data>=5.0)
stop(hObject);
s=daq.createSession('ni');
addAnalogOutputChannel(s,'Dev',0,'Voltage');
t=0:0.001:2;
w=4;
outputSignal=rectpuls(t,w)';
queueOutputData(s,outputSignal);
s.startForeground;
rerun();
end
end
function rerun()
si=daq.createSession(ni’);
si.Rate=10;
si.DurationInSeconds=10;
si.addAnalogInputChannel('Dev1','ai0','Voltage');
si.Chennels.InputType='SingleEnded';
lh=addlistener(si.'DataAvailable',@pulseoutput);
si.IsContinuous=true;
si.startBackground();
end
Whenever voltage exceeding 5V is detected, a pulse will be generated successfully, but the analog input will not restart again and error message appears'Timeout expired before operation could complete'. Any suggestions on how to correct the codes? Thank you in advance.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Analog Input and Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by