understanding the TCPIP object in GUI

3 views (last 30 days)
Hamza
Hamza on 27 Jul 2016
Answered: Geoff Hayes on 30 Jul 2016
I am studying the TCPIP object in matlab, currently I am studying a code in which a TCPIP inspector is given few values. one of them is a itself a function with other two arguments like :
socket = tcpip(GL_PROTOCOL.IP_ADDR, GL_PROTOCOL.PORT_NUM);
socket.InputBufferSize = GL_COLLECTDATA.BUFSIZE;
socket.ReadAsyncMode = 'continuous';
socket.BytesAvailableFcn = {@ScanCallBack,handles,requiredLength};
I am curious about the last line. i tried to run the code in the debug mode as well, but i couldn't follow the process. the ScanCallBack is itself a separate function .
can anyone kindly put some light on {@ScanCallBack,handles,requiredLength} this.

Answers (1)

Geoff Hayes
Geoff Hayes on 30 Jul 2016
Hamza - from writing and reading data, indicates that the the default value for the BytesAvailableFcnMode property indicates that the callback function defined by the BytesAvailableFcn property will be executed when the terminator has been read. Usually the callback would be assigned as
socket.BytesAvailableFcn = @ScanCallBack;
with the default signature for it being
function ScanCallBack(object,event)
where the function has been declared either within the m file or in its own m file as ScanCallBack.m. In your case, you are using
socket.BytesAvailableFcn = {@ScanCallBack,handles,requiredLength};
which means that you want to pass two additional parameters to the callback and so its signature would then become
function ScanCallBack(object,event,handles,requiredLength)
where handles and requiredLength are (presumably) variables that have been defined in the function that is initializing your socket. This is fine, but what you have to remember is that these last two inputs, handles and requiredLength, are copies of the local variables at the time that this callback is assigned to socket.BytesAvailableFcn. So if either changes (and typically the handles structure does) then ScanCallback will not be aware of these changes as it will only receive the older copy.

Community Treasure Hunt

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

Start Hunting!