D o w n l o a d M a c r o s
J e s s e  P e t e r s o n



DownloadMacros is a sample program that demonstrates how to add downloadable macros to the CM11A interface. A macro is a collection of X10 commands that are triggered by either an ON/OFF X10 command or a timer. Once macros are downloaded to the CM11A, the serial interface between the computer and CM11A can be disconnected and the macros will still operate. This allows the macros to function even if the computer is turned off. The macro information stays resident in the CM11A device as long as it plugged into the outlet. The macro information will also stay in the device when unplugged or during a power outage because of the battery backup built into the CM11A.

When a macro is initiated, a signal is sent from the CM11A to the computer interface. The computer interface will transmit the corresponding AddressEvents and FunctionEvents to all registered AddressListeners and FunctionListeners.

Macros can only be downloaded into the CM11A. There is now interface provided to read the macro information back out of the device. Therefore, if you want to have a control program that can send the appriate AddressEvents and FunctionEvents, you will need to persist the macro information. The CM11A object, when serialized, will retain the macro information that has been downloaded. When the object is deserialized, the macro information is reconstituted, allowing it to send the resultant events when a macro occurs.

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

java DownloadMacros [-port serial_port] [-serialFile filename]

Where:

 
-port serial_port Set the serial port that the CM11A can be contacted on. Default: COM2
-serialFile filename Define a filename to read a CM11A serialized object from and write a serialized CM11A object to.

Example

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

java DownloadMacros

Running DownloadMacros on serial port 'COM1'.

java DownloadMacros -port COM1

Running DownloadMacros and serializing the CM11A object to the file named "cm11a.ser".

java DownloadMacros -serialFile cm11a.ser

Running DownloadMacros on port 'COM1' and serializing the CM11A object to the file named "cm11a.ser".

java DownloadMacros -port COM1 -serialFile cm11a.ser


Code

The source code for DownloadMacros.java can be found in the samples/DownloadMacros directory. The program first tries to reconstitute a serialized CM11A if one is provided via the "-serialFile" command line option. If the program is unable to deserialize a CM11A object, a new one is created. The CM11A object is then allocated to establish the serial interface. The macro information in the CM11A object is cleared so that we can start with an empty set of macros. The first set of macros created is initiated with an E7, ON X10 event. When an E7, ON event occurs, the commands E4, ON and E5, ON are transmitted. The next macro set is initiated via an E7, OFF X10 event. When an E7, OFF event occurs, the command E4, OFF and E5, OFF are transmitted. This can be summarized in the following table.

Macro InitiatorMacro Commands
E7, ONE4, ON
E5, ON
E7, OFFE4, OFF
E5, OFF
Table 1: Macro Initiator Table

A timer initiated macro is created next. The timer is configured to initiate at 3:19 PM everyday the commands E4, ON and E5, ON. The timer is also configured to initiate at 3:20 PM everyday the command E4, OFF and E5, OFF.

The last section of the program illustrates how two macros can be combined to form a scene. I have set device E4 to a lamp, E5 to a lamp, and E6 to a TV. When E8, OFF is received, the following commands are sent: E4, DIM to dim the lamp assigned E4 by 50%, E5, DIM to dim the lamp assigned E5 by 50%, E6, ON to turn no the TV, and E9, OFF. E9, OFF is actually an initiator to another macro. After an E9, OFF is received by the CM11A, the CM11A will wait one minute, then transmit the commands E4, OFF and E5, OFF to shut off the lamps.

Macro InitiatorMacro Commands
E8, OFFE4, DIM 50% (lamp)
E5, DIM 50% (lamp)
E6, ON (TV)
E9, OFF (other macro)
E9, OFF(wait 1 minute)
E4, OFF (lamp)
E5, OFF (lamp)
Table 2: Macro Initiator Table

Once all of the macro initiators are added to the CM11A object, the method to download the macros to the CM11A device is invoked.

The object is serialized if a destination output file for a serialized CM11A object is specified. The program then terminates.



Copyright © 1999 Jesse Peterson