Main Content

readbinblock

Read one binblock of data from serial port

Description

data = readbinblock(device) reads a binblock of data from the serial port as uint8 numeric values and returns a 1-by-N array of doubles.

example

data = readbinblock(device,precision) reads a binblock of data interpreted as the type specified by precision. For numeric types, the data is returned as a 1-by-N array of doubles. For text types, the data is returned as character vector or string, as specified.

The function blocks MATLAB® and waits until a binblock is read from the serial port.

The function discards and clears any data in the buffer before the recognized binblock. If no binblock is found the operation times out, returns an empty value, and discards all the data in the buffer. An error in the operation also flushes the data buffer.

example

Examples

collapse all

Read a binblock of numeric uint8 data from the serial port.

The default precision is uint8.

s = serialport("COM3",9600);
data = readbinblock(s);

Read a binblock of numeric uint16 data from the serial port.

s = serialport("COM3",9600);
data = readbinblock(s,"uint16")

Input Arguments

collapse all

Serial port, specified as a serialport object.

Example: serialport()

Size and format of binblock data, specified as a character vector or string. precision determines the number of bits to read for each value and the interpretation of those bits as a MATLAB data type.

Example: 'int16'

Data Types: char | string

Output Arguments

collapse all

Numeric or ASCII data, returned as a 1-by-N vector of doubles or text. For all numeric precision types, data is a row vector of double values. For the text type precision values of 'char' or 'string', data is of the specified type.

Version History

Introduced in R2019b

See Also

Functions