23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

public abstract int getMode()<br />

public abstract int setMode(int mode) throws<br />

UnsupportedCommOperationException<br />

<strong>Java</strong> I/O<br />

Attempts to set the port to an unsupported mode will throw an Unsupported-<br />

CommOperationException .<br />

17.5.2 Controlling the Parallel Port<br />

Data is sent to the parallel port and its attached device using the output stream returned by the<br />

CommPort class's getOutputStream() method. You can interrupt this data by sending the<br />

appropriate signals out the parallel port to the printer. The suspend() and restart()<br />

methods send these signals:<br />

public abstract void restart()<br />

public abstract void suspend()<br />

These are generally interpreted as stopping and restarting printing. You normally suspend and<br />

restart printing if the printer reports an error. These methods do not automatically start a print<br />

job over from the beginning. You are still responsible for sending the printer whatever data it<br />

needs to print from whatever point it was printing or from the point where you want to restart<br />

printing.<br />

17.5.3 Checking the State of the Port<br />

The original parallel port allowed printers to send only a few predefined messages. Each<br />

message was sent by raising the voltage on a specific wire connecting the port to the printer.<br />

These messages are always sent from the printer to the CPU, never in the other direction.<br />

Therefore, <strong>Java</strong> only allows you to check the state of each of these pins, not to set them. The<br />

methods are:<br />

public abstract boolean isPaperOut()<br />

public abstract boolean isPrinterBusy()<br />

public abstract boolean isPrinterSelected()<br />

public abstract boolean isPrinterTimedOut()<br />

public abstract boolean isPrinterError()<br />

Each of these methods returns true if the matching wire is showing voltage relative to<br />

ground, false if it isn't.<br />

There is also a getOutputBufferFree() method that returns the number of bytes currently<br />

available in the parallel port's output buffer—in other words, the number of bytes you can<br />

write before the buffer fills up:<br />

public abstract int getOutputBufferFree()<br />

17.5.4 Parallel Port Events<br />

Although you can check the various pins used to send information from a printer to the<br />

computer whenever you want to, it's more convenient to be able to do it asynchronously. The<br />

<strong>Java</strong> Comm API supports asynchronous notification of activity occurring on parallel ports.<br />

The model used for notification is the same one used for <strong>Java</strong>Beans, the <strong>Java</strong> 1.1 AWT, and<br />

454

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!