Program: Penman Plotter
This program in Example 11-10 is
an outgrowth of the
Plotter
class from Section 8.12.
It connects to a Penman plotter. These
serial-port plotters were made in the United Kingdom in the 1980s, so
it is unlikely that you will meet one. However, there are several
companies that still make pen plotters. See Figure 11-4 for a photograph of the plotter in action.
Figure 11-4. Penman plotter in action
Example 11-10. Penman.java
import java.io.*; import javax.comm.*; import java.util.*; /** * A Plotter subclass for drawing on a Penman plotter. * These were made in the UK and sold into North American markets. * It is a little "turtle" style robot plotter that communicates * over a serial port. For this, we use the "Java Communications" API. * Java Communications is a "standard extension" and must be downloaded * and installed separately from the JDK before you can even compile this * program. * */ public class Penman extends Plotter { private final String OK_PROMPT = "\r\n!"; private final int MAX_REPLY_BYTES = 50; // paranoid upper bound private byte b, reply[] = new byte[22]; private SerialPort tty; private DataInputStream is; private DataOutputStream os; /** Construct a Penman plotter object */ public Penman( ) throws NoSuchPortException,PortInUseException, IOException,UnsupportedCommOperationException { super( ); init_comm("COM2"); // setup serial commx init_plotter( ...
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.