I’m using UsbSerial: A serial port driver library for Android v3.0 by Felipe Rabanal as in A dirty and quick example of serial port communication in Android felhr85.
My goal is to write an Xbee API frame to the android USB OTG port where a Coordinator API XBee Series 2 connected via a Sparkfun USB Xbee dongle should transmit it to another Router API Xbee. (The same Coordinator+dongle has no problem receiving on the OTG port and also properly transmits if used on a Windows PC port)
So, I modified the dirty and quick code:
public static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i + 1), 16));
}
return data;
}
Button sendButton = (Button) findViewById(R.id.buttonSend);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (usbService != null) { // if UsbService was correctly bound, Send data
// USE XCTU API FRAME GENERATOR TO DETERMINE STRING
usbService.write(hexStringToByteArray("7E001010010013A20040FC8760FFFE0000486968"));
}
}
});
//The interpretation of the API packet:
//Transmit Request (API 1)
//7E 00 10 10 01 00 13 A2 00 40 FC 87 60 FF FE 00 00 48 69 68
//Start delimiter: 7E
//Length: 00 10 (16)
//Frame type: 10 (Transmit Request)
//Frame ID: 01 (1)
//64-bit dest. address: 00 13 A2 00 40 FC 87 60
//16-bit dest. address: FF FE
//Broadcast radius: 00 (0)
//Options: 00
//RF data: 48 69
//Checksum: 68
Clicking the send button nothing transmits…
Maybe I’m not writing the frame to the android USB port properly? Should I buy a hardware USB analyzer? Any other mistakes in my code, API packet, hardware assumptions, or conceivably XBee configuration?
Please advise. Thanks!