cbumpste
asked on
Listing Comm ports on WinXP SP2
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.getPort Identifier ("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.getPort Identifier ("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
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.getPort
System.out.println("COM" + portNumber);
portNumber++;
}
}
catch (NoSuchPortException ex) {
// Break out of loop.
}
// List parallel (LPT) ports.
try {
int portNumber = 1;
while (true) {
CommPortIdentifier.getPort
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
'as' in the above should be 'is'... :-)
Such that:
Ignoring exceptions is VERY BAD practice!
Such that:
Ignoring exceptions is VERY BAD practice!
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("Except ion: " + ex);
}
and see if you get any error messages.
> catch (NoSuchPortException ex) {
> // Break out of loop.
> }
to
catch (NoSuchPortException ex) {
System.out.println("Except
}
and see if you get any error messages.
make sure you corectly installed the javacomm dll and properties file as per the install document.
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.
Bah... objects was faster.
ASKER
Thanks guys,
I added the exception that you suggested. I got the following:
javax.comm.NoSuchPortExcep tion
at javax.comm.CommPortIdentif ier.getPor tIdentifie r(CommPort Identifier .java:105)
at NamedPortLister.main(Named PortLister .java:8)
Exception: javax.comm.NoSuchPortExcep tion
Exception: javax.comm.NoSuchPortExcep tion
No such port? I have a physical port on my laptop.
I have Administrator rights on the box.
Cheers,
Craig
I added the exception that you suggested. I got the following:
javax.comm.NoSuchPortExcep
at javax.comm.CommPortIdentif
at NamedPortLister.main(Named
Exception: javax.comm.NoSuchPortExcep
Exception: javax.comm.NoSuchPortExcep
No such port? I have a physical port on my laptop.
I have Administrator rights on the box.
Cheers,
Craig
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
girionis,
The jre directory under the jdk directory was missing those files. Bugger!
Thanks again everyone!!!
The jre directory under the jdk directory was missing those files. Bugger!
Thanks again everyone!!!
:)
ASKER
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
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
Add a:
ex.printStackTrace();
to each catch to see what is going on