Serial Port Programming

by Scott Preston - 2010-08-19 00:00:00

I am going to talk about accessing the serial port via Java or via an HTTP/Serial Bridge. Accessing serial ports is the preferred method of communication to microcontrollers like the Basic Stamp 2, or Arduino.

This should allow you to access the serial port via a web or high-level language rather than having to use C or C++.

The Java Media Framework

The Java Media Framework, by Oracle (formerly Sun Microsystems), provices native access to the serial port via JNI (Java’s Native Interface). There are two versions of this, one for Windows 2.x and one for Linux 3.x.

You can download both of these here:

Installing On Windows

To install on Windows you will need to do the following:

  1. Unzip the file.
  2. Copy win32com.dll to your \bin directory.
  3. Copy comm.jar to and javax.comm.properties your \lib directory.
  4. Add comm.jar to your CLASSPATH

Installing On Linux

  1. Untar the file.
  2. Copy cp libLinuxSerialParallel.so to /usr/lib
  3. Copy comm.jar and javax.comm.properties to your /jre/lib directory
  4. Add comm.jar to your CLASSPATH

An HTTP Bridge

  1. Follow the instructions for Windows or Linux above.
  2. Email me for the java-bridge client
  3. Run the following program in command line: java -cp scottsbots-bridge.jar com.scottsbots.javabridge 5050, where 5050 is the TCP/IP Port number the bridge will run.