write
Write data to serial device
Description
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
write(
writes data to the serial device.serialdevObj,dataIn)
write(
also specifies the precision.serialdevObj,dataIn,precision)
Examples
Create an arduino connection.
arduinoObj = arduino("COM16","Leonardo","Libraries",{'SPI','Serial','I2C'});
Create a connection to the serial device on the Arduino hardware.
serialdevObj = device(arduinoObj,'SerialPort',1)serialdevObj =
device with properties:
Interface: 'Serial'
SerialPort: 1
TxPin: 'D1'
RxPin: 'D0'
BaudRate: 9600 (bits/s)
NumBytesAvailable: 0
Show all properties, functions
Write 3 bytes of data to the serial device.
write(serialdevObj,[88 99 65]);
Create an arduino connection.
arduinoObj = arduino("COM16","Leonardo","Libraries",{'SPI','Serial','I2C'});
Create a connection to the serial device on the Arduino hardware.
serialdevObj = device(arduinoObj,'SerialPort',1)serialdevObj =
device with properties:
Interface: 'Serial'
SerialPort: 1
TxPin: 'D1'
RxPin: 'D0'
BaudRate: 9600 (bits/s)
NumBytesAvailable: 0
Show all properties, functions
Write data to the serial device with the precision of uint16.
write(serialdevObj,256,'uint16');Input Arguments
Serial device connection specified as a device object.
Data to write to the serial device, specified as a scalar or
vector. The range of the values in the array is based on the
precision.
Data precision, specified as one of the following character vectors:
'uint8''int8''uint16''int16''uint32''int32''uint64''int64'
Data can be also be specified in the following formats:
hexadecimalbinarycharstring
For example, write(serialdevObj,0x28) writes data in
hexadecimal and write(serialdevObj,0b0010) writes data in
binary.
More About
Use
writein a MATLAB® Function block with the Simulink® Support Package for Arduino® Hardware to generate code that can be deployed on Arduino Hardware.Values of
dataInis not validated against theprecision. ThedataInvalues will be saturated when it goes beyond the range of the specifiedprecision.
Version History
Introduced in R2019b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)