Main Content

configureCallback

Set callback function and trigger condition for communication with remote host over TCP/IP

Since R2020b

Description

configureCallback(t,"terminator",callbackFcn) sets the callback function callbackFcn to trigger whenever a terminator is available to be read from the remote host specified by the TCP/IP client t. The syntax sets the BytesAvailableFcnMode property of t to "terminator" and the BytesAvailableFcn property to callbackFcn.

Set the terminator character using configureTerminator.

example

configureCallback(t,"byte",count,callbackFcn) sets the callback function callbackFcn to trigger whenever a new count number of bytes are available to be read. The syntax sets the BytesAvailableFcnMode property of t to "byte", the BytesAvailableFcnCount property to count, and the BytesAvailableFcn property to callbackFcn.

example

configureCallback(t,"off") turns off callbacks. The syntax sets the BytesAvailableFcnMode property of t to "off".

example

Examples

collapse all

Create a TCP/IP client called t, using the IP address 172.28.154.231 and port 4012.

t = tcpclient("172.28.154.231",4012)
t = 

  tcpclient with properties:

              Address: '172.28.154.231'
                 Port: 4012
    NumBytesAvailable: 0

  Show all properties, functions

Set the callback to trigger when a terminator is available to be read.

configureCallback(t,"terminator",@callbackFcn)

View the properties to confirm the change.

t.BytesAvailableFcnMode
t.BytesAvailableFcn
ans = 

    "terminator"


ans =

  function_handle with value:

    @callbackFcn

Turn the callback off.

configureCallback(t,"off")

Verify that the callback is off.

t.BytesAvailableFcnMode
ans = 

    "off"

Create a TCP/IP client called t, using the IP address 172.28.154.231 and port 4012.

t = tcpclient("172.28.154.231",4012)
t = 

  tcpclient with properties:

              Address: '172.28.154.231'
                 Port: 4012
    NumBytesAvailable: 0

  Show all properties, functions

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

configureCallback(t,"byte",50,@callbackFcn)

View the properties to confirm the change.

t.BytesAvailableFcnMode
t.BytesAvailableFcnCount
t.BytesAvailableFcn
ans = 

    "byte"


ans =

    50


ans =

  function_handle with value:

    @callbackFcn

Turn the callback off.

configureCallback(t,"off")

Verify that the callback is off.

t.BytesAvailableFcnMode
ans = 

    "off"

Input Arguments

collapse all

TCP/IP client, specified as a tcpclient object.

Example: configureCallback(t,"byte",128,@callbackFcn) sets the callbackFcn callback to trigger each time 128 bytes of new data are available to be read from the TCP/IP client t.

Number of bytes of available data to trigger the callback, specified as a positive integer value. Set the BytesAvailableFcnCount property using this argument.

Example: configureCallback(t,"byte",128,@callbackFcn) sets the callbackFcn callback 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 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. Set the BytesAvailableFcn property using this argument.

Example: configureCallback(t,"terminator",@callbackFcn) sets the callbackFcn callback to trigger when a terminator is available to be read.

Data Types: function_handle

Version History

Introduced in R2020b

See Also

Functions