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 件のコメント

This is the function please if any one was wondering.
function please
g=1+2;
disp(g);
end
David Tetenji
David Tetenji 2021 年 3 月 22 日
I am using the 2021A matlab version

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2021 年 3 月 23 日
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 件のコメント

David Tetenji
David Tetenji 2021 年 3 月 25 日
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'.
David Tetenji
David Tetenji 2021 年 3 月 25 日
Also would it be possible to extrackt outputs from the function 'please' withing the configurecallback line?
Walter Roberson
Walter Roberson 2021 年 3 月 26 日
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

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by