How can I read data in backgorung from my NI hardware?

조회 수: 3 (최근 30일)
Jan Tomaszewski
Jan Tomaszewski 2022년 9월 15일
답변: Jeffrey Clark 2022년 9월 15일
Hi, I would like to run "read" function once in background to collect data in one-second intervals, and foreground to collect data in 0.03 s intervals simultaneously. Unfortunately I can't do it. Matlab return message "Use of function cd is not supported on a thread-based worker." Can you plaese advise me some solution for my problem?
d = daqlist;
d(1, :)
d{1, "DeviceInfo"}
dq = daq("ni")
dq.Rate = 51200;
ch1 = addinput(dq,"Dev1", "ai0","Voltage");
ch2 = addinput(dq,"Dev1", "ai1","Voltage");
F = parfeval(backgroundPool,@background_FFT,2,t_fft);
%%first data acquisition for 0.03 seconds
for i=1:inf
data = read(dq, seconds(0.03));
end
function [FFT,fr]=background_FFT(t_fft)
dq = daq("ni")
dq.Rate = 51200;
ch3 = addinput(dq,"Dev1", "ai3","IEPE");
%second data acquisition for 1 second
for i=1:100000
data = read(dq, seconds(t_fft));
ch3=data.Dev1_ai3;
[FFT,fr]=widmofft(ch3,dq.Rate,t_fft,1);
plot(fr,FFT)
end
Thank you.

답변 (1개)

Jeffrey Clark
Jeffrey Clark 2022년 9월 15일
@Jan Tomaszewski, try moving the device setup into your main program and pass that dq (and maybe ch3) as a parameters to the worker to use. Others have seen this issue with using files (opening) in workers and it seems likely that external devices could fall into that category see. But after the connection is made perhaps it would work. See:

카테고리

Help CenterFile Exchange에서 Data Acquisition Toolbox Supported Hardware에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by