Acquire Continuous and Background Data Using NI Devices

1 次查看(过去 30 天)
s = daq.createSession('ni');
addAnalogInputChannel(s,'myDAQ1', 0, 'Voltage'); %%OUT2, X-Achse
addAnalogInputChannel(s,'myDAQ1', 1, 'Voltage'); %%OUT1, Y-Achse
s.Rate = 100000
s.DurationInSeconds = 0.001
while 1
[data, time] = s.startForeground;
plot(data(:,1)-2.5,data(:,2)-2.5,'*')
axis([-2.5 2.5 -2.5 2.5])
end
Hello. I´m working on a project with an melexis hallsensorjoistick and an NI myDAQ device. I wants to a quire the valtage and give it back as a dot on a white screen. The code which you see above worked out. But I´ve tryed it befor with Continuous and Background Data and it didnt worked out. I wrote also a code to get data of the 2 outputs with continuous and Background Data, but can´t figure it out how to combine them.
clear all
close all
clc
s = daq.createSession('ni');
addAnalogInputChannel(s,'myDAQ1', 0, 'Voltage');
addAnalogInputChannel(s,'myDAQ1', 1, 'Voltage');
s.Rate = 10000;
s.IsContinuous = true;
lh = addlistener(s,'DataAvailable', @(src,event) plot(event.TimeStamps, event.Data));
s.startBackground();
[data, time] = startForeground(s);
plot(data(:,1)-2.5,data(:,2)-2.5,'*')
axis([-2.5 2.5 -2.5 2.5])
My goal is now to create an GUI with only 2 buttons, start and stop. If I try to combine the codes in one script, I get error messeges like "Error using qwert (line 19) This command can not be used while the Session is running." How can I make this working? Thx

回答(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