Chapter 1: Introducing the Java Communication API


Java provides Java Communication Application Programming Interface (JCA), which contains classes and interfaces that help you develop platform-independent communication applications based on technologies, such as voice, mail, fax, or smart cards. JCA provides the javax.comm package, which contains interfaces, classes, and exception classes to interact with the RS232 serial and parallel ports. The serial ports are also called COM ports.

Apart from serial and parallel ports, there exists other type of ports such as Universal Serial Bus (USB) ports. A USB port provides just one standard plug-in for all peripherals in comparison to serial or parallel ports, which provide more than one plug-in for individual devices. A USB port enables you to detect the USB enabled device without restarting your computer.

This chapter explains the RS232 standards for serial ports. It also explains JCA and its classes and interfaces, and describes how to install and set up JCA.

The RS232 Standard

RS232 is a standard that specifies how serial ports communicate. The javax.comm package enables you to develop applications that interact with the devices attached to RS232 serial ports. The RS232 communication standard is based on asynchronous serial communication, which means that communication between the sending device and the receiving device occurs bit by bit. The sending device needs to send the start bit and the stop bit to mark the start and the end of a message.

RS232 Bits Streams

According to the RS232 standard, the port driver breaks the data that needs to be sent into data words. The length of the data words can range from five to eight bits per word. To correctly synchronize the word transfer, the port driver adds some additional bits to the word for error checking. In addition, it is important that the number of bits sent by the sending device must be equal to number of bits received by the receiving device. The additional bits sent with the words are of various types, such as:

  • Start bit: Represents the start of a data word. The start bit does not represent the data word that needs to be sent; it is the starting point of the data word. The space line recognizes the start bit.

  • Data bit: Represents a bit from the data word. After sending the start bit, the communication application sends the data bits to a data word.

  • Parity bit: Represents a bit in the data word for error detection. After sending the data word, the communication application automatically adds a parity bit to the data word. The sending device calculates the value of the parity bit based on the information that it sends. The receiving device also performs the same calculation as the sending device and checks if the actual parity bit value is the same as the calculated value.

  • Stop bit: Represents the end of the data word. All data bits and parity bits are within the start and stop bits.

Physical Properties of the RS232 Cable

The RS232 standards define the physical properties of the RS232 cable, such as the voltage level at which the bit will be sent and the maximum length of the cable for communication to take place. The RS232 standards define two states of signal level, high bit and low bit. A negative voltage identifies the high bit state and a positive voltage identifies a low bit state. RS232 also defines standards for the maximum cable length. Per RS232 standards, the maximum cable length is 50 feet. This standard allows communication to occur at the optimum speed.

Error Detection

To detect errors during communication, both the sending and the receiving device calculate the value of the parity bit. If the value of the parity bit after calculation is the same at both ends, the communication is error-free; otherwise, it is not. It is mandatory for both the sender and the receiver to use the same algorithms to check the value of the parity bits sent with the data word. The two types of parity checking are:

  • Even parity: In even parity, the number of data bits sent contains an even number of logical 1s. If the number of high data bits is even, the communication application adds a low parity to a communication message; otherwise, the communication application adds a high parity bit.

  • Odd parity: The odd parity bit is similar to the even parity bit but in odd parity, the number of high bits is always odd.

Communicating Using the Serial Device

Serial devices communicate using a serial port, which transfers data one bit at a time using a single wire in a data cable. The serial port on a computer supports full-duplex communication. This means that the port can send and receive data at the same time. To send and receive data separately, serial ports use separate wires.

A device attached to a serial port starts communicating by first sending a start bit. The start bit signifies that the data or message is about to start. The device can send five, six, seven, or eight data bits, based on the agreed number of bits, between the device and the serial port. The device and a port must agree on the number of data bits to be sent and received. After data has been sent, the device sends a stop bit to indicate that the transfer of data bits is over. A stop bit has a value of one.

Communicating Using the Parallel Device

Parallel devices communicate using a parallel port, which simultaneously transfers eight bits over eight separate wires in a data cable. The parallel port consists of a connector with 17 signal lines and 8 ground lines. The signal lines include Control, Status, and Data lines.

The Control lines act as an interface control. These lines enable handshaking of signals from the computer to the device attached to a parallel port. The Status lines help in indicating the status of the device attached to the computer, such as printer busy, paper empty, and interface or peripheral errors. The Data lines provide data from the computer to the device attached to a parallel port, such as printer.




Developing Applications Using JCA
Developing Applications Using JCA
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 43

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net