I try to create an application that can communicate with a USB msp430 microcontroller USB (HID class), so I try to send the letter T for récupperer the current date in the microcontroller (asynchronous). when I call the "getLokerTime" function, the application crashes. I think it is because of "if (connection.requestWait () == request)" because when I put in the comments provided, the application does not crash.
can you help me?
void getLokerTime(UsbDeviceConnection connection){
int bufferMaxLength=endPointWrite.getMaxPacketSize();
ByteBuffer buffer = ByteBuffer.allocate(bufferMaxLength);
UsbRequest request = new UsbRequest(); // create an URB
request.initialize(connection, endPointWrite);
buffer.putChar('T');
// queue the outbound request
boolean retval = request.queue(buffer, 1);
Toast.makeText(getApplicationContext(), " envoi de la donnée " + retval , Toast.LENGTH_SHORT).show();
if (connection.requestWait() == request) {
//if(retval == true){
// wait for confirmation (request was sent)
UsbRequest inRequest = new UsbRequest();
// URB for the incoming data
inRequest.initialize(connection, endPointRead);
// the direction is dictated by this initialisation to the incoming endpoint.
if(inRequest.queue(buffer, bufferMaxLength) == true){
connection.requestWait();
// wait for this request to be completed
// at this point buffer contains the data received
byte[] dst = new byte[8];
buffer.get(dst);
buffer.clear();
String contenu;
//byte[] data = buffer.array();
//String str = new String( data);
try {
contenu = new String(dst , "UTF-8");
Toast.makeText(getApplicationContext(), " le contenu du buffer : " + contenu , Toast.LENGTH_SHORT).show();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}