write
データを Bluetooth デバイスに書き込む
説明
例
近くの Bluetooth デバイスへの接続を作成します。この例では、HC-06 Bluetooth モジュールはループバック デバイスとして設定されます。
device = bluetooth("HC-06")device =
bluetooth with properties:
Name: "HC-06"
Address: "98D331FB3B77"
Channel: 1
NumBytesAvailable: 0
NumBytesWritten: 0
Show all properties
値 1:10 をデバイスに書き込みます。
write(device,1:10)
デバイスがループバック デバイスとして設定されているため、デバイスに書き込むデータは MATLAB® に返されます。すべてのデータを読み取ります。
read(device,10)
ans = 1×10
1 2 3 4 5 6 7 8 9 10近くの Bluetooth デバイスへの接続を作成します。この例では、HC-06 Bluetooth モジュールはループバック デバイスとして設定されます。
device = bluetooth("HC-06")device =
bluetooth with properties:
Name: "HC-06"
Address: "98D331FB3B77"
Channel: 1
NumBytesAvailable: 0
NumBytesWritten: 0
Show all properties
string "helloworld" をデバイスに書き込みます。
write(device,"helloworld","string")
デバイスがループバック デバイスとして設定されているため、デバイスに書き込みまれるデータが MATLAB に返されます。データの最初の 5 つの値を string として読み取ります。
read(device,5,"string")ans =
"hello"read コマンドをもう一度使用して、データの次の 5 つの値を読み取ります。
read(device,5,"string")ans =
"world"入力引数
Bluetooth デバイスの接続。bluetooth オブジェクトとして指定します。
例: write(device,10) は、Bluetooth 接続 device に書き込みます。
数値または ASCII データ。1 行 N 列の数値ベクトルとして、あるいはテキストの文字ベクトルまたは string スカラーとして指定します。数値型のすべての datatype について、data は値の行ベクトルです。
例: write(device,300) は値 300 を書き込みます。
データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string
各値のサイズと形式。文字ベクトルまたは string として指定します。datatype は、各値について書き込むバイト数と、MATLAB データ型としてのそれらのバイトの解釈を決定します。
読み込みまたは書き込み操作では、データ転送のためにデータ型が uint8 に変換されます。転送後、データ型は指定された datatype に戻ります。
例: write(device,1:5,"double") は値 [1,2,3,4,5] を double データとして書き込みます。
データ型: char | string
バージョン履歴
R2020b で導入
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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)