Main Content

configureCallback

Set callback function and trigger condition for communication with UDP socket

Since R2020b

    Description

    configureCallback(u,"terminator",callbackFcn) sets the callback function callbackFcn to trigger whenever a terminator is available to be read from the specified UDP socket. u must be a byte-type udpport object. This syntax sets the BytesAvailableFcnMode property of u to "terminator", and the BytesAvailableFcn property to callbackFcn.

    You set the terminator string with the configureTerminator function.

    configureCallback(u,"byte",count,callbackFcn) sets the callback function callbackFcn to trigger whenever a new count number of bytes are available to be read. u must be a byte-type udpport object. This syntax sets the BytesAvailableFcnMode property of u to "byte", the BytesAvailableFcnCount property to count, and the BytesAvailableFcn property to callbackFcn.

    configureCallback(u,"datagram",count,callbackFcn) sets the callback function callbackFcn to trigger whenever a new count number of datagrams are available to be read. u must be a datagram-type udpport object. This syntax sets the DatagramsAvailableFcnMode property of u to "datagram", the DatagramsAvailableFcnCount property to count, and the DatagramsAvailableFcn property to callbackFcn.

    configureCallback(u,"off") turns off callbacks. This syntax sets the BytesAvailableFcnMode or DatagramsAvailableFcnMode property of u to "off".

    example

    Examples

    collapse all

    Create a UDP socket and configure its callback.

    Set the callback to trigger when a specified terminator is received.

    u = udpport;
    configureTerminator(u,"CR/LF")
    configureCallback(u,"terminator",@myCallback)

    Set the callback to trigger when 50 bytes are available to read.

    configureCallback(u,"byte",50,@myCallback)

    Turn off the callback.

    configureCallback(u,"off")

    Input Arguments

    collapse all

    UDP socket, specified as a udpport object.

    Example: u = udpport

    Data Types: udpport object

    Number of bytes or datagrams of available data to trigger the callback, specified as a positive integer value. This argument sets the BytesAvailableFcnCount or DatagramsAvailableFcnCount property.

    Example: configureCallback(u,"byte",128,@readMyData) sets readMyData as the BytesAvailableFcn to trigger each time 128 bytes of new data are available to be read.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Callback function to run when the trigger condition is met, specified as a function handle. The function handle can be a named function handle or an anonymous function with input arguments. This argument sets the BytesAvailableFcn property.

    Example: configureCallback(u,"terminator",@readMyData) sets readMyData as the BytesAvailableFcn to trigger when a terminator is available.

    Data Types: function_handle

    Version History

    Introduced in R2020b

    See Also

    Functions