Preload function giving too many input argument error
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 9 de En. de 2023
what is class(waterHi) ? The rules for resolving classes allow the second parameter to determine the class in some cases. The hypothesis here is that there just might be a preload function for the class of waterHi
Walter Roberson
el 9 de En. de 2023
as a debugging step
which preload(dq, output_waterOn)
which preload(dq)
This should show you which method is being invoked
Julia Pai
el 9 de En. de 2023
Walter Roberson
el 9 de En. de 2023
It would be interesting to try
dq.preload(output_waterOn)
Julia Pai
el 9 de En. de 2023
Walter Roberson
el 10 de En. de 2023
Hmmmm... I would have to look at the code. Unfortunately that toolbox is not supported on Mac, and it is a big pain on my system to get Windows running :(
Julia Pai
el 10 de En. de 2023
Walter Roberson
el 11 de En. de 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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Introduction to Installation and Licensing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!