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

  • Home
  • SEARCH
  • 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 7950121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:10:19+00:00 2026-06-04T02:10:19+00:00

I am trying to send and receive data over USB, my device, the Acer

  • 0

I am trying to send and receive data over USB, my device, the Acer Iconia A500 has everything needed to connect to the device and everything, that is fine and works properly, but when I try sending and receiving data it doesn’t behave as expected. This is my code

for( ; ; ) { //this is the main loop for transferring   
    String get = "$getPos";
    byte[] getBytes = get.getBytes();
    conn.bulkTransfer( epOUT, getBytes, getBytes.length, 500 );

    try {
        Thread.sleep( 500 );
        byte[] buffer = new byte[4096];
        conn.bulkTransfer( epIN, buffer, 4096, 500 );
        StringBuilder byStr = new StringBuilder();

        for( int i = 0; i < buffer.length; i++ ) {
            if( buffer[i] != 0 ) {
                byStr.append( buffer[i] + ", " );
            }
        }

        l( byStr );
    }
    catch( InterruptedException e ) {
        e.printStackTrace();
    }

    if( mStop ) {
        mStopped = true;
        return;
    }

    l( "sent " + counter );
    counter++;
    counter = (byte)( counter % 16 );
}

Its meant to return an Array of bytes about 80 characters long but it only returns two bytes back which are 1 and 96, if there was a error on the USB devices end it would still return a few more then two. Is my code even close to correct? I based it of the USB to serial article by serverbox.

  • 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-04T02:10:21+00:00Added an answer on June 4, 2026 at 2:10 am

    I was trying to send data over the wrong baud rate.

    Here’s the code that works. Posting it for everyone who is using FTDI devices and needs help.

    private Runnable mLoop = new Runnable() {
    
            @Override
            public void run() {
                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;
    
                conn.controlTransfer(0x40, 0, 0, 0, null, 0, 0);// reset
                                                                // mConnection.controlTransfer(0×40,
                                                                // 0, 1, 0, null, 0,
                                                                // 0);//clear Rx
                conn.controlTransfer(0x40, 0, 2, 0, null, 0, 0);// clear Tx
                conn.controlTransfer(0x40, 0x02, 0x0000, 0, null, 0, 0);// flow
                                                                        // control
                                                                        // none
                conn.controlTransfer(0x40, 0x03, 0x0034, 0, null, 0, 0);// baudrate
                                                                        // 57600
                conn.controlTransfer(0x40, 0x04, 0x0008, 0, null, 0, 0);// data bit
                                                                        // 8, parity
                                                                        // none,
                                                                        // stop bit
                                                                        // 1, tx off
    
                UsbEndpoint epIN = null;
                UsbEndpoint epOUT = null;
    
                byte counter = 0;
    
                UsbInterface usbIf = dev.getInterface(0);
                for (int i = 0; i < usbIf.getEndpointCount(); i++) {
                    l("EP: "
                            + String.format("0x%02X", usbIf.getEndpoint(i)
                                    .getAddress()));
                    if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
                        l("Bulk Endpoint");
                        if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)
                            epIN = usbIf.getEndpoint(i);
                        else
                            epOUT = usbIf.getEndpoint(i);
                    } else {
                        l("Not Bulk");
                    }
                }
    
                for (;;) {// this is the main loop for transferring
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    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];
    
                    StringBuilder str = new StringBuilder();
    
                    if (conn.bulkTransfer(epIN, buffer, 4096, 500) >= 0) {
                        for (int i = 2; i < 4096; i++) {
                            if (buffer[i] != 0) {
                                str.append((char) buffer[i]);
                            } else {
                                l(str);
                                break;
                            }
                        }
    
                    }
                    // this shows the complete string
                    l(str);
    
                    if (mStop) {
                        mStopped = true;
                        return;
                    }
                    l("sent " + counter);
                    counter++;
                    counter = (byte) (counter % 16);
                }
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to figure out how to send and receive XML Data over
i'm trying to send/receive data over wifi to an iphone/ipodtouch app from a C#
I'm trying to send binary data from a database over an ASP.NET page. I
I'm trying to create a client-server program that send and receive a string (its
I have a class that Handles send & receive over a socket between my
I'm trying write a java program to send live microphone data over UDP, then
I am trying to send/receive some data across 2 computers (mac, ubuntu) using a
I'm trying to send a network packet of data to a hardware device. I
I'm trying to send and receive using pipes: send.cpp struct { long a; long
For about a year now, I've had problems trying to send and receive email

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.