Tuesday, October 27, 2015

Java Simple Serial Connector (jSSC)

Java Simple Serial Connector (jSSC) is a simple library for working with serial ports. This is a good replacement to rxtx library which is not in active development now. Though I am not sure how much jSSC is in active development as I could see in maven a jar from Jan 2014. I would also recommend reading Jim Connor's blog about the state of communications API.

Coming to jSSC library, I will show a simple program to show the list of ports. 



  • First include the jar in pom

                <dependency>
<groupId>org.scream3r</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
 </dependency>


  • Write the program to list the ports

     import jssc.SerialPortList;

     public class PortListing {

public static void main(String[] args) {
//Get the list of port names
String[] ports = SerialPortList.getPortNames();
for(String port: ports){
System.out.println(port);
}
  }
     }

The good thing about this library is that it is self contained and one does not have to copy dll at different places as in rxtx. More examples can be seen at https://code.google.com/p/java-simple-serial-connector/ Though google code has been archived and this project has not found a new home. 

No comments:

Post a Comment