How to run a while or for loop in a script with NIDAQ Background operations?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have been attempting to create a script that simultaneously controls serial devices and captures data using NIDAQ Data Acquisition Toolbox. I found that when I start a for or while loop, the background acquisition ceases for the entire duration. Is there a reason for this sort of behavior?
Example:
%%NI DAQ
DAQ = daq.createSession('ni');
LC_1 = addAnalogInputChannel(DAQ,'cDAQ2Mod1', 'ai0', 'Bridge' );
LC_2 = addAnalogInputChannel(DAQ,'cDAQ2Mod1', 'ai1', 'Bridge');
LC_1.BridgeMode = 'Full';
LC_2.BridgeMode = 'Full';
LC_1.ADCTimingMode = 'HighSpeed';
LC_2.ADCTimingMode = 'HighSpeed';
range = 0.05;
LC_1.Range = [-range , range];
LC_2.Range = [-range , range];
LC_1.NominalBridgeResistance = 350;
LC_2.NominalBridgeResistance = 350;
DAQ.NotifyWhenDataAvailableExceeds = 1;
DAQ.IsContinuous = true;
DAQ.Rate = 100;
lh = addlistener(DAQ, 'DataAvailable', @plotData);
DAQ.startBackground;
pause(10);
while 1
%No data is capture here however short or long the loop
end
0 commentaires
Réponses (2)
Nicholas Jackson
le 21 Fév 2018
Hi Edward, I'm having a similar issue. Did you ever get this resolved? Thanks
0 commentaires
Louis Edelman
le 6 Mar 2018
You need to write a function that pulls the data out of the DataAvailable event. Instead of @PlotData use something like the script below with daq_trigger, daq_data, and daq_times as global variables in your script.
function background_pull(src, event) %BACKGROUND_PULL Extracts the data acquired in a background DAQ acquisition %and outputs it to the workspace with the session trigger time. % Detailed explanation goes here global daq_times daq_data daq_trigger daq_data = event.Data; % Extract data from structyure daq_trigger = datetime(event.TriggerTime, 'ConvertFrom', 'datenum', 'TimeZone', 'local'); % Extract the first sample time as the trigger time daq_trigger = datetime(daq_trigger, 'TimeZone', 'UTC'); % Convert to UTC to match Camera % Note that for the NI-6143 event.TimeStamps(1) == 0, however this isn't % true for all cards daq_times = event.TimeStamps; % Extract the frame time from the end
0 commentaires
Voir également
Catégories
En savoir plus sur National Instruments Frame Grabbers dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!