Page 34 - The Definitive Guide to Building Java Robots
P. 34
Preston_5564C02.fm Page 15 Wednesday, September 14, 2005 5:42 AM
CHAPTER 2
■ ■ ■
Serial Communication
“The problem with communication is the illusion that it has been accomplished.”
— George Bernard Shaw
2.0 Introduction
In this book, all communications used with your microcontroller will use RS-232 serial commu-
nication at 9600 baud, eight data bits, one stop bit, and no flow control. There are other methods
of communicating with microcontrollers, notably I2C (Inter-Integrated Communication),
parallel communications, Ethernet, WiFi, and Bluetooth just to name a few. But I have chosen to
use serial communications for its popularity and its extensibility with other software and devices.
I will show and describe 12 Java classes and 2 BASIC Stamp programs. All of the classes are
in package com.scottpreston.javarobot.chapter2. All of the Stamp programs are in the folder /
BasicStamp/chapter2.
In this chapter, I will introduce you to the Java Communications API by explaining some
of its more important classes, and then test it using some simple programs. Later, I will simplify
it for your use with robotics and then extend serial communications over a network using Java
Server Pages and a web client.
Once I have discussed and simplified serial communications, I will model a microcontroller
program in a Java class. By modeling the microcontroller program in Java, it should simplify
the programming of your robot.
The chapter will conclude with an example that uses a Bluetooth serial adapter in conjunction
with a BASIC Stamp to demonstrate wireless serial communications.
Configuring Your Serial Port
Again, configure the serial port to the following: 9600 baud, eight data bits, no parity, one stop
bit, and no flow control. To configure this for Windows, open the Control Panel, choose System ➤
Hardware ➤ Device Manager, and then click Ports. Make sure to note the (COMx) port number.
You can see the windows for these in Figures 2-1 and 2-2 shown next.
■Note UNIX users, the ports here are numbered ttyS0, ttyS1, and so on. Replace all references to COMx
with ttySx.
15