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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

the DTR pin is connected to the DCD and DSR pins. This allows two PCs to communicate<br />

using a communications program and a direct serial connection without any modem. This is<br />

why not all serial cables are created equal, and the cable that works for one device may not<br />

work for another.<br />

Figure 17.3. PC null modem cable<br />

Data is sent from computer to device across the TD line and from device to computer across<br />

the RD line. You access these lines through the output and input streams returned by<br />

CommPort's getOutputStream() and getInputStream() methods. You do not directly<br />

manipulate these pins. The ground pins are used only to maintain a common reference voltage<br />

between the devices. No program ever sends voltage over these lines. This leaves six pins you<br />

may want to read or write. These are:<br />

• DTR<br />

• RTS<br />

• CTS<br />

• DSR<br />

• RI<br />

• CD<br />

Each of these has an effectively boolean value: true if it's showing voltage relative to ground,<br />

false if it isn't. The SerialPort class provides methods to read the current state of all these<br />

pins. It provides methods to write to those pins that would normally be written to by the<br />

computer end of the connection.<br />

17.4.3.1 DTR<br />

Data Terminal Ready, DTR, means the computer is ready to send or receive data. CR,<br />

Computer Ready, would be more likely true nowadays, but the RS-232 standard was<br />

developed in the days of dumb terminals, when personal computers were still an oddity.<br />

public abstract void setDTR(boolean dtr)<br />

public abstract boolean isDTR()<br />

17.4.3.2 RTS<br />

Request To Send, RTS, is one-half of hardware handshaking. The computer raises voltage on<br />

the RTS line to tell the modem it's waiting to send.<br />

448

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

Saved successfully!

Ooh no, something went wrong!