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 8790605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:42:08+00:00 2026-06-13T22:42:08+00:00

So I’ve implemented the Android USB Accessory API such that I can plug in

  • 0

So I’ve implemented the Android USB Accessory API such that I can plug in my phone to my laptop running linux and it puts the phone into USB Accessory mode. Then I can access the accessory, open it, and begin reading an writing to it. My code looks almost identical to the example in the documentation. The main difference is that I’m using separate read and write methods and accessing them via JNI from native code.

Here’s where it gets interesting. After successfully reading/writing for a second or two, the bulk transfer writes from my laptop starts giving timeout errors and then the read call to the USB Accessory in Android throws an IOException with the ENODEV error code. This is with the cable still connected and UsbManager still lists the Accessory in the list, and I still have permission for it.

To add to the oddness of it, I discovered that if I put a 100ms sleep in the read loop, the problem basically goes away (though it still happens on occasion). Having the sleep in there is not just a horrible kludge, but it introduces an intolerable latency into my app. The lower the sleep time, the less effective the hack is, to where it’s ineffective at 10ms of sleep time.

I’m transmitting around 20-30kbps of real-time data using bulk transfers (but not so real-time that a bulk transfer won’t suffice), and the transfer size ranges from 50 to 800 bytes at about 20-30Hz. Could it be a limitation of USB? I don’t have a ton of experience with it, so I’m basically treating it about the same as a network socket. Should I queue up smaller messages and send them off together in less frequent but larger transfers? Is there a problem with small, high-ish frequency bulk transfers? I’ll look into this, but I’m basically grasping at straws here.

Hardware:

  • Laptop is running Ubuntu 10.04 and using libusb 1.0.0.
  • Phone is Galaxy Nexus S running stock Android 4.1.2.
  • 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-13T22:42:09+00:00Added an answer on June 13, 2026 at 10:42 pm

    So, while I still don’t understand everything that is going on, implementing a double-buffering scheme fixed my problem.

    I discovered that a Java Android App reading at full speed had no issues with the ENODEV problem, which lead me to the conclusion that the Java Native Interface was the root of my problems.

    Previously, I was reading from the UsbAccessory directly from methods called from the JNI in a polling fashion. Something about the transition from native code to Java and then from Java down to the native Android kernel apparently made everything grumpy.

    My fix was to read/write to the UsbAccessory from Java-only threads (no JNI calls) and then buffer that data to read/write from the methods called by JNI.

    Seems to work like a charm. Before I was getting send timeouts very consistently on the accessory side, and then eventually the IOExeception on the Android side as outlined above, and now I get no timeouts, no IOExceptions. I’m still a little curious what exactly causes that behavior, but I suspect it requires strong JNI Kung-fu to understand.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this

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.