1

USB msp430 マイクロコントローラー USB (HID クラス) と通信できるアプリケーションを作成しようとしているので、マイクロコントローラーで現在の日付を受信するために文字 T を送信しようとしています (非同期)。「getLokerTime」関数を呼び出すと、アプリケーションがクラッシュします。提供されたコメントを入力すると、アプリケーションがクラッシュしないため、「if (connection.requestWait () == request)」が原因だと思います。

手伝って頂けますか?

void getLokerTime(UsbDeviceConnection接続){

    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();
                }




             }
        }

}
4

0 に答える 0