How to get list of available ports in my pc?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phpuser123
    New Member
    • Dec 2009
    • 108

    #1

    How to get list of available ports in my pc?

    I just run some codes to get a list of available ports n my cmputer and it returned me false when I have 3 com ports that are free. How do I solve this prob?

    My codes:

    Code:
    public static void main(String[] args) {
            //SerialParameters params=new SerialParameters();
           // System.out.println(CommPortIdentifier.PORT_SERIAL );
            Enumeration portList = CommPortIdentifier.getPortIdentifiers();
            System.out.println(portList.hasMoreElements());
            while(portList.hasMoreElements()){
                System.out.println("Has more elements");
                 CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
                   if (portId.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
                        System.out.println(portId.getName());
                   }
                   else{
                         System.out.println(portId.getName());
                   }
                
            }
    }
    Output :
    false
    Last edited by Niheel; Dec 20 '10, 06:42 PM.
Working...