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 CenterFile Exchange에서 Periodic Waveform Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by