Reputation: 1
I'm sending information to an Arduino Nano from an Android device. bulkTransfer
returns the correct value (length of data transmitted) but the Arduino receives strange values. I think it is because the baud rate of the Arduino (9600) is different from the baud rate the Android is transmitting, but I can't find the way to know which is this value.
So I have tried to call controlTransfer
to set the baud rate of the Android but controlTransfer always return -1. I don't understand why bulkTransfer
works but controlTransfer
fails.
I'm using this code:
public int sendData(byte[] nbyte) throws IOException, NullPointerException {
if(nbyte == null) throw new NullPointerException("nbyte cannot be null");
int result = this.usbDeviceConnection.controlTransfer(0x40, 0, 0, 0, null, 0, 0);// reset
result = this.usbDeviceConnection.controlTransfer(0x40, 0, 1, 0, null, 0, 0);// clear Rx
result = this.usbDeviceConnection.controlTransfer(0x40, 0, 2, 0, null, 0, 0);// clear Tx
result = this.usbDeviceConnection.controlTransfer(0x40, 0x03, 0x4138, 0, null, 0, 0);
int len = this.usbDeviceConnection.bulkTransfer(this.usbEndpoint, nbyte, nbyte.length, 5000);
if(len == -1) throw new IOException("Bulktransfer failed");
return len;
}
Upvotes: 0
Views: 687