S e t C l o c k
J e s s e  P e t e r s o n



SetClock is simple program that sets the clock of a CM11A. It sets the clock to the current time or 11:58:45 PM on February 28th to show how the CM11A keeps track of the day of year. The CM11A assumes that there is always 366 days in a year; 0 for January 1 and 365 for December 31. When set to February 28th, the day of the year will be 58. When the clock reaches 12:00:00 AM, the day of the year progresses to 59. It is the controlling systems responsibility to update the clock after the transition from February 28 to March 1, depending on if the year happens to not be a leap year. The CM11A also does not keep track of situations like Daylight Savings Time. The controlling program must update the CM11A in that situation as well.

The program SetClock can be started by entering the following command line:

java SetClock [-port serial_port] [-now]

Where:

 
-port serial_port Set the serial port that the CM11A can be contacted on. Default: COM2
-now Set the clock to the current time.

Example

Running SetClock on the default serial port of 'COM2'.

java SetClock

Running SetClock on serial port 'COM1'.

java SetClock -port COM1


Code

The source code for SetClock.java can be found in the samples/SetClock directory. It is very straight forward. It will create a CM11A instance and then instantiate the device. If the command line parameter for using the current time is specified, the current time is sent to the device, otherwise, the time of 11:58:45 PM on February 28th is downloaded to the interface. The current time is determined via the Calendar class.

The status of the interface is updated to prove that the time has been updated. Status results are received in the status method. The SetClock class implements the CM11AStatusListener interface. This allows the SetClock object to be passed as the parameter to the CM11A's updateStatus method. Doing so registers the SetClock object as the recipient of the status event. (This does not preclude listeners who explicitly register as a listener for status events from receiving the status event as well.) After issuing the updateStatus method call, the program waits 3 seconds to give the CM11A a chance to respond with the status before communication is severed with a call to deallocate.

The program then terminates.



Copyright © 1999 Jesse Peterson