Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java Comm Problem

Status
Not open for further replies.

NeilV

Programmer
Oct 14, 2002
117
GB
Hi,

I am trying to write an application to read from the COM port on my PC using the java communications api. However, when I try to enumerate the ports on my Windows 2000 PC it doesn't return any ports.. Here is my Code:

import javax.comm.*;
import java.util.*;

public class PortList {
public static void main(String [] args){

Enumeration portList = CommPortIdentifier.getPortIdentifiers();

while(portList.hasMoreElements()) {
CommPortIdentifier portId = (CommPortIdentifier)portList.nextElement();
if( portId.getPortType() ==
CommPortIdentifier.PORT_SERIAL)
{
System.out.println("Serial port: " +
portId.getName());
} else if (portId.getPortType() ==
CommPortIdentifier.PORT_PARALLEL)
{
System.out.println("Parallel port: " +
portId.getName());
} else
System.out.println("Other port: " +
portId.getName());
}
}
}

What am I doing wrong??

Neil
 
Your code is fine. I ran it on my Win2000 box with no problem.

Make sure the win32com.dll that came with the java comm library is in your winnt/system32 folder. It won't work without it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top