Nexus 7 から接続された USB HID デバイスに 16 進数データを送信しようとしていますが、Android SDK メソッドは byte[] バッファでのみ機能します。
bulkTransfer または controlTransfer を使用して 10 進文字列値として生成される 16 進データを送信するにはどうすればよいですか?
message[0]= 0;
message[1]= 166;
message[2]= 2;
message[3]= 252;
message[4]= 255;
SDK メソッド:
bulkTransfer(UsbEndpoint endpoint, byte[] buffer, int length, int timeout)
controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int length, int timeout)
このように: http://pure-basic.narod.ru/article/pickit2.html、デバイスを使用した PC アプリケーションは正常に動作します。
OutBuffer(0)=0
OutBuffer(1)=$A6 ; EXECUTE_SCRIPT
OutBuffer(2)=2
OutBuffer(3)=$FC ; _VDD_GND_OFF
OutBuffer(4)=$FF ; _VDD_ON
更新 - 回答
private void sendData() {
//byte b = (byte) 129; // (byte) 0x81 Also work
int status = connection.bulkTransfer(endPointWrite, toByte(129), 1, 250);
}
private static byte toByte(int c) {
return (byte) (c <= 0x7f ? c : ((c % 0x80) - 0x80));
}
// for received data from USB HID device
private static int toInt(byte b) {
return (int) b & 0xFF;
}