S e t C l o c k |
J e s s e P e t e r s o n |
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.