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!