Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Opening up new ports to Java with javax.comm

Sometimes a simple set of APIs can be exceptionally powerful

I was introduced to the javax.comm package of classes when I discovered they were used in the development kit for the Java Ring. (For details on javax.comm, see Rinaldo Di Giorgio's Java Developer column in the May issue of JavaWorld: "Java gets serial support with the new javax.comm package.") During my mad rush at JavaOne to get a program into my ring, I ran into a variety of problems, not the least of which was communicating with the ring. I downloaded the distribution from the Java Developer Connection and tried unsuccessfully to use it to talk to the Java Ring. Later, I discovered the problem with my ring: I didn't have Dallas Semiconductor's legacy APIs installed correctly. With the ring working, I basically forgot about the communications package. That is, until one weekend about a month ago, which is the starting point for this story.

For many different reasons (mostly having to do with highly interactive simulated environments -- for example, games), the primary computer in my "lab" runs Windows 95. However, on this particular weekend I was more concerned with another computer that, in many ways, was about as powerful as the Java Ring: a Digital Equipment Corporation PDP-8/e.

The PDP-8 was arguably the first true personal computer. Designed in the late 1960s and produced in relatively high quantities in the 70s, the PDP-8 could be lifted by a single individual, was powered by 120-volt line current, and cost less than 0,000. Most of these computers shipped with a single peripheral: a Teletype Model ASR-33 terminal -- the original "TTY" in computer lingo.

The ASR-33 teletype was a printing terminal that came with a paper-tape reader and punch. Yep, it was paper tape, 1"-wide paper with holes punched in it, that was the primary storage medium for programs on the PDP-8.

The PDP-8 was the first computer I ever programmed and therefore it has a special place in my heart. Further, due to some fortuitous circumstances, I was in the right place at the right time and managed to save a PDP-8 that was going to be scrapped as junk. A photograph of my prize is shown below.

A Digital Equipment Corporation PDP-8/e

On this special weekend not too long ago, I decided to bring the PDP-8 back to life, if only to relive those precious early memories and to show my daughter just how good she has it with her "measley old 133-MHz Pentium."

Reviving one classic by simulating another

To begin my revival effort, I had to get a program into the PDP-8. On the PDP-8, this is achieved by following a three-step process:

  1. Using the front-panel switches, the user "keys" a short program into the magnetic core memory. This program is called the RIM Loader, and its purpose is to load another program from paper tape that is in Read-in-Mode, or RIM, format.

  2. RIM Loader loads the paper tape in RIM format. This tape contains a program called a BIN Loader, which can load programs from paper tape in binary (BIN) format.

  3. Finally, you run BIN Loader to load the program you really want, which is on a paper tape in BIN format. Whew!


After going through these three steps, the program you want to run is stored in core memory. All the user needs to do then is set the starting address and tell the machine to "go."

In my effort to revive the machine, Step 1 was no problem, but Step 2 involved the use of the paper-tape reader in the Teletype -- and I didn't have a Teletype. Of course, I did have my desktop computer, so the logical step was to simulate a paper tape reader on my desktop.

From a logical and programming standpoint, simulating a paper-tape reader is trivial. You simply read a file that contains the data from the "tape," send it out to a serial port at 110 baud (yes, only 10 characters per second), until you have exhausted the file. I could write a program in C on my Solaris system or my FreeBSD system in about 10 minutes that could do this -- but, remember, I was on a Windows 95 system, not a Unix system.

From bad to ugly and back again

I knew I could easily write this program in C, so that was my language of choice. Bad choice. I brought up my copy of Visual C++ 5.0 and whipped out a simple program called sendtape.c that called open() on the communications port. I tried to set it into RAW mode (the mode in Unix where the operating system doesn't try to interpret anything on the serial port as user input) and then tried to compile it. Whoops, no ioctl() function or tty functions -- nada, zip, zilch!

No problemo, I thought to myself, "I've got the whole Microsoft Software Developer's Network library on CD with my C compiler; I will do a quick search on the keywords 'COM port'."

The search turned up many references to the Microsoft Component Object Model (also called COM), and also references to MSComm. MSComm is a C++ class that Microsoft supplies to talk to the serial ports. I looked at the examples and was appalled at how much code it would take to do such a simple thing as write bytes to the serial port at 110 baud. All I wanted to do was open the darned serial port, set its baud rate, and stuff a few bytes down it -- not create a new class of serial communications-enhanced applications!

Sitting in front of my monitor was the Blue Dot receptor for my Java Ring, and I thought to myself, "Aha! The folks at Dallas Semiconductor have figured out how to talk to a serial port on the PC. Let's see what they do." After looking through the company's source code for Win32, it was clear that talking to serial ports was not going to be a simple task.

Java to the rescue

At this point in my weekend, I was thinking perhaps I'd drag one of my Unix machines to the lab in order to code the program on it instead of using what I already had. Then I remembered my experience with the Java Ring and the java.comm package from Sun. I decided to pursue that avenue instead.

What does java.comm provide?

The Java Communications API -- or java.comm -- provides a platform-independent method for accessing serial and parallel ports from Java. As with other Java APIs such as JFC, JDBC, and Java 3D, a certain level of indirection is forced on the programmer to isolate the platform's idea of "what a serial port is" from the programming model. In the case of the javax.comm design, items like device names, which vary from platform to platform, are never used directly. The three interfaces of the API provide platform-independent access to serial and parallel ports. These interfaces provide method calls to list the available communication ports, control shared and exclusive access to ports, and control specific port features such as baud rate, parity generation, and flow control.

1 | 2 | 3 | 4 |  Next >
Resources
  • Example program from the javax.comm distribution http://www.javaworld.com/jw-09-1998/indepth/SimpleWrite.java
  • A paper tape reader simulator for loading PDP-8 programs from a Java-capable computer http://www.javaworld.com/jw-09-1998/indepth/SendTape.java
  • Rinaldo Di Giorgio devoted his JavaWorld May issue Java Developer column to javax.comm in "Java gets serial support with the new javax.comm package" http://www.javaworld.com/jw-05-1998/jw-05-javadev.html
  • Early access pages on Java Developer Connection (registration required) http://developer.java.sun.com/developer/earlyAccess/index.htm
  • Early access versions of the Java Communications API (registration required) http://developer.java.sun.com/developer/earlyAccess/communications.html
  • Doug Jones' page describing the PDP-8's history and pointers to his FTP archive http://www.cs.uiowa.edu/~jones/pdp8/
  • Previous Java In Depth articles http://www.javaworld.com/topicalindex/jw-ti-indepth.html