Connecting Tech Pros Worldwide Forums | Help | Site Map

Com ports not showing up using Java

Member
 
Join Date: Mar 2008
Posts: 114
#1: Oct 11 '09
I'm running a small program that should list all of the comm ports that are available on the computer. The only problem is that nothing is recognized. I've stepped through the program and it jumps over the while .....hasMoreItems. When I set the hasMoreItems to false it executes it. There are no syntax errors and it runs completely, it just doesn't give me the info I need.

Thanks in advance!

Expand|Select|Wrap|Line Numbers
  1. package gps;
  2.  
  3. import javax.comm.*;
  4. import java.util.Enumeration;
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         Enumeration port = CommPortIdentifier.getPortIdentifiers();
  9.         while (port.hasMoreElements()) {
  10.             CommPortIdentifier ports = (CommPortIdentifier) port.nextElement();
  11.             String type="";
  12.             switch (ports.getPortType()) {
  13.                 case CommPortIdentifier.PORT_PARALLEL:
  14.                     type = "Parallel";
  15.                     break;
  16.                 case CommPortIdentifier.PORT_SERIAL:
  17.                     type = "Serial";
  18.                     break;
  19.                 default: /// Shouldn't happen
  20.                     type = "Unknown";
  21.                     break;
  22.             }
  23.             System.out.println(ports.getName() + ": " + type);
  24.         }
  25.     }
  26. }
  27.  

Member
 
Join Date: Mar 2008
Posts: 114
#2: Oct 12 '09

re: Com ports not showing up using Java


Figured it out...this is happening because javax.comm is for solaris systems...Installed rxtxcomm and it works just fine.
Reply