The Java Communication API (JCA) supports the javax.comm package, which provides the CommPortIdentifier class to control access to communications ports. For example, you can determine the ports attached to a computer, open any specific port for Input/Output (I/O) operations, view the description of the port, and determine the ownership of the port by using methods in the CommPortIdentifier class.
This chapter explains how to develop a Port Information application, which uses the javax.comm package to list all the serial and parallel ports attached to a computer and provide information on ports selected by an end user. It also explains how to open the ports for Input/Output (I/O) operations.
The Port Information application uses the following files:
PortDescription.java: Creates a user interface that an end user can use to list the parallel and serial ports, open a selected port, and view the description of the selected port.
ShowDescriptionWindow.java: Displays the tabular description of the selected serial or parallel port.
Figure 2-1 shows the architecture of the Port Information application:
Figure 2-1: Architecture of the Port Information Application
The PortDescription.java file calls the ShowDescriptionWindow.java file, when the end user selects a serial or parallel port from the populated list of ports and clicks the Port Description button.
The ShowDescriptionWindow.java file displays the description of the selected port. The ShowDescriptionWindow.java file displays the various fields related to the selected port which includes Port Type, Port Name, Port Mode, Port Status, and Owner Name to the end user.