Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Migrates legacy session-based MATLAB Data Acquisition code to the modern daq interface, including callbacks, triggers, and output refill.
64% 100%+36 ptsof test cases passed
Passed 25 of 25 test cases with the skill, and 16 of 25 without it.
In legacy MATLAB DAQ sessions, developers set `s.ExternalTriggerTimeout = 15;` to prevent infinite hangs when waiting for an external start pulse. What is the equivalent property on modern `DataAcquisition` objects?
Uses DigitalTriggerTimeout to set the trigger timeout on the DataAcquisition object.
3 of 3 safety checks passed
When a ScansAvailableFcn or ScansRequiredFcn needs to maintain state across fires (running counters, phase accumulators, latch flags, file handles), four mechanisms are available. Three work, one fails silently. This file is the decision guide.
| Need | Use |
|---|---|
| Simple scalar counter or flag, in a function-form script | Nested function (Pattern A) |
| Complex state shared across multiple callbacks and external code | Handle class wrapper (Pattern B) |
| Quick prototype, single callback, can re-create state each fire | Anonymous-function closure (Pattern C, with caveats) |
Code already passes d everywhere and you don't want extra files | Whole-struct UserData rewrite (Pattern D, advanced) |
Never use: src.UserData.X = src.UserData.X + ... field mutation (see anti-pattern below).
The callback is a nested function inside the entry function. Local variables in the entry function are captured by reference in nested functions, so updates persist.
function runStreamingAcquisition()
d = daq("ni");
addinput(d, "Dev1", "ai0", "Voltage");
d.Rate = 1000;
d.ScansAvailableFcnCount = 200;
scansRead = 0;
target = d.Rate * 5;
d.ScansAvailableFcn = @(src, ~) onBlock(src);
d.ErrorOccurredFcn = @(~, evt) fprintf("DAQ error: %s\n", evt.Error.message);
start(d, "Continuous");
while d.Running
pause(0.05);
end
function onBlock(src)
data = read(src, src.ScansAvailableFcnCount, "OutputFormat", "Matrix");
scansRead = scansRead + size(data, 1);
Next to this one in the catalogue, plus more from the same author.