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

3 views (last 30 days)
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.

Answers (1)

Jeffrey Clark
Jeffrey Clark on 15 Sep 2022
@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:

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!