S e n d X 1 0
J e s s e  P e t e r s o n



SendX10 is a command line program that allows you to send X10 commands. It is a demonstration program that shows you how to interact with the X10 API. It allows the X10 transmitter device to be chosen at runtime. Currently, the X10 API provides interfaces for the serial devices CM11A and CM17A. (The CM17A is the model number for the Firecracker RF interface device.)

SendX10 has the following command line usage. A Windows batch file called SendX10.bat has been provided so that you do not have to type: java SendX10 <rest of command>.

SendX10 [-port serial_port] [-transmitter class_name] command [options]

Where:

-port serial_port serial_port is the name of the serial port for the CM11A interface. On Windows, "COM1" or "COM2" for example.
-transmitter class_name class_name is the name of a class that implements com.jpeterson.x10.Gateway and implements com.jpeterson.x10.module.Transmitter. The default value is: com.jpeterson.x10.module.CM11A
command Any one of the commands described below.
options Any options for the specified command. See below.
Commands:
  • on houseCode deviceCode
  • off houseCode deviceCode
  • dim houseCode deviceCode units
  • bright houseCode deviceCode units
  • allLightsOn houseCode
  • allLightsOff houseCode
  • allUnitsOff houseCode
  • Where:
    houseCode The house code 'A' through 'P', uppercase.
    deviceCode The device code '1' through '16'.
    units Number of units to dim or brighten.


    Example

    To turn a lamp on with house code 'B' and device code '3', the following command would be executed.

    SendX10 on B 3
    To turn the lamp off, the following command would be executed.
    SendX10 off B 3


    Code

    The source code for SendX10.java can be found in the samples/SendX10 directory.

    Within the main method of SendX10.java, the optional serial port parameter is read. If the optional parameter specifying a classname to use for the X10 transmitter is provided in the command line argument, the class name is saved off. There are two possible values provided with the distribution: com.jpeterson.x10.module.CM11A is the class to use with a CM11A device or com.jpeterson.x10.module.CM17A is the class to use with a CM17A (a.k.a. Firecracker) device. If the optional transmitter parameter is not provided in the command line argument list, by default, the CM11A class is used. Depending on if a port is identified, the appropriate SendX10 constructor is called. Once the constructor returns, the transmit method of SendX10 is called, passing in the rest of the command line arguments.

    The single argument constructor directly calls the double argument constructor, passing in the default value of "COM2" for the port.

    The double argument constructor will create a new instance of the Transmitter class based on the class name. This is done within a "try" section to ensure proper handling of unknown transmitter class names and other such errors. If the transmitter object is an instance of the class SerialGateway (both com.jpeterson.x10.module.CM11A and com.jpeterson.x10.module.CM17A are instances of SerialGateway) and a port is specified, the transmitter object is cast to a SerialGateway so that the serial port can be set. Finally, the transmitter object, which is cast to a Gateway object, is allocated.

    The transmit method of SendX10.java determines what command to send and then sends it. Some commands require two X10 events, others only require one. An array of X10Events is created to hold the commands. If the command line argument is the 'on' command, an array of X10Events with 2 elements is allocated. The AddressEvent is placed in the array at position 0 and an OnEvent is placed in the array at position 1. Cases for all of the other commands are handled similarly. Once the array of events is created, a for loop is used to iterate through the events array, calling cm11a.transmit() for each event. The program then waits for the transmission queue of X10Events contained by the Transmitter object to become empty. This means that all of the events have been sent. If the Transmitter is an instance of Gateway, the object is deallocated with a call to deallocate, and then the program is ended.



    Copyright © 1999 Jesse Peterson