Snafu: Comm Ports auflisten (librxtx-java unter Debian Lenny)

Hallo!
Wollte mal versuchen mit Java die serielle Schnittstelle anzusprechen. Hab also zuerst mal ein kleines Prog geschrieben, dass mir die CommPorts auflisten soll.
Um es kurz zu machen, es geht nicht wirklich. Statt mir die CommPorts aufzulisten spuckt es irgendwelche Infos über die librxtx aus.
Kann mir wer helfen? Weiß nicht so recht, was ich falsch mache.

Ausgabe vom Programm:


> java Comm  

Comm Ports  
Experimental:  JNI_OnLoad called.  
Stable Library  
=========================================  
Native lib Version = RXTX-2.1-7  
Java lib Version   = RXTX-2.1-7  
  
Source:  
~~~java
import gnu.io.*;  
import java.util.Enumeration;  
  
public class Comm  
{  
        public static void listPorts()  
        {  
                Enumeration ports = CommPortIdentifier.getPortIdentifiers();  
                while(ports.hasMoreElements()) {  
                        CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();  
                        String type;  
                        if(port.getPortType() == CommPortIdentifier.PORT_SERIAL)  
                                type = "Serial";  
                        else  
                                type = "Parallel";  
                        System.out.println("Type: " + type + " Name: " + port.getName());  
  
                }  
        }  
  
        public static void main(String[] args)  
        {  
                System.out.println("Comm Ports");  
                listPorts();  
                System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");  
        }  
}
--
LG,
Snafu
  1. Hallo Snafu,

    ich nutze (die alte) Bib javacomm von SUN unter Windows. Mit dieser erhalte ich mit nachfolgendem Code:

      
    import java.io.*;  
    import java.util.*;  
    import javax.comm.*;  
    public class TestClass  {  
        static CommPortIdentifier portId;  
        static Enumeration portList;  
      
        InputStream inputStream;  
        SerialPort serialPort;  
        Thread readThread;  
      
        public static void main(String[] args) {  
            portList = CommPortIdentifier.getPortIdentifiers();  
      
            while (portList.hasMoreElements()) {  
                portId = (CommPortIdentifier) portList.nextElement();  
                System.out.println(  portId.getPortType()+"  "+portId.getName() );  
            }  
        }  
      
    }  
    
    

    folgende Ausgabe (auf einem VISTA-Rechner):

    1  COM4  
    1  COM3  
    2  LPT1  
    2  LPT2
    

    Mit RXTX habe ich es damals auch nicht hinbekommen?! Vll kannst Du aber auch die andere Erweiterung nutzen. Im Code sehe ich zumindest auch keinen Fehler.

    Mit freundlichem Gruß
    Micha

    --
    simple JavaScript Spiele: Snake, MineSweeper, Sudoku oder Tetris