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

6 ビュー (過去 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));
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));
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 Center および File ExchangeData Acquisition Toolbox Supported Hardware についてさらに検索




Community Treasure Hunt

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

Start Hunting!

Translated by