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

3 Ansichten (letzte 30 Tage)
Jan Tomaszewski
Jan Tomaszewski am 15 Sep. 2022
Beantwortet: Jeffrey Clark am 15 Sep. 2022
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.

Antworten (1)

Jeffrey Clark
Jeffrey Clark am 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:

Kategorien

Mehr zu Data Acquisition Toolbox Supported Hardware finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by