how to split in subplot real time analog input monitoring (scope)

1 view (last 30 days)
Hi, I have this script which I am trying to use to visualize data input from multiple analog channels (from 2 niDAQ USB 6211 devices, 16 channels in total). I would like to visualize channels separately at least for the two DAQs (best would be to be able to set groups). Thanks for your help
clear, clc, close all; daq.reset; %% Create Data Acquisition Session % Create a session for the specified vendor. s = daq.createSession('ni');
%% Set Session Properties % Set properties that are not using default values. s.Rate = 20000; s.IsContinuous = true; n_channels = 16
%% Add Channels to Session % Add channels and set channel properties, if any. addAnalogInputChannel(s,'Dev1','ai0','Voltage'); addAnalogInputChannel(s,'Dev1','ai1','Voltage'); addAnalogInputChannel(s,'Dev1','ai2','Voltage'); addAnalogInputChannel(s,'Dev1','ai3','Voltage'); addAnalogInputChannel(s,'Dev1','ai4','Voltage'); addAnalogInputChannel(s,'Dev1','ai5','Voltage'); addAnalogInputChannel(s,'Dev1','ai6','Voltage'); addAnalogInputChannel(s,'Dev1','ai7','Voltage'); addAnalogInputChannel(s,'Dev2','ai0','Voltage'); addAnalogInputChannel(s,'Dev2','ai1','Voltage'); addAnalogInputChannel(s,'Dev2','ai2','Voltage'); addAnalogInputChannel(s,'Dev2','ai3','Voltage'); addAnalogInputChannel(s,'Dev2','ai4','Voltage'); addAnalogInputChannel(s,'Dev2','ai5','Voltage'); addAnalogInputChannel(s,'Dev2','ai6','Voltage'); addAnalogInputChannel(s,'Dev2','ai7','Voltage');
%% Initialize Session UserData Property % Initialize the custom fields for managing the acquired data across callbacks. s.UserData.Data = []; s.UserData.TimeStamps = []; s.UserData.StartTime = [];
%% Add Listeners % Add listeners to session for available data and error events. lh1 = addlistener(s, 'DataAvailable', @recordData); lh2 = addlistener(s, 'ErrorOccurred', @(~,eventData) disp(getReport(eventData.Error)));
%% Acquire Data % Start the session in the background. startBackground(s) pause(5) % Increase or decrease the pause duration to fit your needs. stop(s)
%% Log Data % Convert the acquired data and timestamps to a timetable in a workspace variable. ai0 = s.UserData.Data(:,1); ai1 = s.UserData.Data(:,2); ai2 = s.UserData.Data(:,3); ai3 = s.UserData.Data(:,4); ai4 = s.UserData.Data(:,5); ai5 = s.UserData.Data(:,6); ai6 = s.UserData.Data(:,7); ai7 = s.UserData.Data(:,8); ai8 = s.UserData.Data(:,9); ai9 = s.UserData.Data(:,10); ai10 = s.UserData.Data(:,11); ai11 = s.UserData.Data(:,12); ai12 = s.UserData.Data(:,13); ai13 = s.UserData.Data(:,14); ai14 = s.UserData.Data(:,15); ai15 = s.UserData.Data(:,16); DAQ_1 = timetable(seconds(s.UserData.TimeStamps),ai0,ai1,ai2,ai3,ai4,ai5,ai6,ai7); DAQ_2 = timetable(seconds(s.UserData.TimeStamps),ai8,ai9,ai10,ai11,ai12,ai13,ai14,ai15);
%% Clean Up % Remove event listeners and clear the session and channels, if any. delete(lh1) delete(lh2) clear s lh1 lh2
%% Callback Function % Define the callback function for the 'DataAvailable' event. function recordData(src, DAQ_1) src.UserData.Data = [src.UserData.Data; DAQ_1.Data]; src.UserData.TimeStamps = [src.UserData.TimeStamps; DAQ_1.TimeStamps];
if isempty(src.UserData.StartTime) src.UserData.StartTime = DAQ_1.TriggerTime; end
plot(DAQ_1.TimeStamps, DAQ_1.Data)
subplot(2,1,2)
plot(DAQ_2.TimeStamps, DAQ_2.Data)
xlabel('Time (s)')
ylabel('Amplitude (V)')
legend('ai0','ai1','ai2','ai3','ai4','ai5','ai6','ai7','ai8','ai9','ai10','ai11','ai12','ai13','ai14','ai15')
end

Answers (0)

Categories

Find more on Dialog Boxes 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!