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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:26:22+00:00 2026-05-19T10:26:22+00:00

I am trying to display the available ports in my computer using the following

  • 0

I am trying to display the available ports in my computer using the following codes..

public static void test(){

    Enumeration lists=CommPortIdentifier.getPortIdentifiers();
        System.out.println(CommPortIdentifier.PORT_SERIAL);
        System.out.println(lists.hasMoreElements());
        while (lists.hasMoreElements()){
            CommPortIdentifier cn=(CommPortIdentifier)lists.nextElement();

            if ((CommPortIdentifier.PORT_SERIAL==cn.getPortType())){
                System.out.println("Name is serail portzzzz "+cn.getName()+" Owned status "+cn.isCurrentlyOwned());

                try{
                    SerialPort port1=(SerialPort)cn.open("ComControl",800000);
                    port1.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                    System.out.println("Before get stream");
                    OutputStream out=port1.getOutputStream();
                    InputStream input=port1.getInputStream();
                    System.out.println("Before write");
                    out.write("AT".getBytes());
                    System.out.println("After write");
                    int sample=0;
                    //while((( sample=input.read())!=-1)){
                    System.out.println("Before read");
                        //System.out.println(input.read() + "TEsting ");
                    //}
                        System.out.println("After read");
                    System.out.println("Receive timeout is "+port1.getReceiveTimeout());
                }catch(Exception e){
                    System.err.println(e.getMessage());
                }
            }

            else{
                System.out.println("Name is parallel portzzzz "+cn.getName()+" Owned status "+cn.isCurrentlyOwned()+cn.getPortType()+"    ");
            }
        }

}

My output is always ;

1
false

It is not looping though the while (lists.hasMoreElements()){

///
)

What could be the possible problems?

  • 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-19T10:26:23+00:00Added an answer on May 19, 2026 at 10:26 am

    You are missing the driver:

    String driverName = "com.sun.comm.Win32Driver";
    CommDriver commdriver =
    (CommDriver) Class.forName(driverName).newInstance();
    commdriver.initialize();
    

    Let know if you need more code or this is enough to get you started.

    OR

    have this file javax.comm.properties in your class path
    With this content:
    Driver=com.sun.comm.Win32Driver

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

Sidebar

Related Questions

I am trying to display a list of products available on a public-facing website.
I'm trying to check if the username is available and display it for the
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
I'm trying to display an svg graph with associated javascript in my application using
I am trying to display all the images available in a blackberry device inside
I am trying to display a 2-dimensional array. int arr[numRows][numCols] = {{0,1,2,3,4,5,6},{7,8,9,10,11,12,13},{14,15,16,17,18,19,20}}; void display(int
I was trying the following example, but with external URLs: Using WebViews The example
I'm trying to display an image from a webcam in my app using HJCache
I am trying to display all the fonts available in the system with its
Im trying to display some files in a web page so the user can

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.