How could I use "startbackground(s)' continuous read AI 0 signal and output AO 0 voltage at the same time? (with DAQ 6212)
5 views (last 30 days)
Show older comments
I learn startbackground(s) can separated get input channel and output voltage to output channel.
But I would like to make them together!
(Because if I use startForeground(), it looks like it need time to active DAQ so I prefer to use startbackground();)
(I test by USB BNC 6212)
I can separate them read AI0 port like:
s = daq.createSession('ni');
dev3_ai0 = addAnalogInputChannel(s,'dev3','ai0','Voltage')
lh=addlistener(s,'DataAvailable', @DAQsaveData);
%I save a function like:
function DAQsaveData(src,event)
a=event.Data;
save('D:\test\test.mat','a');
plot(event.TimeStamps, event.Data)
end
startBackground(s);
and I can see the figure ploting, also save the data to txt file.
and I can output AO0 port sine wave like:
s = daq.createSession('ni');
dev3_ao0 = addAnalogOutputChannel(s,'dev3','ao0','Voltage')
s.IsContinuous = true;
s.Rate=200000;
x=1:1:100000;
y=transpose(sin(x));
lh=addlistener(s,'DataRequired', @(src,event)DAQsaveData(y));
queueOutputData(s,y)
startBackground(s);
Then I can see sine wave on Oscilloscope.
But is that any method to make input and output at the same time at background?
I have try 'DataAvailable' and not sure it can use for output function.
like: (with the same function DAQsaveData I used)
s = daq.createSession('ni')
dev3_ai0 = addAnalogInputChannel(s,'dev3','ai0','Voltage')
dev3_ao0 = addAnalogOutputChannel(s,'dev3','ao0','Voltage')
s.Rate=200000;
s.IsContinuous = true;
x=1:1:100000;
y=transpose(sin(x));
lh=addlistener(s,'DataAvailable', @(src,event)DAQsaveData(y));
queueOutputData(s,transpose(y));
startBackground(s);
After this I can see sine wave appear on Oscilloscope for less than 5 secs, then input (with plot function) and output voltage are stop!
Because in 32bit I can use start(AI)+getdata(AI) and putsample(AO,1) in a very short time like 0.1 sec at sample rate=200000, and sample per trigger = 10000; (Actually I only need to output a single value to output port AO until next tandem data come form input port AI)
But if I use startForeground() it will take a long time more than 0.2 sec to run the daq. But startbackground() is much faster.
Is that any way to make startbackground() continuous let DAQ 6212 input and output?
THANKS A LOT!!
%% @2015b 64 bits Matlab and USB BNC 6212
%%--------my setup
s =
Data acquisition session using National Instruments hardware:
Will run continuously at 200000 scans/second until stopped.
Number of channels: 2
index Type Device Channel MeasurementType Range Name
----- ---- ------ ------- ------------------- ---------------- ----
1 ai Dev3 ai0 Voltage (Diff) -10 to +10 Volts
2 ao Dev3 ao0 Voltage (SingleEnd) -10 to +10 Volts
AutoSyncDSA: false
NumberOfScans: Inf
DurationInSeconds: Inf
Rate: 200000
IsContinuous: true
NotifyWhenDataAvailableExceeds: 20000
IsNotifyWhenDataAvailableExceedsAuto: true
NotifyWhenScansQueuedBelow: 100000
IsNotifyWhenScansQueuedBelowAuto: true
ExternalTriggerTimeout: 10
TriggersPerRun: 1
Vendor: National Instruments
Channels: [1x2 daq.AnalogChannel]
Connections: ''
IsRunning: false
IsLogging: false
IsDone: true
IsWaitingForExternalTrigger: false
TriggersRemaining: 0
RateLimit: [0.1 250000.0]
ScansQueued: 0
ScansOutputByHardware: 100000
ScansAcquired: 100000
%%--------
0 Comments
Answers (0)
See Also
Categories
Find more on Analog Data Acquisition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!