"Think outside the [B0X]"

Java communication api

Instructions on how to add serial/parallell port support in Java

Install java communication api:

on Ubuntu:

apt-get install librxtx-java

on Windows:
Download x86 or x64 versions from http://www.cloudhopper.com/opensource/rxtx/

Create a java project and add jar to build classpath:


Example code:

import gnu.io.CommPortIdentifier;
import java.util.Enumeration;

public class Main {
   public static void main(String[] args) {
      Enumeration<CommPortIdentifier> ports = CommPortIdentifier.getPortIdentifiers();
      while(ports.hasMoreElements()) {
         System.out.println("Got port:" + ports.nextElement().getName());

Output may look something like:

Stable Library
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
Got port:/dev/ttyS0
Experimental:  JNI_OnLoad called.
BUILD SUCCESSFUL (total time: 0 seconds)

Category: Dev notes

Tagged: , , , ,