Solved

Listing Comm ports on WinXP SP2

Posted on 2006-07-03
11
789 Views
Last Modified: 2010-05-18
Hi,

I have the following code from the book Java I/O:

import javax.comm.*;
public class NamedPortLister {
  public static void main(String[] args) {
    // List serial (COM) ports.
    try {
      int portNumber = 1;
      while (true) {
        CommPortIdentifier.getPortIdentifier("COM" + portNumber);
        System.out.println("COM" + portNumber);
        portNumber++;
      }

    }
    catch (NoSuchPortException ex) {
      // Break out of loop.
    }
    // List parallel (LPT) ports.
    try {
      int portNumber = 1;
      while (true) {
        CommPortIdentifier.getPortIdentifier("LPT" + portNumber);
        System.out.println("LPT" + portNumber);
        portNumber++;
      }
    }
    catch (NoSuchPortException ex) {
      // Break out of loop.
    }
  }
}

I have tried Netbeans & the command line. Both compile and *seem* to run, however there is no output??
Running WinXp SP2
Java Comm 2.0
JDK 1.5.07

Cheers,
Craig
0
Comment
Question by:cbumpste
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 17029443
You are probably getting an exception, which you are ignoring. Ignoring as VERY BAD practice!

Add a:
ex.printStackTrace();
to each catch to see what is going on
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 17029449
'as' in the above should be 'is'... :-)

Such that:
Ignoring exceptions is VERY BAD practice!
0
 
LVL 35

Expert Comment

by:girionis
ID: 17029452
Try to code the catch block, it might be going in there, i.e. not finding any port. Change this

>  catch (NoSuchPortException ex) {
>       // Break out of loop.
>     }

to

catch (NoSuchPortException ex) {
     System.out.println("Exception: " + ex);
    }

and see if you get any error messages.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 92

Expert Comment

by:objects
ID: 17029494
make sure you corectly installed the javacomm dll and properties file as per the install document.
0
 
LVL 35

Expert Comment

by:girionis
ID: 17029502
And make sure the javax.comm.properties is in the correct place (<jdk>/lib), otherwise have a look in the installation instructions for alternative locations.
0
 
LVL 35

Expert Comment

by:girionis
ID: 17029506
Bah... objects was faster.
0
 

Author Comment

by:cbumpste
ID: 17029575
Thanks guys,

I added the exception that you suggested. I got the following:


javax.comm.NoSuchPortException
        at javax.comm.CommPortIdentifier.getPortIdentifier(CommPortIdentifier.java:105)
        at NamedPortLister.main(NamedPortLister.java:8)
Exception: javax.comm.NoSuchPortException
Exception: javax.comm.NoSuchPortException

No such port? I have a physical port on my laptop.
I have Administrator rights on the box.

Cheers,
Craig
0
 
LVL 35

Accepted Solution

by:
girionis earned 125 total points
ID: 17029610
Try the following:

1) Copy the javax.comm.properties into your $JAVA_HOME/jre/lib folder
2) copy the win32com.dll into your $JAVA_HOME/bin

and try again.
0
 

Author Comment

by:cbumpste
ID: 17029643
girionis,

The jre directory under the jdk directory was missing those files. Bugger!

Thanks again everyone!!!
0
 
LVL 35

Expert Comment

by:girionis
ID: 17029656
:)
0
 

Author Comment

by:cbumpste
ID: 17029658
Guys,

Sorry that it appears that only a single person can be assigned points.

The tips on the printing exceptions were good as well.

Cheers,
Craig
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java Restore security prompts not working 10 271
JAVA API design with micro service cloud in mind 1 116
Html Table Looping (part 2) 5 42
Java List 4 77
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question