Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
W Joey
W Joey le 18 Juil 2015
Modifié(e) : W Joey le 18 Juil 2015
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.

Réponses (0)

Catégories

En savoir plus sur Analog Input and Output dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by