configureCallback

Set serial port callback function and trigger

Description

example

configureCallback(device,"terminator",callbackFcn) sets callbackFcn to trigger whenever a terminator is available to read.

configureCallback(device,"byte",count,callbackFcn) sets callbackFcn to trigger whenever count number of bytes are available to read.

configureCallback(device,"off") turns off callbacks.

The serialport object BytesAvailableFcnMode property indicates the mode as "terminator", "byte", or "off". The BytesAvailableFcn property indicates callback function specified by callbackFcn. The BytesAvailableFcnCount property indicates the count setting.

Examples

collapse all

Configure serial port interface callbacks, then clear callbacks.

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

s = serialport("COM3",9600);
configureCallback(s,"byte",50,@callbackFcn)

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

configureCallback(s,"terminator",@callbackFcn)

Turn the callback off.

configureCallback(s,"off")

Input Arguments

collapse all

Serial port, specified as a serialport object.

Example: serialport()

Number of bytes of available data to trigger callback, specified as a positive integer value.

Example: 128

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

Callback function to run when triggered, specified as a function handle.

Example: @myFunction

Data Types: function_handle

See Also

Functions

Introduced in R2019b