Example: capture analog streams with NationInstrument DAQ from MATLAB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [] = main() | |
close all; | |
% Make sure: | |
disp('Searching devices...'); | |
devs=daq.getDevices(); | |
if (length(devs.Vendor)~=1), | |
error('Is the USB DAQ connected?'); | |
end | |
dev=devs(1); | |
fprintf('Connected to: %s\n', dev.Description); | |
% Create session: | |
s = daq.createSession ('ni'); | |
[ch1,idx1] = s.addAnalogInputChannel(dev.ID, 'ai1', 'Voltage'); | |
[ch2,idx2] = s.addAnalogInputChannel(dev.ID, 'ai9', 'Voltage'); | |
ch1.TerminalConfig='SingleEnded'; | |
ch2.TerminalConfig='SingleEnded'; | |
% Capture: | |
s.IsContinuous = true; | |
s.Rate = 1000; | |
s.prepare(); | |
global GRAB; | |
GRAB=[]; | |
disp('Push any KEY to START...'); | |
pause; | |
%[data,timeStamps,triggerTime] = s.startForeground(); | |
lh = s.addlistener('DataAvailable', @plotData); | |
s.startBackground(); | |
disp('Push any KEY to STOP...'); | |
pause; | |
s.stop(); | |
delete (lh); | |
FIL=sprintf('GRAB_%s.txt', datestr(now(),'yyyy_mm_dd_HH_MM_SS') ) ; | |
fprintf('Saving to: %s\n',FIL); | |
save(FIL,'GRAB', '-ascii'); | |
end | |
function plotData(src,event) | |
global GRAB; | |
GRAB=[GRAB;event.TimeStamps event.Data]; | |
plot(GRAB(1:150:end,1),GRAB(1:150:end,2:end)); | |
title(sprintf('Valor: AL=%f F=%f',event.Data(end,1),event.Data(end,1))); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment