portio Serial and Parallel Port Driver

Java(TM) Edition

Table of Contents

Class Overview
Example User Code
Package Installation
Known Bugs

Forward...
The portio package defines an API for accessing serial and parallel ports from Java applications and applets. Currently, there is only one implementation, which is for Central Data's EtherLite(R) product line. Due to the nature of the EtherLite products, the entire serial/parallel port driver for it can be implemented in Java, using no native methods. Central Data is making portio source code available to the public, so that anyone may implement versions that support other serial or parallel port hardware in existence (see our Software License Agreement). Any comments or suggestions regarding portio should be sent to portio engineering.


Class Overview

The following list describes the different portio classes. The discussion only covers serial ports. Where applicable, a corresponding Parallel class can be used instead.


Example User Code

Some example Java code which starts an EtherLiteDriver, opens a port, changes the baud rate and character size from the default, and sends out 256 bytes of data follows. Note that the only change needed to do the same operations with any other implementation of PortDriver would be to change the third line, which selects the specific PortDriver to be used.

// make driver for EtherLite device with host name "EtherLite1"
EtherLiteDriver driver = null;
try { driver = new EtherLiteDriver( "EtherLite1" ); }
catch( PortIOException e ) {
    System.out.println( "Failed making driver: " + e );
    System.exit(1);
}

// get information about the device
PortDriverInfo info = driver.getDriverInfo();
if( info.serialCount == 0 ) {
    System.out.println( "No serial ports on device" );
    System.exit(1);
}

// make some arrays to hold objects related to each serial port
SerialPort port[] = new SerialPort[info.serialCount];
InputStream in[] = new InputStream[info.serialCount];
OutputStream out[] = new OutputStream[info.serialCount];

// open the first serial port
try { port[0] = new SerialPort( driver, 0 ); }
catch( PortIOException e ) {
    System.out.println( "Failed opening port: " + e );
    System.exit(1);
}
in[0] = port[0].getInputStream();
out[0] = port[0].getOutputStream();

// choose settings we want and then change them at the port
SerialPortParams params = new SerialPortParams();
params.inBaud = params.outBaud = 115200;
params.charSize = 8;
try { port[0].setParams( params ); }
catch( PortIOException e ) {
    System.out.println( "Failed setting params: " + e );
    System.exit(1);
}

// create a block of data to send out and then send it!
byte outBuf[] = new byte[256];
for( int i = 0; i < 256; i++ ) outBuf[i] = (byte)i;
try { out[0].write( outBuf ); }
catch( IOException e ) {
    System.out.println( "Failed write to port: " + e );
    System.exit(1);
}

// close the port neat and clean after releasing objects
SerialPort thisPort = port[0];
port[0] = null;
in[0] = null;
out[0] = null;
try { thisPort.close(); }
catch( PortIOException e ) {
    System.out.println( "Failed closing port: " + e );
    System.exit(1);
}

This is a very simple example of accessing a serial port. More extensive operations can be performed, as detailed in the documentation for the portio package.


Package Installation


Known Bugs

The portio package has been tested with Java 1.0.2 and 1.1 on the Windows(R) 95 platform with EL-8+ and EL-16 devices. It has also been tested with Java 1.0.2 on the Solaris platform with EL-16 devices.

There are no known bugs at this time. If you experience a bug with the EtherLite implementation of portio, or if you have suggested improvements for this package, please email portio engineering.


EtherLite is a registered trademark of Central Data Corporation. Java is a trademark or registered trademark of Sun Microsystems, Inc. in the U.S. and other countries.