メインコンテンツ

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

write

R2026a

Bluetooth Low Energy 周辺デバイス上の特性または記述子にデータを書き込む

説明

特性の値の書き込み

write(c,data) は、指定した data を、Bluetooth® Low Energy 周辺デバイスの特性に書き込みます。入力 characteristic オブジェクト c の Attributes プロパティは、"Write" と "WriteWithoutResponse" のいずれか、または両方でなければなりません。

例

write(c,data,type) は、デバイスで応答の受信を想定するかどうかを、type を使用して指定します。

例

write(c,data,precision) は書き込まれるデータの精度を指定します。

例

write(c,data,precision,type) は、応答タイプとデータ精度の両方を指定します。

例

記述子の値の書き込み

write(d,data) は、指定した data を、Bluetooth Low Energy 周辺デバイスの記述子に書き込みます。記述子 d の Attributes プロパティには "Write" が含まれていなければなりません。

例

write(d,data,precision) は書き込まれるデータの精度を指定します。

例

例

すべて折りたたむ

Bluetooth Low Energy 周辺デバイス上の特性にデータを書き込みます。

近くにある Bluetooth Low Energy 周辺デバイスへの接続を作成します。

b = ble("DemoDevice")
b = 
  ble with properties:

               Name: "DemoDevice"
            Address: "5A0B858BC07C"
          Connected: 1
           Services: [5×2 table]
    Characteristics: [12×5 table]

Show services and characteristics

"Gender" 特性を表す characteristic オブジェクトを作成します。

c = characteristic(b,"User Data","Gender")
c = 
  Characteristic with properties:

             Name: "Gender"
             UUID: "2A8C"
       Attributes: "Read" "Write"
      Descriptors: []

この特性は読み取りと書き込みが可能であるため、そこにデータを書き込んで値の変化を確認することができます。readを使用して最新のデータを取得します。

data = read(c)
data = 
0

Bluetooth SIG Web サイトの User Data Service にあるこの特性の仕様を参照して、データを解釈します。0 は男性を、1 は女性を表します。女性を示すよう特性に 1 と書き込みます。

write(c,1)

特性から再度読み取って、データの変化を確認することができます。

data = read(c)
data = 
1

Bluetooth Low Energy 周辺デバイス上の記述子にデータを書き込みます。

近くにある Bluetooth Low Energy 周辺デバイスへの接続を作成します。

b = ble("DemoDev")
b = 
  ble with properties:

               Name: "DemoDev"
            Address: "FF548EA5658F"
          Connected: 1
           Services: [5×2 table]
    Characteristics: [10×5 table]

Show services and characteristics

"Heart Rate Measurement" 特性を表す characteristic オブジェクトを作成します。

c = characteristic(b,"Heart Rate","Heart Rate Measurement")
c = 
  Characteristic with properties:

             Name: "Heart Rate Measurement"
             UUID: "2A37"
       Attributes: "Notify"
      Descriptors: [1x3 table]
 DataAvailableFcn: []

Show descriptors

"Client Characteristic Configuration" 記述子を表す descriptor オブジェクトを作成します。

d = descriptor(c,"Client Characteristic Configuration")
d = 
  Descriptor with properties:

          Name: "Client Characteristic Configuration"
          UUID: "2902"
    Attributes: ["Read"    "Write"]

この記述子には、通知または表示が有効か無効かに関する情報が含まれています。readを使用して現在のデータを取得できます。

data = read(d)
data = 1×2

    0    0

Bluetooth SIG Web サイトの Bluetooth Core Specification にあるこの記述子の仕様を参照して、このデータを解釈します。

通知または表示のステータスが変更されると、この値は変化します。たとえば、"Heart Rate Measurement" 特性の通知を有効にするようこの値に書き込みます。次に、記述子を再び読み取って、値の変化を確認します。

write(d,[1 0])
data = read(d)
data = 1×2

    1    0

入力引数

すべて折りたたむ

Bluetooth Low Energy 周辺デバイスの特性。characteristic オブジェクトとして指定します。

特性または記述子に書き込むデータ。スカラーまたは数値配列として指定します。Bluetooth SIG Web サイトにある特性または記述子の仕様を参照して、書き込むデータの種類を決定してください。

例: write(c,[1 0]) は、数値配列を特性 c に書き込みます。

データ型: double | uint8 | uint16 | uint32 | uint64

特性の応答オプション タイプ。"withresponse" または "withoutresponse" として指定します。"withresponse" を指定すると、周辺デバイスでは、書き込みの成功を示すデバイスからの応答が想定されます。"withoutresponse" を指定すると、周辺デバイスでは応答が想定されません。既定値は特性の Attributes プロパティによって異なります。

c.Attributes既定の type
"Write""withresponse"
"WriteWithoutResponse""withoutresponse"
"Write" と "WriteWithoutResponse""withresponse"

例: write(c,5,"withoutresponse") は、応答を受信せずに、データを特性に書き込みます。

データ精度。"uint8"、"uint16"、"uint32"、または "uint64" として指定します。

例: write(d,300,"uint16") は、符号なし 16 ビット整数としてデータを特性に書き込みます。

Bluetooth Low Energy 周辺デバイスの記述子。descriptor オブジェクトとして指定します。

バージョン履歴

R2019b で導入