Start DAQ Continuous Sampling after discrete samples

6 ビュー (過去 30 日間)
Holden
Holden 2024 年 9 月 9 日
移動済み: Walter Roberson 2024 年 10 月 30 日 22:47
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

回答 (1 件)

Holden
Holden 2024 年 9 月 9 日
移動済み: Walter Roberson 2024 年 10 月 30 日 22:47
I just realized I used "start" as a boolean! Please ignore this post

カテゴリ

Help Center および File ExchangePeriodic Waveform Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by