RS-232 serial ports are one of the oldest I/O technologies still in use today. They really haven changed a lot in the last 20 years. RS-232 serial ports work reliably and work well, but a 20-year-old technology designed for 300-baud modems, daisy-wheel printers, and 16-bit processors with 4.77-MHz clock rates doesn suffice for digital video, DVD burners, and optical mice. Consequently, more modern computers have switched to a different serial protocol known as Universal Serial Bus (USB).
Hardware-wise, USB is much faster and thus better suited for the data transfer needs of todays more bandwidth-hungry devices. USB also uses a different connector thats much easier to plug in and unplug and less susceptible to bent pins and broken ports. USB cables carry power as well as data, so small USB devices that don draw a lot of current don need separate power cords. However, to a Java programmer there are two key differences:
Many different devices can be connected to the same USB port. Indeed, up to 127 different devices may be daisy chained to a single USB controller.
Data is sent to and received from USB devices in individual I/O request packets (IRPs). The stream classes are not used.
This makes communicating with USB devices more complex than reading and writing the streams from the single device on a serial port.
There are several extant versions of USB. The basic architecture and APIs are the same regardless of version. As a software developer or end user, the primary difference is speed. USB 1.0 and 1.1 support low-speed 1.5-Mbps connections and full-speed 12 Mbps connections.[*]USB 2.0 adds support for high-speed 480-Mbps connections. High-speed devices can normally fall back to full speed when attached to a USB 1.1 hub or controller. Furthermore, not all USB 2.0 devices are high speed. My typing speed is 30 words per minute at best. A low-speed USB keyboard is more than adequate.
[*] Thats megabits per second, Mbts, not megabytes per second, MBps.
USB communication is not a standard part of the JDK. It is available as a standard extension in the javax.usb package. IBM has published an open source implementation of this API for Linux that can be downloaded from http://javax-usb.org. While, like most things Java, this API is at least theoretically platform independent, currently this is the only available implementation. It has not yet been ported to the Mac, Windows, or other platforms.
The Java USB API is a very low-level API that closely mirrors the actual USB hardware and protocols. It involves a lot of bit-twiddling and byte manipulation. A number of higher-level protocols, such as the Human Interface Device (HID) class and the Mass Storage Driver, sit on top of the raw USB API. The Java USB API does not support these higher-level protocols. They can be implemented on top of the low-level USB API Java does support, but this is a decidedly nontrivial undertaking.
Streams in Memory
The File System
Working with Files
File Dialogs and Choosers
Character Sets and Unicode
Readers and Writers
Formatted I/O with java.text
The Java Communications API
The J2ME Generic Connection Framework
Authors: Elliotte Rusty Harold
Similar book on Amazon