MATLAB ヘルプ センター
データを Bluetooth デバイスに書き込む
write(device,data)
write(device,data,datatype)
write(device,data) は、行ベクトルまたは列ベクトル data を Bluetooth® 接続 device に書き込みます。
device
data
例
write(device,data,datatype) は、data の形式に関係なく、datatype で指定された形式で data を書き込みます。
datatype
すべて折りたたむ
近くの 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 をデバイスに書き込みます。
1:10
write(device,1:10)
デバイスがループバック デバイスとして設定されているため、デバイスに書き込むデータは MATLAB® に返されます。すべてのデータを読み取ります。
read(device,10)
ans = 1×10 1 2 3 4 5 6 7 8 9 10
string "helloworld" をデバイスに書き込みます。
"helloworld"
write(device,"helloworld","string")
デバイスがループバック デバイスとして設定されているため、デバイスに書き込みまれるデータが MATLAB に返されます。データの最初の 5 つの値を string として読み取ります。
read(device,5,"string")
ans = "hello"
read コマンドをもう一度使用して、データの次の 5 つの値を読み取ります。
read
ans = "world"
bluetooth
Bluetooth デバイスの接続。bluetooth オブジェクトとして指定します。
例: write(device,10) は、Bluetooth 接続 device に書き込みます。
write(device,10)
N
数値または ASCII データ。1 行 N 列の数値ベクトルとして、あるいはテキストの文字ベクトルまたは string スカラーとして指定します。数値型のすべての datatype について、data は値の行ベクトルです。
例: write(device,300) は値 300 を書き込みます。
write(device,300)
300
データ型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string
single
double
int8
int16
int32
int64
uint8
uint16
uint32
uint64
char
string
"uint8"
"int8"
"uint16"
"int16"
"uint32"
"int32"
"uint64"
"int64"
"single"
"double"
"char"
"string"
各値のサイズと形式。文字ベクトルまたは string として指定します。datatype は、各値について書き込むバイト数と、MATLAB データ型としてのそれらのバイトの解釈を決定します。
読み込みまたは書き込み操作では、データ転送のためにデータ型が uint8 に変換されます。転送後、データ型は指定された datatype に戻ります。
例: write(device,1:5,"double") は値 [1,2,3,4,5] を double データとして書き込みます。
write(device,1:5,"double")
[1,2,3,4,5]
データ型: char | string
R2020b で導入
writeline
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 のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
ヨーロッパ
アジア太平洋地域
最寄りの営業オフィスへのお問い合わせ