too many input arguments using built in configurecallback for tcpip object

t = tcpclient('xxxx',xxxx);
configureCallback(t,"byte",14,@please);
i have a function in the same folder as please and i get this error all the time.
Warning: Error occurred while executing the listener callback for event DataWritten defined for class
asyncio.InputStream:
Error using please
Too many input arguments.

2 Comments

This is the function please if any one was wondering.
function please
g=1+2;
disp(g);
end

Sign in to comment.

 Accepted Answer

You have three choices:
1)
t = tcpclient('xxxx',xxxx);
configureCallback(t,"byte",14,@(varargin)please());
2)
t = tcpclient('xxxx',xxxx);
configureCallback(t,"byte",14,@please);
function please(varargin)
g=1+2;
disp(g);
end
3)
t = tcpclient('xxxx',xxxx);
configureCallback(t,"byte",14,@please);
function please(~,~)
g=1+2;
disp(g);
end

3 Comments

Thank you very much for this answer! the very first option worked well! also on the website on how to use the configure callback it didn't make any reference to 'varagin'.
Also would it be possible to extrackt outputs from the function 'please' withing the configurecallback line?
In MATLAB, with only a few exceptions, callback functions must accept two parameters.
The first of the parameters passed in is the handle of the object the callback is being made for. In this particular case, it would be a handle to t, the tcpclient object.
The second parameter is empty for many kinds of callbacks, but if not empty contains data related to the event that triggered the callback. The event data might be numeric or a struct or an object, depending on the kind of kind of callback.
varargin is not special to these kinds of callbacks; varargin is general MATLAB function syntax; varargin is an input variable in a function definition statement that enables the function to accept any number of input arguments. https://www.mathworks.com/help/matlab/ref/varargin.html

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!