Take Discrete DAQ sample while doing Continuous Sampling
6 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I am doing a background sampling of a DAQ USB6003 in Matlab. What I need to do is periodically pull the latest data point from the background sampling. However, when I try to do this using the "read" function during the background sessions, I get the error:
Error using roboAnterograde_speedStop (line 159)
NI Error -50103:
The specified resource is reserved. The operation could not be completed as specified.
Task Name: _unnamedTask<3FF>
Status Code: -50103
I also tried creating a second DAQ object with only the channel added that I need to continously check during the background sesions and it also doesn't work.
So, does anyone have a good way to pull the latest data points during the background sampling without stopping the sampling?
Hopefully this makes sense.
Thank you
0 件のコメント
回答 (3 件)
akshatsood
2024 年 9 月 17 日
編集済み: akshatsood
2024 年 9 月 17 日
I see that you are performing a background sampling of a DAQ USB6003 in MATLAB and you need to periodically pull the latest data point from the background sampling.
The error you are encountering, "NI Error -50103", indicates that the resource is reserved, meaning that the DAQ device is already in use by another task. This is a common issue when attempting to access the same DAQ device from multiple tasks simultaneously.
Here are a few strategies you can try to resolve this issue and periodically access the latest data points:
Use a Listener to Access Data - MATLAB allows you to set up a listener that can be triggered whenever new data is available. This approach avoids directly accessing the DAQ device while it is in use.
s = daq.createSession('ni'); % Create a DAQ session
addAnalogInputChannel(s, 'Dev1', 'ai0', 'Voltage');
s.Rate = 1000; % 1000 Hz
s.DurationInSeconds = 10;
% Add a listener for DataAvailable event
lh = addlistener(s, 'DataAvailable', @(src, event) processData(event));
function processData(event)
latestData = event.Data(end, :); % Get the latest data point
disp(latestData);
end
s.startBackground();
Use a Circular Buffer - Implement a circular buffer to store the latest data points and access them as needed. This approach can be combined with the listener method.
bufferSize = 1000;
circularBuffer = zeros(bufferSize, 1);
bufferIndex = 1;
function processData(event)
global circularBuffer bufferIndex bufferSize;
data = event.Data;
numDataPoints = size(data, 1);
for i = 1:numDataPoints
circularBuffer(bufferIndex) = data(i);
bufferIndex = mod(bufferIndex, bufferSize) + 1;
end
% Access the latest data point
latestData = circularBuffer(mod(bufferIndex - 2, bufferSize) + 1);
disp(latestData);
end
Please refer to the following MATLAB Answer for better understanding
I hope this helps.
0 件のコメント
Holden
2024 年 9 月 18 日
2 件のコメント
akshatsood
2024 年 9 月 23 日
It sounds like the issue might indeed be related to the speed at which the "read" function is called. If the discrete "read" command is slower than the loop, it could cause the discrepancy between "cnt" and "spot". You might want to try adding a brief pause in the loop or optimizing the read process to ensure it can keep up with the loop iterations.
参考
カテゴリ
Help Center および File Exchange で National Instruments Frame Grabbers についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!