Write data to serial port



write(device,data,precision) writes the 1-by-N matrix of data to the specified serial port. The written data has the specified precision regardless of the format in the matrix.

The write function blocks MATLAB and waits until finished writing data to the serial port.


collapse all

Write the values [1,2,3,4,5] in uint8 format to the serial port device. These five values at 1 byte each are a total of 5 bytes.

s = serialport("COM3",9600);

Input Arguments

collapse all

Serial port, specified as a serialport object.

Example: serialport()

Numeric or ASCII data to write to serial port, specified as a 1-by-N vector of numeric values or text. For all numeric precision types, data is a row vector of values.

Example: [20:24]

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

Size and format of each value, specified as a character vector or string. precision determines the number of bits to write for each value and its format as a MATLAB data type. For ASCII text, you can specify precision as either 'char' or 'string'.

Example: 'int16'

Data Types: char | string

See Also


Introduced in R2019b