ヘルプ センターヘルプ センター
Bluetooth デバイスからの ASCII 文字列データ行の読み取り
R2020b 以降
data = readline(device)
例
data = readline(device) は、Bluetooth® 接続 device からの終端文字の最初の出現まで ASCII データを読み取り、data を終端文字なしで string として返します。関数が device の Timeout プロパティで指定された期間内にデータを返せない場合は、0 行 0 列の double の [] として data を返します。この関数は、終端文字に到達するかタイムアウトが発生するまで、MATLAB® の実行を一時停止します。
data
device
[]
すべて折りたたむ
近くの 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
既定の ASCII 終端文字をチェックします。
device.Terminator
ans = "LF"
終端文字を "CR" に設定し、ASCII データの文字列を書き込みます。関数 writeline は、終端文字をデータに自動的に追加します。
writeline
configureTerminator(device,"CR") writeline(device,"hello")
終端文字が自動的に追加された別の ASCII データの文字列を書き込みます。
writeline(device,"world")
デバイスがループバック デバイスとして設定されているため、デバイスに書き込むデータは MATLAB に返されます。ASCII データ文字列を読み取ります。関数 readline は、終端文字に到達するまでデータを返します。
readline
readline(device)
ans = "hello"
ASCII データ文字列をもう一度読み取り、書き込んだ 2 つ目の文字列を返します。
ans = "world"
Bluetooth 接続をクリアします。
clear device
bluetooth
Bluetooth デバイスの接続。bluetooth オブジェクトとして指定します。
例: data = readline(device) は、Bluetooth 接続 device から ASCII データを読み取ります。
R2020b で導入
read
configureTerminator
次の MATLAB コマンドに対応するリンクがクリックされました。
コマンドを MATLAB コマンド ウィンドウに入力して実行してください。Web ブラウザーは 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:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office