フィルターのクリア

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 Center および File ExchangeAnalog Input and Output についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by