1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| 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();
}
}
}
} |
Partager