Page 63 - The Definitive Guide to Building Java Robots
P. 63

Preston_5564C02.fm  Page 44  Wednesday, September 14, 2005  5:42 AM



                 44     CHAPTER 2  ■  SERIAL COMMUNICATION



                                } else {
                                    if (delay == 0) {
                                        serialPort.write(cmd);
                                    } else {
                                        serialPort.write(cmd);
                                        Utils.pause(delay);
                                        out = serialPort.read();
                                    }
                                }
                                return out;
                            }


                            public void close() {
                                serialPort.close();
                            }
                        }


                        To provide an example of how these three classes fit together—StandardSerialPort, JController,
                        and Controller—I have provided the UML class diagram in Figure 2-8.
                            At the beginning of SimpleStamp, I create three constants. These constants are used in two
                        ways. The first is to make it easier to modify command strings when synchronizing the Stamp
                        program. Second, because the actual commands sent to the Stamp are bytes, I can use these
                        constants as the actual commands for the byte[] sent to the write() method of the serial port.
                            The constructor of this class will get an instance of a SerialPort from the SingleSerialPort
                        class.
   58   59   60   61   62   63   64   65   66   67   68