How to handle multiple devices with an external trigger signal in NI-PXI platform?

3 次查看(过去 30 天)
I have a NI-PXI chassis(model: 1042Q) and multiple data aquisition devices(PXI-4496) for multi-channel signal acquisition and processing.
With an external digital trigger, how can I connect the trigger signal and make a matlab program. Please let me know the useful code to deal with multiple devices with an external trigger signal in a PXI chassis.

回答(2 个)

R
R 2024-6-25
编辑:R 2024-6-25
To acquire data from multiple NI PXI-4496 devices using an external digital trigger in a PXI chassis (model: 1042Q) with MATLAB, use the 'Data Acquisition Toolbox'. First, ensure the NI-DAQmx drivers and Data Acquisition Toolbox are installed. Use daqlist("ni") to identify connected devices and create a DataAcquisition object with daq("ni").
Add analog input channels from each PXI-4496 device using addinput, specifying channels (e.g., addinput(d, deviceIDs{i}, "ai0:7", "Voltage")). Configure the external digital trigger with addtrigger, setting the trigger type to "Digital", source to "StartTrigger", and condition to "RisingEdge" (e.g., addtrigger(d, "Digital", "StartTrigger", "Dev1/PFI0", "External")).
Set the sample rate and duration and start the session to begin data acquisition when the external trigger is received.
Below is a sample code you can refer:
% Ensure the Data Acquisition Toolbox is installed and NI-DAQmx drivers are available
% Step 1: List all connected DAQ devices
devices = daq.getDevices;
% Display connected devices
disp('Connected DAQ devices:');
disp(devices);
% Step 2: Create a data acquisition session
s = daq.createSession('ni');
% Step 3: Add analog input channels from each PXI-4496 device
% Replace 'Dev1', 'Dev2', etc. with the actual device IDs from the devices list
deviceIDs = {'Dev1', 'Dev2'}; % Example device IDs
numDevices = length(deviceIDs);
for i = 1:numDevices
% Add all channels from each device
addAnalogInputChannel(s, deviceIDs{i}, 0:7, 'Voltage'); % PXI-4496 has 8 channels (0-7)
end
% Step 4: Configure the external digital trigger
% Replace 'PFI0' with the actual PFI line used for the external trigger
s.addTriggerConnection('External', 'Dev1/PFI0', 'StartTrigger');
% Step 5: Set the rate and duration of the acquisition
s.Rate = 50000; % Sample rate in Hz (50 kHz)
s.DurationInSeconds = 10; % Duration of the acquisition in seconds
% Step 6: Start the session and acquire data
disp('Waiting for external trigger...');
[data, time] = s.startForeground;
% Step 7: Process the acquired data
disp('Data acquisition complete.');
plot(time, data);
xlabel('Time (s)');
ylabel('Voltage (V)');
title('Acquired Data from Multiple PXI-4496 Devices');
legend(arrayfun(@(x) sprintf('Channel %d', x), 1:size(data, 2), 'UniformOutput', false));
% Save the data to a file if needed
save('acquired_data.mat', 'data', 'time');
Refer to the documentation link and examples to know more:

Hyu-Sang Kwon
Hyu-Sang Kwon 2024-6-25
Thanks very much for your immediate reply.
I tried your code, but I got the following error message.
Because I use the Matlab 2018b version, these commands such as "daqlist" and "daq" may cause an error.
Would you modify this code for Matlab 2018b?
Thanks in advance.
-------------------------------------------------------------------------
'daqlist'은(는) 정의되지 않은 함수 또는 변수입니다.
오류 발생: Mat_answer_01 (line 4)
devices = daqlist("ni");
  4 个评论
R
R 2024-6-26
@Hyu-Sang Kwon, it seems that you need to ensure all devices in a session start together and use the same scan clock. You can add this configuration before Step 5, i.e., setting the rate and duration of the acquisition:
% Ensure that all devices use the same clock
for i = 2:numDevices
s.addClockConnection('Dev1/PFI0', deviceIDs{i}, 'ScanClock');
end
Hyu-Sang Kwon
Hyu-Sang Kwon 2024-6-26
I added the configuration commands and ran the program, but unfortunately, it dosen't still work.
The error message is as follows, and the command line 30 is
s.addClockConnection('Dev1/PFI0', deviceIDs{i}, 'ScanClock');
-------------------------------------------------------------------------------------------------------------------
>> Mat_answer_03
Connected DAQ devices:
Data acquisition devices:
index Vendor Device ID Description
----- ------ --------- -----------------------------
1 ni Dev1 National Instruments PXI-4496
2 ni Dev2 National Instruments PXI-4496
경고: A channel that does not support on-demand operations was added to the session. On-demand operations using inputSingleScan and
outputSingleScan will be disabled. Only clocked operations using startForeground and startBackground can be done.
경고: A channel that does not support on-demand operations was added to the session. On-demand operations using inputSingleScan and
outputSingleScan will be disabled. Only clocked operations using startForeground and startBackground can be done.
다음 사용 중 오류가 발생함: Mat_answer_03 (line 30)
Can not determine destination device and terminal name from input argument 'Dev2'. Use 'DeviceName/TerminalName' format or 'External'.
>>

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simultaneous and Synchronized Operations 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by