メインコンテンツ

writebinblock

Write one binblock of data to serial port

Description

writebinblock(device,data,datatype) converts data into a binblock and writes it to the serial port. data can be a string, character vector, or numeric 1-by-N matrix. The written data has the specified datatype regardless of the format in the matrix. The function blocks MATLAB and waits until the binblock data is written to the serial port.

example

writebinblock(device,data,datatype,header) prefixes the ASCII string specified by header to the data that is sent.

example

Examples

collapse all

Convert [1,2,3,4,5] to a binblock and write it to the serial port as uint8.

s = serialport("COM3",9600);
 ⋮
writebinblock(s,1:5,"uint8")

Define a serialport connection and header string.

s = serialport("COM3",9600);
hdr = "MEMTEST DATA";

Write the header and data values [1,2,3,4,5] as a binblock in double format to the serial port s.

writebinblock(s,1:5,"double",hdr)

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 string, character vector, or 1-by-N vector of numeric values. For all numeric 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. datatype determines the number of bits to write for each value and its format as a MATLAB data type. For ASCII text, you can specify datatype as either "char" or "string".

Example: "int16"

Data Types: char | string

ASCII string prefixed to the data, specified as a string or character vector.

Example: writebinblock(v,1:5,"double","Test 34.1") writes the header string "Test 34.1" followed by the values [1,2,3,4,5] as double data.

Data Types: char | string

Version History

Introduced in R2019b

expand all

See Also

Functions