0

これは本当に頭をぶつけています。Android アプリから BluetoothChatService を介して、無線トランシーバーのシリアル入力に接続されたシリアル Bluetooth アダプターに英数字データを送信しています。

AT コマンドを使用してオンザフライで無線を構成しようとする場合を除いて、すべて正常に動作します。AT+++ (コマンド モードに入る) は正常に受信されましたが、次の 2 つのコマンドの拡張 ASCII 文字に問題があります。コマンド モードを終了するには、CCh ATO が必要です。

以前のプロトタイプで PIC basic のシリアル コマンドを使用して無線を構成したことがあり、ハイパータームから直接コマンドを入力して構成することもできるため、無線を構成できることはわかっています。これらの方法はどちらも、厄介な CCh をラジオが理解できる形式に何らかの方法で変換します。

私は、次のようなエンコーディングを仕上げるために、Android初心者が思いつく可能性のあるすべてのことを試しました。

private void command_address() {
    byte[] addrArray = {(byte) 0xCC, 16, 36, 65, 21, 13};                   
    CharSequence addrvalues = EncodingUtils.getString(addrArray, "UTF-8");  
    sendMessage((String) addrvalues);
}

しかし、何があっても、その上位バイト (CCh/204/-52) を正常に動作させることができないようです。他のすべての (< 127) バイト、コマンドまたはデータは問題なく送信されます。ここで何か助けていただければ幸いです。

-デイブ

4

1 に答える 1

0

Welll ... turns out the BluetoothChat code re-creates the byte array with message.getBytes() before sending to the service. (after all, being chat code it would normally source only regular ascii strings) As others on this site have pointed out, getBytes() can create encoding issues in some cases. So, for purposes of sending these extended-ascii commands, I don't mess with strings and just send the byte array to the service with

private void sendCommand(byte[] cmd) {
    mChatService.write(cmd);
}

The so-called command array is first initialized with placeholders for the hex radio address elements

byte[] addrArray = {(byte) 0xCC, 16, 0, 0, 0, 13};

and then filled in with the help of the conversion method

radioArray = HexStringToByteArray(radioAddr1);

which can be found here: HexStringToByteArray@stackoverflow

于 2011-01-11T15:41:08.260 に答える