Embedded Freaks..

August 7, 2008

Enumerating serial port (using RxTX)

Filed under: java — Tags: , , — kunilkuda @ 5:53 am

This is simple code to enumerate your serial port names.

public static String[] listSerialPorts() {

    Enumeration ports = CommPortIdentifier.getPortIdentifiers();
    ArrayList portList = new ArrayList();
    String portArray[] = null;
    while (ports.hasMoreElements()) {
        CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
        if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    portArray = (String[]) portList.toArray(new String[0]);
    return portArray;

If the serial ports are not detected, use this option as execution parameter: -Dgnu.io.rxtx.SerialPorts=/dev/ttyACM0:/dev/ttyUSB0:/dev/<your port name>

1 Comment »

  1. Is this applicable to J2ME?

    Comment by kawaii — February 22, 2011 @ 6:57 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: