Methods Summary |
---|
public void | drawString(java.lang.String mesg)
send("L" + mesg + "\r"); expect(OK_PROMPT);
|
private void | expect(char s)Expect a given CHAR for a result
byte b;
try {
for (int i=0; i<MAX_REPLY_BYTES; i++){
if ((b = is.readByte()) == s) {
return;
}
System.err.print((char)b);
}
} catch (IOException e) {
System.err.println("Penman:expect(char "+s+"): Read failed");
System.exit(1);
}
System.err.println("ARGHH!");
|
private void | expect(java.lang.String s)Expect a given String for a result
byte ans[] = new byte[s.length()];
System.err.println("expect " + s + " ...");
try {
is.read(ans);
} catch (IOException e) {
System.err.println("Penman:expect(String "+s+"): Read failed");
System.exit(1);
};
for (int i=0; i<s.length() && i<ans.length; i++)
if (ans[i] != s.charAt(i)) {
System.err.println("MISMATCH");
break;
}
System.err.println("GOT: " + new String(ans));
|
private void | init_comm(java.lang.String portName)Set up communication.
XXX: Should probably re-use CommPortOpen instead.
// get list of ports available on this particular computer.
// Enumeration pList = CommPortIdentifier.getPortIdentifiers();
// Print the list. A GUI program would put these in a chooser!
// while (pList.hasMoreElements()) {
// CommPortIdentifier cpi = (CommPortIdentifier)pList.nextElement();
// System.err.println("Port " + cpi.getName());
// }
// Open a port.
CommPortIdentifier port =
CommPortIdentifier.getPortIdentifier(portName);
// This form of open takes an Application Name and a timeout.
tty = (SerialPort) port.open("Penman Driver", 1000);
// set up the serial port
tty.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
tty.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_OUT|
SerialPort.FLOWCONTROL_RTSCTS_OUT);
// Get the input and output streams
is = new DataInputStream(tty.getInputStream());
os = new DataOutputStream(tty.getOutputStream());
|
private void | init_plotter()
send("I"); expect('!"); // eat VERSION etc., up to !
send("I"); expect('!"); // wait for it!
send("H"); // find home position
expect('!"); // wait for it!
send("A"); // Set to use absolute coordinates
expect('!");
curx = cury = 0;
penUp();
|
public void | moveTo(int absx, int absy)move to absolute location
System.err.println("moveTo ["+absx+","+absy+"]");
curx = absx;
cury = absy;
send("M" + curx + "," + cury + ","); expect(OK_PROMPT);
|
public void | penColor(int c)
penColor = (c%3)+1; // only has 3 pens, 4->1
System.err.println("PenColor is ["+penColor+"]");
send("P" + c + ","); expect(OK_PROMPT);
|
public void | penDown()
setPenState(false);
send("D"); expect(OK_PROMPT);
|
public void | penUp()
setPenState(true);
send("U"); expect(OK_PROMPT);
|
public void | rmoveTo(int incrx, int incry)Move to a relative location
moveTo(curx + incrx, cury + incry);
|
private void | send(java.lang.String s)Send a command to the plotter. Although the argument is a String,
we send each char as a *byte*, so avoid 16-bit characters!
Not that it matters: the Penman only knows about 8-bit chars.
System.err.println("sending " + s + "...");
try {
for (int i=0; i<s.length(); i++)
os.writeByte(s.charAt(i));
} catch(IOException e) {
e.printStackTrace();
}
|
public void | setFont(java.lang.String fName, int fSize)
// Font name is ignored for now...
// Penman's size is in mm, fsize in points (inch/72).
int size = (int)(fSize*25.4f/72);
send("S"+size + ","); expect(OK_PROMPT);
System.err.println("Font set request: " + fName + "/" + fSize);
|
private void | setPenState(boolean up)
penIsUp = up;
System.err.println("Pen Up is ["+penIsUp+"]");
|