Serial Port problem

G

Guest

Enumeration portList = CommPortIdentifier.getPortIdentifiers();

this command returns an empty Enumeration. Why?

My system is PC with WinXP.
I have 1 parallel and 2 serial ports
 
P

Paul Lutus

- Chameleon - said:
Enumeration portList = CommPortIdentifier.getPortIdentifiers();

this command returns an empty Enumeration. Why?

Probably because of the rest of your code, which you don't show, the version
of Java, which you don't name, the installation of the JAvCommAPI, which
you don't describe, or your system, which you don't describe fully.
My system is PC with WinXP.
I have 1 parallel and 2 serial ports

Are the ports activated in BIOS? How did you install the JavaCommAPI? Where
is the rest of the code that handles the serial ports?
 
G

Guest

Paul Lutus said:
Probably because of the rest of your code, which you don't show

the version of Java, which you don't name
latest

the installation of the JAvCommAPI, which you don't describe
latest

or your system, which you don't describe fully.

I try to communicate with modem in COM1 ("ATDT123456789")
Are the ports activated in BIOS?
yes

How did you install the JavaCommAPI?

from Sun's readme.html. It works fine, but it does not recognize any port.

Where
is the rest of the code that handles the serial ports?



-----------------
void function() {
try {
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
CommPortIdentifier potId =
CommPortIdentifier.getPortIdentifier("COM1"); // exception
while (portList.hasMoreElements())
{ //
never true
CommPortIdentifier portId = (CommPortIdentifier)
portList.nextElement(); // never run
..........................
}
} catch(Exception ex) {
}
}
 
W

William Brogden

Enumeration portList = CommPortIdentifier.getPortIdentifiers();

this command returns an empty Enumeration. Why?

My system is PC with WinXP.
I have 1 parallel and 2 serial ports

The usual reason is that your JVM is not finding the
javax.comm.properties file. As I recall, it should be in
JAVA_HOME/lib

Bill
 
G

Guest

Enumeration portList = CommPortIdentifier.getPortIdentifiers();

this command returns an empty Enumeration. Why?

My system is PC with WinXP.
I have 1 parallel and 2 serial ports
As a first thought, have you initialized the comm driver.
I forgot and couldn't see any ports until I used this:

String driverName = "com.sun.comm.Win32Driver";
try{
CommDriver commdriver =
(CommDriver)Class.forName(driverName).newInstance();
commdriver.initialize();
}
catch (Exception e2)
{
e2.printStackTrace();
}

If this doesn't help maybe you could post your code.
 
G

Guest

Enumeration portList = CommPortIdentifier.getPortIdentifiers();
As a first thought, have you initialized the comm driver.
I forgot and couldn't see any ports until I used this:

String driverName = "com.sun.comm.Win32Driver";
try{
CommDriver commdriver =
(CommDriver)Class.forName(driverName).newInstance();
commdriver.initialize();
}
catch (Exception e2)
{
e2.printStackTrace();
}

If this doesn't help maybe you could post your code.

I have javax.comm.properties file inside <java dir>\lib directory and this
file have this line inside:
 
J

JScoobyCed

-------------
Your code works and thankyou, but why I must load dynamically this driver?
If I want to run this code in Linux or other platform?

Thanks again!

Err... JavaCOM API is using a native library: win32comm.dll on Win
plateforms, and something I don't rememeber .so on Solaris.
For Linux and MacOS X (and actually also Win), you need the RXTX port of
the JavaCOM API AND the solaris .so library. I have successfully used
this port on RedHat, MacOS 10.2 and 10.3.
http://users.frii.com/~jarvi/rxtx/download.html

There are other ports, but I never tested them.
 
T

Tor Iver Wilhelmsen

Enumeration portList = CommPortIdentifier.getPortIdentifiers();

this command returns an empty Enumeration. Why?

Sadly, the API implementation silently fails if the DLL isn't found.

Try locating the COMM-API related DLL and put it in a directory you
reference in the "java.library.path" system property.
 
G

Guest

I have javax.comm.properties file inside <java dir>\lib directory and this
file have this line inside:
-------------
Driver=com.sun.comm.Win32Driver
-------------
Your code works and thankyou, but why I must load dynamically this driver?
If I want to run this code in Linux or other platform?

Thanks again!
If that works my first thought would be that you do not have your java
lib path set up correctly. What environment/IDE are you developing in?
Do you have multiple JREs installed and if so have you installed the
Java comm api in the one ypu are running?
 
G

Guest

Enumeration portList = CommPortIdentifier.getPortIdentifiers();
If that works my first thought would be that you do not have your java
lib path set up correctly. What environment/IDE are you developing in?
Do you have multiple JREs installed and if so have you installed the
Java comm api in the one ypu are running?

I have 3 JRE in my machine.
1 with Borland J Builder
1 the original from Sun
1 with Mathematica

I have installed comm in both Borland J Builder and Sun's stand-alone
 
G

Guest

I have 3 JRE in my machine.
1 with Borland J Builder
1 the original from Sun
1 with Mathematica

I have installed comm in both Borland J Builder and Sun's stand-alone
After a quick google I found this:

What you have to do is to copy
1) win32com.dll to directory : JBuilder3/bin
2) javax.comm.properties to directory : JBuilder3/jre/lib
3) comm.jar to directory : JBuilder3/lib

http://forum.java.sun.com/thread.jsp?thread=14251&forum=8&message=35130

I hope this helps.
 
G

Guest

Enumeration portList = CommPortIdentifier.getPortIdentifiers();
After a quick google I found this:

What you have to do is to copy
1) win32com.dll to directory : JBuilder3/bin
2) javax.comm.properties to directory : JBuilder3/jre/lib
3) comm.jar to directory : JBuilder3/lib

http://forum.java.sun.com/thread.jsp?thread=14251&forum=8&message=35130

I hope this helps.


YES! IT WORKS NOW!
JBuilder has 2 directories with "lib", JBuilder3 and jdk1.4
I was installed java.comm.properties in jdk1.4\lib (not in jbuilder3\lib)

THANKS A LOT FOR YOUR TIME
I was installed not in JBuilder directory
 
Joined
May 23, 2008
Messages
1
Reaction score
0
Hi all
i also encounter this problem when using CommPortIdentifier.getPortIdentifiers();

its return nothing..

i using a usb serial converter and the OS i using is win XP pro
and java version is 1.6
 
Joined
Sep 16, 2010
Messages
1
Reaction score
0
On Ubuntu 10.04

Dear Paul Lutus,

I have installed Javax.comm
and also the rxtx followed an howto

But could never make it work:

Code:
System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyUSB0"); 
		//System.setProperty("os.name", "Linux-all-ports");
		 String driverName = "gnu.io.RXTXCommDriver";
		try{
		 CommDriver commdriver =
		(CommDriver)Class.forName(driverName).newInstance( );
		commdriver.initialize();
		}
		catch (Exception e2)
		{
		e2.printStackTrace();
		 }
		 
		portList = CommPortIdentifier.getPortIdentifiers();
		System.out.println(portList.hasMoreElements());

it returns a false, list is always empty.

Though I have tried changing the version of rxtx, tried recompiling RXTXCommDriver.java as well following another recommendation from another forum but couldn't rebuild the RXTXcomm.jar successfully. (now re-using backup)

Though:
laptop:/dev$ ls ttyS* ttyUSB*
ttyS0 ttyS1 ttyS100 ttyS2 ttyS3 ttyUSB0

=> So the ports do exist actually.

And javax.comm.properties file is in JAVA_HOME/lib

I need to send data through my usb-serial adapter on linux.
The thread is quite old but I hope you still can help me.

Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top