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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:53:52+00:00 2026-05-28T20:53:52+00:00

I have two issues with a serial program on mobile device: InputStream.available() always returns

  • 0

I have two issues with a serial program on mobile device:

  1. InputStream.available() always returns 0 according to documentation. Can’t use DataInputStream because the data might be a file and not a string. If I simply call the read() on the InputStream it’ll block the IO operation if the byte(s) doesn’t exist on the other side. In addition, I don’t know how much is the size of input data. So how do I find if data is available at port and how much is the size of available data?
  2. I’m using hyperterminal to test the serial port and mobile is only responding to AT commands, like ata and atd. So any string like “hello” is ignored and my app can’t see it. so is this true? or I’m missing something? how can I make the data visible to my app?

well any suggestion? code snippets maybe?

  • 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-05-28T20:53:53+00:00Added an answer on May 28, 2026 at 8:53 pm

    You can add a Listener to a SerialPort that gets notified whenever data is available on that port. Inside this callback, in.available() should also return the number of bytes that can be read, but it is probably better to just consume bytes until read return -1.

    final CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM1");
    
    final SerialPort com1 = (SerialPort)portId.open("Test", 1000);
    final InputStream in = com1.getInputStream();
    
    com1.notifyOnDataAvailable(true);
    com1.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    com1.addEventListener(new SerialPortEventListener() {
        public void serialEvent(SerialPortEvent event) {
            if (event.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
                try {
                    byte[] buffer = new byte[4096];
                    int len;
                    while (-1 != (len = in.read(buffer))) {
                        // do something with buffer[0..len]
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm new to JQuery. I have an two issues that I can't figure
I can add a QPixMapImage to a QGraphicsScene, but then I have two issues.
I have two issues both related to (I believe) my SQL Server setup. I
I have found many people with simliar issues but no soultions...basically I have two
I have inherited a middle tier system with some multi-Threading issues. Two different threads,
I have two issues I have ignored so far, but I will really appreciate
I have two issues. I have Ubuntu 10.10 and I have installed git server
I have two issues:- 1. I need to be able to set the value
My code works fine in a way. I have two issues with it though.
I have two issues I'm trying to work though. The first is I'm trying

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.