Preload function giving too many input argument error
5 views (last 30 days)
Show older comments
Hi,
I'm trying to configure a DIO NIDAQ card to acquire and send out signals for an experimental task.
I'm first testing an output signal (which goes to a solenoid pump). My code is as follows:
dq = daq("ni");
% Output channels
ch = addoutput(dq,'Dev1','port1/line0:7','Digital');
output_waterOn = [1 0 0 0 0 0 0 0]; % port0/line0 on turns on pump
output_allOff = [0 0 0 0 0 0 0 0];
Writing the signal to the DAQ works fine.
write(dq, output_waterOn) % running this line of code turns pump on
write(dq, output_allOff) % running this line of code turns pump off
However, I'd like to have the pump run without blocking MATLAB, since other task-related MATLAB processes will need to run in the meantime. But I'm running into an error with the function 'preload' which is really puzzling me.
% do a timed delivery that doesn't block matlab
rewardDur = 2; % duration of pump delivery, in seconds
timenow2ms = @(x) x.Second*1000 + x.Minute*60*1000 + x.Hour*60*60*1000;
%
preload(dq, output_waterOn); % ERROR HERE %%%%%%%
%
timeStart = timenow2ms(datetime("now"));
start(dq, 'RepeatOutput');
while 1
if timenow2ms(datetime("now")) > timeStart+rewardDur*1000
stop(dq)
break
end
end
Running "preload(dq, waterHi)" returns the error message "Too many input arguments."
But running "preload(dq)" returns the obvious message "Error using daq.interfaces.DataAcquisition/preload. Not enough input arguments."
9 Comments
Walter Roberson
on 11 Jan 2023
I accidentally booted into Windows (indeed a pain, it took more than 6 hours for it to do system updates, and it is dangerous to stop those part way through.)
While there I had a look at the R2021b version of the code (I do not happen to have R2022b installed on that Windows partition.)
Inside the C:\Program Files\MATLAB\R2022b\toolbox\daq\cli\+daq\+interfaces\DataAcquisition.m file at roughly line 843 (probably later in R2022b) you will find
function preload(obj,scans)
and then some comments. In the R2021b version, after the comments there is the line
narginchk(2,2);
That line is checking that the preload function was called with a minimum of 2 arguments (first 2) and with a maximum of 2 arguments (second 2).
Please check whether your R2022b version shows the same check. If it does, put a breakpoint at that line and execute
preload(dq, output_waterOn)
and the code should stop at that breakpoint. You should then be able to check nargin and check to be sure that in the context of that code, that obj and scans are both defined. Then dbstep to execute the narginchk line and see whether it rejects the arguments even though nargin is okay.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!