Hi! I need to communicate Android with microcontrollers plate (USB HID device). Avaliable default endpoint 0 and endpoint IN. I need to send data by control endpoint 0, but i have a problem with it. Functions controlTransfer() returns right values of sent bytes. But data doesn receive device.Where can be a misstake?
Java:
public int write_msg (long cmd, int ver, int device_control) {
synchronized (this) {
final int BUF_LEN = 8;
// Длина запроса
byte buf[] = new byte[BUF_LEN];
for (int i = 0; i < BUF_LEN; i++)
buf[i] = 0;
buf[0] = (byte)0xFF;
buf[1] = (byte)0x01;
buf[2] = (byte)(cmd >> 24);
buf[3] = (byte)(cmd >> 16);
buf[4] = (byte)(cmd >> 8);
buf[5] = (byte)(cmd);
buf[6] = (byte)ver;
buf[7] = (byte)device_control;
int res = mConnection.controlTransfer(0x21,
0x9,
0x03,
0,
buf,
buf.length,
200);
lgView.append("set: " + res + "\n");
try {
TimeUnit.MILLISECONDS.sleep(10);
} catch (InterruptedException e) {
//Handle exception
lgView.append("Error: exception - sleep(10ms)! \n");
}
res = mConnection.controlTransfer(0xA1,
0x01,
0x03,
0,
buf,
buf.length,
200);
lgView.append("get: " + res + "\n" + "Rx buf [0-1]: " +
buf[0] + " " +
buf[1] + "\n");
}