| Perhaps you are developing a package of instruments and sensors 
              to distribute to remote locations. A small weather station kit would 
              be an example. With the techniques and tools discussed so far in 
              JavaTech, you could use Java to develop much of the software that 
              is needed to do analysis of the data and to build a client/server 
              system to provide the data to distant users via the Internet.  But to make the system work, you would also need software to access 
              the instrument hardware. You might also need to control a modem 
              to do dial-up connections if there was no local network available. 
             To do these things you will need to access the platform's communications 
              ports, such as those for serial lines, that are connected to the 
              instruments. You could use the techniques in Chapter 
              22 to connect via C hardware drivers, but a much easier alternative 
              is to take advantage of the available communication classes and 
              talk to these ports directly from your Java programs.  The Java Communications API consists of the javax.comm 
              package. This package does not come with the core Java development 
              kits but instead is included in the set of optional Java Extensions 
              packages that provide various useful services but are not available 
              for all platforms. With the Communications API you can obtain a set of objects representing 
              the RS232 serial ports and IEEE 1284 parallel ports on a platform. 
              With these you can obtain exclusive ownership of a port, read and 
              write to the port either synchronously and asynchronously, and receive 
              events from the port that indicate some state change in the port 
              such as the arrival of data. The serial and parallel port classes provide low level I/O capabilities. 
              The serial port class methods even give access even to individual 
              pins. You can open an input and/or output stream to the port. You 
              must write your own protocol handler, or obtain one from a third 
              party, to deal with a particular device such as a modem or printer. Other types of ports (see below) like USB are coming to dominate 
              desktop PC systems. RS232 serial ports and especially the 1284 parallel 
              ports are used less and less and are often absent on new consumer 
              machines. However, for technical applications we expect that the 
              RS232 serial port will remain common for many more years. There 
              are thousands of new and old types of devices that use RS232 for 
              communications and it will be a long time before they completely 
              disappear. In the following sections we will look at sample codes for carrying 
              out basic I/O tasks with the serial and parallel ports.  Installing javax.comm The J2SE installation does not include the javax.comm 
              set of files. You must download and install it separately. The Sun 
              Java Communications site currently provides files suitable for 
              Windows platforms and Solaris. See the resources section below for 
              links to sites that provide javax.comm 
              for Linux . For example, for MS Windows follow this procedure: 
              Download and unpack the javacomm20-win32.zip 
                file.Place the win32com.dll 
                in <jdk>\jre\bin 
                directory (or the \jre\bin 
                subdirectory of your current J2SDK directory.)Place the comm.jar 
                in <jdk>\jre\lib\ext. 
              Place the javax.comm.properties 
                in <jdk>\jre\lib. 
              Do not alter the CLASSPATH. where <jdk> refers to the directory path for your JDK, e.g. 
              C:\Program Files\Java\jdk1.5.0.   For help with installation problems, see the readme.html that 
              comes with the javax.comm files and the Java 
              Comm API FAQ. Other Types of Ports Unfortunately, the javax.comm 
              package does not currently support access to other types of ports 
              such as USB and Firewire. Below we discuss the USB and 1-Wire systems 
              for which independent Java software packages are available. USB  
              The specifications for a javax.usb 
                package is currently under development by the Java 
                Community Process. There is third party software available 
                for some platforms such as the jUSB: 
                Java USB open source software that works with USB ports on 
                Linux platforms.  Note that indirect access to USB and other ports that communicate 
                with audio and video devices comes via the Java 
                Media Framework (java.sun.com/products/java-media/jmf/), 
                which is another Java Extensions API not available on all platforms. 
                While they don't allow for low level interaction with the ports, 
                the JMF classes do provide for considerable control over the communications 
                with these devices in the context of audio and video applications. 1-Wire & iButton   
              1-Wire® is a proprietary protocol of Dallas Semiconductor (now 
                part of Maxim-IC) that needs only one wire plus ground to do serial 
                transmission and also to supply power. The system works only over 
                short ranges but provides for a simple two-contact interface. 
               A network of 1-Wire nodes via twisted pair wire can be configured 
                in a master and slaves arrangement since each node has a unique 
                address. This report 
                discusses 1-Wire circuits with Maxim-IC chips for measuring various 
                environmental parameters such as humidity, temperature, barometric 
                pressure, wind direction, solar radiance ,  The iButton, 
                also from Maxim-IC, consists of a computer chip, ROM, EPROM, and 
                EEPROM in a stainless-steel case. The lid provides the data line 
                connection and the base the ground. It communicates using the 
                1-Wire protocol and physical contact between the can and a reader. 
                Two speeds are available: 16kbps and overdrive mode at 142kbps. 
               The primary application of iButtons is to provide a compact authentication 
                device. An ID number is etched in the can and can be stored in 
                the EPROM. A number of different versions 
                of iButtons are now available such as those that act as temperature 
                sensors.  The 1-Wire 
                API for Java provides classes for communicating over a 1-Wire 
                interface and for talking to iButton devices. The TINI 
                system also includes a 1-Wire interface to provide for remote 
                web access to individual devices connected to a 1-Wire network. References and Web Resources   Most recent update: Nov. 3, 2006 |