Discovering comm ports

From Rxtx

(Difference between revisions)
Jump to: navigation, search
 
(47 intermediate revisions not shown)
Line 1: Line 1:
-
Hi guys,
+
This code snippet shows how to find out the available comms ports on your computer.:
-
I found so much useful things here.
+
-
Thank you.  
+
-
[http://tylka.extra.hu/mature-sluts.html mature british sluts] |
+
<pre>
-
[http://tylka.extra.hu/mature-galleries.html adult galleries mature women] |
+
import gnu.io.*;
-
[http://tylka.extra.hu/mature-boobs.html busty mature fucking] |
+
    static void listPorts()
-
[http://tylka.extra.hu/mature-ladies.html classy mature ladies]
+
    {
 +
        java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
 +
        while ( portEnum.hasMoreElements() )
 +
        {
 +
            CommPortIdentifier portIdentifier = portEnum.nextElement();
 +
            System.out.println(portIdentifier.getName()  +  " - " +  getPortTypeName(portIdentifier.getPortType()) );
 +
        }       
 +
    }
 +
   
 +
    static String getPortTypeName ( int portType )
 +
    {
 +
        switch ( portType )
 +
        {
 +
            case CommPortIdentifier.PORT_I2C:
 +
                return "I2C";
 +
            case CommPortIdentifier.PORT_PARALLEL:
 +
                return "Parallel";
 +
            case CommPortIdentifier.PORT_RAW:
 +
                return "Raw";
 +
            case CommPortIdentifier.PORT_RS485:
 +
                return "RS485";
 +
            case CommPortIdentifier.PORT_SERIAL:
 +
                return "Serial";
 +
            default:
 +
                return "unknown type";
 +
        }
 +
    }
 +
</pre>
 +
 
 +
Please note that on Ubuntu 11.04, the Arduino Uno and possibly others are recognised as /dev/ttyACMxx .
 +
The RXTX library only searches through /dev/ttySxx, so you need to make symlinks if your distro does the same,
 +
so for example ln -s /dev/ttyACM0 /dev/ttyS33 .
 +
 
 +
Besides that, you need to close the serial port after starting, to prevent Linux from making new devices, like /dev/ttyACM2.
 +
Do not forget to remove the lock file from /var/lock if you forgot to close the port.

Latest revision as of 00:35, 15 June 2011

This code snippet shows how to find out the available comms ports on your computer.:

import gnu.io.*;
    static void listPorts()
    {
        java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
        while ( portEnum.hasMoreElements() ) 
        {
            CommPortIdentifier portIdentifier = portEnum.nextElement();
            System.out.println(portIdentifier.getName()  +  " - " +  getPortTypeName(portIdentifier.getPortType()) );
        }        
    }
    
    static String getPortTypeName ( int portType )
    {
        switch ( portType )
        {
            case CommPortIdentifier.PORT_I2C:
                return "I2C";
            case CommPortIdentifier.PORT_PARALLEL:
                return "Parallel";
            case CommPortIdentifier.PORT_RAW:
                return "Raw";
            case CommPortIdentifier.PORT_RS485:
                return "RS485";
            case CommPortIdentifier.PORT_SERIAL:
                return "Serial";
            default:
                return "unknown type";
        }
    }

Please note that on Ubuntu 11.04, the Arduino Uno and possibly others are recognised as /dev/ttyACMxx . The RXTX library only searches through /dev/ttySxx, so you need to make symlinks if your distro does the same, so for example ln -s /dev/ttyACM0 /dev/ttyS33 .

Besides that, you need to close the serial port after starting, to prevent Linux from making new devices, like /dev/ttyACM2. Do not forget to remove the lock file from /var/lock if you forgot to close the port.

Personal tools