Preload function giving too many input argument error

조회 수: 5 (최근 30일)
Julia Pai
Julia Pai 2023년 1월 9일
답변: Julia Pai 2023년 1월 12일
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."
If I'm formatting the input wrong that would be one thing, but the documentation for preload specifies "preload(d,scanData) provides scan data to the DataAcquisition interface d for device output." -- so why is passing 2 inputs into "preload" giving me a error?
  댓글 수: 9
Julia Pai
Julia Pai 2023년 1월 10일
I understand, thanks for your help Walter!
Walter Roberson
Walter Roberson 2023년 1월 11일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Julia Pai
Julia Pai 2023년 1월 12일
I submitted a tech support request and here is the answer I received from the MATLAB support team:
"I have been able to reproduce the issue you are experiencing on my end. It appears to be caused by the output channels lacking support for clocked operations.
Operations which send or receive data must be controlled by a clock. If the hardware itself supports clocked operations you can queue data onto it and make it step through the queue in the background, but if it doesn’t then the program must directly control it, referred to as a “software clock.” This is why the “write” function works as intended while the “preload” function, which queues data for background operation, does not.
This is limited by the operating modes the hardware itself supports, so there are two ways to work around it:
  • You can design your program around the “write” function to directly control the output of the module.
  • You can switch to a different module which supports clocked operations.
The “Too many input arguments” error message you are seeing is not the intended behavior. I have made the development team aware of this and we hope to improve it in a future release. Thank you for bringing this to our attention."

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by