Start DAQ Continuous Sampling after discrete samples
6 次查看(过去 30 天)
显示 更早的评论
Hello All,
I am using a DAQ USB6003, and have written some code that waits for a signal using the "read" command, and once it gets the signal (trigger), I then want to start continuous background sampling. The code looks like this
% Description
% Code to start collecting data from distal load cell on rising edge
% Clear Workspace
close all;
clearvars;
clc;
figNum = 1;
%% Program Parameters
%% Add DAQ Device and Channels
% Device
d1 = daq("ni"); % initiate object
%%
deviceID = 'dev1';
%%%%%%%%%%%%%%%%%%%%%%%%%% INPUT CHANNELS %%%%%%%%%%%%%%%%%%%%%%%%%%%
distForceID = 'ai0'; % analog channel for SPEED from Aruino
distForceCh1 = addinput(d1,deviceID,distForceID,'voltage');
%% Loop and Wait for Signal to Start Sampling
start = false;
priorData = [];
cnt = 1;
while ( start ~= true )
[scanData,timeStamp,~] = read(d1,"OutputFormat","Matrix"); % read single scan
priorData(cnt) = scanData;
if (scanData > 1)
start = true;
end
cnt = cnt + 1;
end
%% Start Data Sampling
% Start Data Sampling
start(d1,"Continuous"); % start analog channels
disp('Start');
sampling = true; % boolean that sampling is running
cnt = 1; % initialize for logging Zaber position
timerStart= tic; % start of timer for when position is logged
stop(d1); % end analog recording
disp('Stop');
However, when it gets to the line for continuous sampling, I get the following error:
Unable to use a value of type daq.interfaces.DataAcquisition as an index.
When I eliminate the while loop with the discrete sampling, I do not get the error. Any ideas how do resolve this? I didn't see much online regarding this error
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Periodic Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!