Note that there are some explanatory texts on larger screens.

plurals
  1. POEstablish communication between Android host and USB Device
    primarykey
    data
    text
    <p>i'm trying to implement a bidirectional communication between an android host and a USB device, of course i'm using the USB Host API provided by Google. The USB Device contains a firmware that echoes any character it receives. The user just inserts a character in a EditText and press a Button to send the character. Here is the code</p> <pre><code>public void sendData(View v){ final String character = request.getText().toString() + "\n\r"; log.setText(log.getText() + "\n" + "Sending..."); if(character != null){ Thread t = new Thread(new Runnable() { @Override public void run() { byte[] array = character.getBytes(); Log.d("USB", "Sending Data..."); mDeviceConnection.bulkTransfer(mEndpointOut, array, array.length, 100); ByteBuffer output_buffer = ByteBuffer.allocate(array.length); Log.d("USB", "Creating Buffer"); UsbRequest req = new UsbRequest(); req.initialize(mDeviceConnection, mEndpointIn); req.queue(output_buffer, array.length); if(mDeviceConnection.requestWait() == req){ Log.d("USB", output_buffer.getChar(0) + ""); Message m = new Message(); m.obj = output_buffer.array(); handler.sendMessage(m); output_buffer.clear(); } else{ Log.d("USB", "No USBRequest received"); } } }); t.start(); } } </code></pre> <p>The variable request is the EditText, log is a reference to a TextView so i can show some debbug information. First i send the character using the bulkTransfer method, then i use USBRequest to queue a request to read data on the in endpoint, aparently it send the character correctly, but whe i show the received character, it show some weird symbols, like chinese characters or a rhombus with a question symbol inside (almost always this is the response). I Want to know if the code i use for this communication is correct, and if it is, then why am i receiving that weird characters?</p> <p>Thank you so much for you help</p> <p>PD: Sorry for my english.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload