How do I generate a continuous signal and acquire data over short spans simultaneously? (New to DAQ Toolbox)

3 views (last 30 days)
As the subject says, I am completely new to using the Data Acquisition Toolbox, and I am writing a program to calibrate a piece of equipment by incrementing the continuous output voltage by .25V every iteration, taking input measurements for 2 seconds, and averaging the values to make a single data point for the single output setting. I am using an NI USB-6211, and here is the code:
close all; clear all; clc;
s1 = daq.createSession('ni');
s2 = daq.createSession('ni');
s1.addAnalogInputChannel('Dev1',0,'Voltage');
s1.addAnalogInputChannel('Dev1',1,'Voltage');
s1.addAnalogInputChannel('Dev1',2,'Voltage');
s2.addAnalogOutputChannel('Dev1',0,'Voltage');
s1.Rate = 1000; % (should be default)
s2.Rate = 1000;
s1.DurationInSeconds = 2;
s2.IsContinuous = true;
outputValue = zeros(500,1);
for i = 0:0.25:5
disp(['Output ',num2str(i),'V to MFCs.']);
outputValue(:) = i;
lh = s2.addlistener('DataAvailable', ...
@(src,event) src.queueOutputData(outputValue));
s2.queueOutputData(outputValue);
s2.startBackground();
disp(['Acquiring data at ',num2str(i),'V setting for 2 seconds.']);
[capturedData,time] = s1.startForeground();
disp('Finished acquiring');
v0Avg = mean(capturedData(:,1))
v1Avg = mean(capturedData(:,2))
V2Avg = mean(capturedDate(:,3))
s2.stop();
s1.stop();
delete(lh);
end
It seems to get hung up at the "[capturedData,time] = s1.startForeground();" line, and I have no clue right now as to why that would be.
Also, if you see that I am doing anything silly or nonsensical, feel free to shed some knowledge.
Thank you for your help
  1 Comment
Brian Marker
Brian Marker on 17 Jan 2014
Edited: Walter Roberson on 20 May 2015
Sorry for the weird formatting in the code. I'm not sure why it did that.
close all; clear all; clc;
s1 = daq.createSession('ni');
s2 = daq.createSession('ni');
s1.addAnalogInputChannel('Dev1',0,'Voltage');
s1.addAnalogInputChannel('Dev1',1,'Voltage');
s1.addAnalogInputChannel('Dev1',2,'Voltage');
s2.addAnalogOutputChannel('Dev1',0,'Voltage');
s1.Rate = 1000;
s2.Rate = 1000;
s1.DurationInSeconds = 2;
s2.IsContinuous = true;
outputValue = zeros(500,1);
for i = 0:0.25:5
disp(['Output ',num2str(i),'V to MFCs.']);
outputValue(:) = i;
lh = s2.addlistener('DataAvailable', ...
@(src,event) src.queueOutputData(outputValue));
s2.queueOutputData(outputValue);
s2.startBackground();
disp(['Acquiring data at ',num2str(i),'V setting for 2 seconds.']);
[capturedData,time] = s1.startForeground();
disp('Finished acquiring');
laserAvg = mean(capturedData(:,1))
sensorAvg = mean(capturedData(:,2))
outputAvg = mean(capturedDate(:,3))
s2.stop();
s1.stop();
delete(lh);
end

Sign in to comment.

Answers (1)

BienLe
BienLe on 2 Mar 2015
Edited: BienLe on 2 Mar 2015
Hi, I encountered the same problem. Could you please help me to solve the problem? My Matlab always hung up whenever I use "Iscontinuous = true".
Thanks a lot.
Bien

Community Treasure Hunt

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

Start Hunting!