Opening a Parallel Port

Problem

You want to open a parallel port.

Solution

Use a CommPortIdentifier ’s open( ) method to get a ParallelPort object.

Discussion

Enough of serial ports! Parallel ports as we know ‘em are an outgrowth of the “dot matrix” printer industry. Before the IBM PC, Tandy and other “pre-PC” PC makers needed a way to hook printers to their computers. Centronics, a company that made a variety of dot matrix printers, had a standard connector mechanism that caught on, changing only when IBM got into the act. Along the way, PC makers found they needed more speed, so they built faster printer ports. And peripheral makers took advantage of this by using the faster (and by now bidirectional) printer ports to hook up all manner of weird devices like scanners, SCSI and Ethernet controllers, and others via parallel ports. You can, in theory, open any of these devices and control them; the logic of controlling such devices is left as an exercise for the reader. For now we’ll just open a parallel port.

Just as the SerialPortOpen program set the port’s parameters, the ParallelPortOpen program sets the parallel port access type or “mode.” Like baud rate and parity, this requires some knowledge of the particular desktop computer’s hardware. There are several common modes, or types of printer interface and interaction. The oldest is “simple parallel port,” which the API calls MODE_SPP. This is an output-only parallel port. Other common modes include EPP (extended parallel port, ...

Get Java Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.