write
Description
Examples
Write and Read Data with Bluetooth Device
Create a connection to a nearby Bluetooth device. In this example, the HC-06 Bluetooth module is configured as a loopback device.
device = bluetooth("HC-06")
device = bluetooth with properties: Name: "HC-06" Address: "98D331FB3B77" Channel: 1 NumBytesAvailable: 0 NumBytesWritten: 0 Show all properties
Write the values 1:10
to the device.
write(device,1:10)
Since the device is configured as a loopback device, the data you write to the device is returned to MATLAB®. Read all the data.
read(device,10)
ans = 1×10 1 2 3 4 5 6 7 8 9 10
Specify Data Type to Write and Read with Bluetooth Device
Create a connection to a nearby Bluetooth device. In this example, the HC-06 Bluetooth module is configured as a loopback device.
device = bluetooth("HC-06")
device = bluetooth with properties: Name: "HC-06" Address: "98D331FB3B77" Channel: 1 NumBytesAvailable: 0 NumBytesWritten: 0 Show all properties
Write the string "helloworld"
to the device.
write(device,"helloworld","string")
Since the device is configured as a loopback device, the data written to the device is returned to MATLAB. Read the first five values of data as a string.
read(device,5,"string")
ans = "hello"
Use the read
command again to read the next five values of
data.
read(device,5,"string")
ans = "world"
Input Arguments
device
— Bluetooth device connection
bluetooth
object
Bluetooth device connection, specified as a bluetooth
object.
Example: write(device,10)
writes to the Bluetooth connection device
.
data
— Numeric or ASCII data
1-by-N
numeric array | character vector | string scalar
Numeric or ASCII data, specified as a 1-by-N vector of numeric values or as a
character vector or string scalar of text. For all numeric datatype
types, data
is a row vector of values.
Example: write(device,300)
writes the value
300
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| char
| string
datatype
— Size and format of each value
"uint8"
(default) | "int8"
| "uint16"
| "int16"
| "uint32"
| "int32"
| "uint64"
| "int64"
| "single"
| "double"
| "char"
| "string"
Size and format of each value, specified as a character vector or string.
datatype
determines the number of bytes to write for each value
and the interpretation of those bytes as a MATLAB data type.
For any read or write operation, the data type is converted to
uint8
for the data transfer. After the transfer, the data type
reverts to the specified datatype
.
Example: write(device,1:5,"double")
writes the values
[1,2,3,4,5]
as double data.
Data Types: char
| string
Version History
Introduced in R2020b
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)