MyPort.read()

Description

Reads values from Arduino using an ArCOM serial port object

  • Reads scalar values or arrays

  • Reads signed and unsigned integers of 8, 16 or 32 bits.

Syntax

Data = MyPort.read(nValues, Datatype, nValues2, Datatype2...)

Parameters

  • nValues: The number of values to read

  • Datatype: A string specifying the data type to read:

    • 'uint8'

    • 'uint16'

    • 'uint32'

    • 'int8'

    • 'int16'

    • 'int32'

  • nValuesN, DatatypeN: Optionally, additional scalars or arrays of data can be read, using pairs of additional data and datatype arguments.

Returns

  • Data: A MATLAB variable containing the data read from Arduino, of the specified data type. If multiple arrays are returned, format Data as [Data1, Data2] = MyPort.read()

Examples

These examples assume a port has been created with:

MyPort = ArCOMObject('COM3', 115200); % Use your actual port and baud rate


% 1. This reads a 32-bit unsigned integer from Arduino. Arduino is connected to an ArCOM serial port in the current workspace, named MyPort.

MyInteger = MyPort.read(1, 'uint32');


% 2. This reads a 100-sample waveform from Arduino as signed 16-bit integers.

MyWaveform = MyPort.read(100, 'int16');


% 3. This reads an 8-bit code, 10 16-bit samples and 50 32-bit timestamps.

[opCode, samples, timestamps] = MyPort.read(1, 'uint8', 10, 'int16', 50, 'uint32');