MyPort.write()
Description
Writes values to Arduino using an ArCOM serial port
Accepts scalar values or arrays
Accepts signed and unsigned integers of 8, 16 or 32 bits.
Returns an error if data is out of range for the intended data type.
Syntax
MyPort.write(Data, Datatype, Data2, Datatype2,...)
Parameters
Data: A MATLAB variable containing data to send.
Datatype: A string specifying the data type:
'uint8'
'uint16'
'uint32'
'int8'
'int16'
'int32'
DataN, DatatypeN: Optionally, additional scalars or arrays of data can be added as pairs of additional data and datatype arguments.
Instead of a list of separate calls to ArCOM, this allows more efficient transmission: the data vectors will be packaged into a byte string, and transmitted with a single write call to the underlying interface.
Returns
None
Examples
These examples assume a port has been created with:
MyPort = ArCOMObject('COM3', 115200); % Use your actual port and baud rate
% 1. This sends a 32-bit unsigned integer to Arduino. Arduino is connected to an ArCOM serial port in the current workspace, named MyPort.
MyInt = 3141592;
MyPort.write(MyInt, 'uint32');
% 2. This sends a 100-sample sine wave (range: +/- 10,000) to Arduino as signed 16-bit integers.
MyWave = int16(sin(.1*(1:100))*10000);
MyPort.write(MyWave, 'int16');
% 3. This sends an 8-bit op code, a 32-bit time and a 16-bit sample with a single call to the underlying serial interface:
opCode = 56;
time = 102423;
sample = 5001;
MyPort.write(opCode, 'uint8', time, 'uint32', sample, 'int16');