Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
W Joey
W Joey el 18 de Jul. de 2015
Editada: W Joey el 18 de Jul. de 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.

Respuestas (0)

Categorías

Más información sobre Analog Input and Output en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by