Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7958289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:23:57+00:00 2026-06-04T04:23:57+00:00

I have been trying to figure this out for a while now, but every

  • 0

I have been trying to figure this out for a while now, but every way I have seen just doesn’t work, I am trying to send some string data to a USB device, the device should either send back the data I wanted or send back “bad command” which is about 11 bytes right? For now I am getting back is just 2 bytes, 1 and 192. I am trying to just send 9 bytes in total, “$fdump G” and “/n”. No matter what I do it just doesn’t work.

Here’s my code as well, I am not sure how to change the bytes to a string or char but I will do that once I start getting back data because I know that what is meant to return is at least 11 bytes.

for(;;){//this is the main loop for transferring    

                String get = "$fDump G\n";
                l("Sending: " + get);

                byte[] by = get.getBytes();

                //This is where it sends
                l("out " + conn.bulkTransfer(epOUT, by, by.length, 500));

                //This is where it is meant to receive
                byte[] buffer = new byte[4096];
                l("in " + conn.bulkTransfer(epIN, buffer, 4096,500));

                StringBuilder byStr = new StringBuilder();

                //This shows what's coming in
                for(int i = 0; i < buffer.length; i++){
                    if(buffer[i] != 0){
                    byStr.append(buffer[i]);
                    l(byStr);}
                }
                //this shows the complete string
                l(byStr);

                if(mStop){
                    mStopped = true;
                    return;
                }
                l("sent "+counter);
                counter++;
                counter = (byte) (counter % 16);
            }

I really don’t know why it is not working. I have lots of skill in Android but I just can’t get my head around this.

enIN and enOUT are end points:

epIN = usbIf.getEndpoint(i);

epOUT = usbIf.getEndpoint(i);

Also conn is the USB device connection.

            UsbDevice dev = sDevice;
            if (dev == null)
                return; 
            UsbManager usbm = (UsbManager) getSystemService(USB_SERVICE);
            UsbDeviceConnection conn = usbm.openDevice(dev);
            l("Interface Count: "+dev.getInterfaceCount());
            l("Using "+String.format("%04X:%04X", sDevice.getVendorId(), sDevice.getProductId()));

            if(!conn.claimInterface(dev.getInterface(0), true)) 
                return;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:23:57+00:00Added an answer on June 4, 2026 at 4:23 am
    epIN = usbIf.getEndpoint(i);
    epOUT = usbIf.getEndpoint(i);
    

    If here i (the endpoint index) has the same value for both calls you will end up with the same endpoint. The endpoint however has a direction and can’t be used to send and receive data. As the bulkTransfer() method uses the endpoint address to determine the direction you end up in two reads or two writes respectively.

    Note that the endpoint index in an interface does not match the endpoint address. Interfaces are logical mappings for endpoints (which have hardware addresses).
    I guess you may want to read from IN endpoint 1 (address: 0x81) and write to OUT endpoint 1 (address: 0x01). Therefor you are using the same value for i However IN 1 and OUT 1 are not the same endpoint.

    Examine the device descriptor to find out which endpoint you want to communicate with. The first mentioned endpoint after the interface descriptor is accessible via UsbInterface.getEndpoint(0) regardless of its physical address. Check the direction of that endpoint and use it appropriately. Find the other endpoint using UsbInterface.getEndpoint(1) (assuming they are the two first endpoints in one interface).

    btw: Your byte buffers are too big. The maximum size of bulk transfer packets is 64 bytes for full speed and 512 bytes for high speed devices.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying this for quite a while now, but can't figure it out.
I have been trying to figure this out for a while now and decided
I have been trying for a while now, but I can't figure out how
Okay I've been trying to figure this out for a while now. I have
I have been trying to figure this out for way to long tonight. I
I have been pulling my hair trying to figure this out but nothing is
for the last hour I have been trying to figure this out myself but
I've been trying to figure this out for a couple days now. I have
I have been trying to figure out how all this validation works, but I
I have been trying for a while now trying to figure out how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.