Foreground DAQ acquisition after background acquisition suddenly not getting correct number of scans
2 次查看(过去 30 天)
显示 更早的评论
I wrote some code in App Designer several months ago. The code was working fine until yesterday when I started seeing the following warning:
Warning: only X scans available
Where X is some number between 1 and 4.
It is happening when my code switches between background and foreground data acquisition on a button push.
Here is a snippet of the code in question -
% Get DAQ info from pulldown
deviceIndex = app.Screen1.DAQDropDown.Value-1;
deviceID = app.Screen1.DevicesInfo(deviceIndex).ID;
vendor = app.Screen1.DevicesInfo(deviceIndex).Vendor.ID;
% Delete existing data acquisition object
delete(app.DAQ);
app.DAQ = [];
% Create a new data acquisition object
dq = daq(vendor);
app.DAQ=dq;
% Add channels
ch = addinput(app.DAQ, deviceID, 0:15,"Voltage");
for cnt=1:16
ch(cnt).TerminalConfig = 'SingleEndedNonReferenced';
end
% Change to background process DAQ settings and start background acquisition
app.Screen3.Screen2.DAQ.Rate = 5;
app.Screen3.Screen2.DAQ.ScansAvailableFcnCount=1;
app.Screen3.Screen2.DAQ.ScansAvailableFcn = @(obj,evt) WriteMyDataScan(app,obj,evt);
start(app.Screen3.Screen2.DAQ,"Continuous");
% Button pushed function: TakeScanButton
function TakeScanButtonPushed(app, event)
%Increase scan count
app.ScanCount=app.ScanCount+1;
%Stop the background DAQ process
stop(app.Screen3.Screen2.DAQ);
daq_dev=app.Screen3.Screen2.DAQ;
%Set sample rate and number of samples
daq_dev.Rate=25;
samples=50;
%read 50 samples
data=read(daq_dev,samples,'OutputFormat',"Matrix");
%Change back to background process DAQ settings and re-start background acquisition
app.Screen3.Screen2.DAQ.Rate = 5;
app.Screen3.Screen2.DAQ.ScansAvailableFcnCount=1;
app.Screen3.Screen2.DAQ.ScansAvailableFcn = @(obj,evt) WriteMyDataScan(app,obj,evt);
start(app.Screen3.Screen2.DAQ,"Continuous");
end
The read command in the TakeScanButtonPushed -
data=read(daq_dev,samples,'OutputFormat',"Matrix");
should be reading 50 samples.
...but sometimes upon stopping the background DAQ process, the NumScansAcquired field would be non-zero... and in that case instead of 50 scans, I would only get the number of scans listed in the NumScansAcquired field. If the NumScansAcquired field was zero, the read command gets all 50 scans.
The problem seems to be fixed by adding a flush between stopping the background acquisition and doing the read.
The mystery is - why did this suddenly start happening? The machine is not connected to the internet. The DAQ driver has not been updated. The OS (Windows 10) hasn't been updated. Matlab (R2020b) has not been updated. The code hasn't changed.
0 个评论
回答(1 个)
Namnendra
2023-4-27
Hey Aaron,
It's difficult to say exactly what might have caused this sudden change in behavior without more information, but one possibility is that there may be some external factor causing intermittent interruptions in the data acquisition process. This could be due to fluctuations in power supply, interference from nearby electronics, or other environmental factors.
Adding a flush command between stopping the background acquisition and reading the data can help ensure that any remaining data in the buffer is cleared before reading new data, which may explain why this change fixed the issue.
It's also possible that there may be some changes in the hardware or software environment that are not immediately apparent, such as changes to drivers or firmware updates that were installed automatically. It may be worth checking to see if there have been any updates or changes made to the system recently, even if they were not intentional.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!