私はBLE113モジュールにデータを送信するアンドロイドアプリを持っています。どのタイプのタイプが「ユーザー」かというGATT特性を通じてデータを受け取ります。私は文字列としてデータを取得することができます。私が24などの整数を送ると、文字列 '24'として受け取られます。とにかくこの文字列番号を整数型に変換できますか?BGScript:文字列を整数に変換する
これはgatt.xmlのものです。
<characteristic uuid="xxxxx-xxxx-xxxxx-xxxx-xxxxxxxxxx" id="configuration">
<description>Config Register</description>
<properties read="true" write="true"/>
<value type="user" />
</characteristic>
これはAndroid側のスニペットで、整数値 '1'を書きます。
String str = "1";
try {
byte[] value = str.getBytes("UTF-8");
chara.setValue(value);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
.
.
.
boolean status = mBluetoothGatt.writeCharacteristic(chara);
BGScript側でデータを整数 '1'として受信したいとします。私は変換に何か悪いことをしていますか?整数を送るのを助けてください。
GATT特性のタイプ 'USER'で何かをしなければなりませんか? 'hex'または 'utf-8'に変更すると、問題は解決されますか? chara
は型であると仮定すると、あなたのAndroidプロジェクトで
<characteristic uuid="xxxxx-xxxx-xxxxx-xxxx-xxxxxxxxxx" id="configuration">
<description>Config Register</description>
<properties read="true" write="true"/>
<value type="hex">00</value>
</characteristic>
、:そのようなgatt.xmlファイルで
使用しているサンプルコードを追加してください。送信時と受信時の両方簡単な型変換の問題にぶち当たっているかもしれません。 – SJoshi
こんにちは、私はスニペットで質問を編集しました。ありがとうTed –