2013-06-05
md
Finding the CM15A
Downloads-> <-Part 3 - Listening to the CM15A

 ActiveHome Pro SDK with Delphi - Part 3 

Table of Contents

  1. Absence of the CM15A
  2. Using Other TActiveHome Methods
  3. Querying the State of a Device
  4. What's Next?

Absence of the CM15A toc

At first blush, it does not seem to matter much if the ActiveHome SDK does not report the absence of the CM15A when sending commands to it. If the device is not connected, it does not reply to a send message and a visual check should let a person see if it is connected to the computer!

As for the first comment, it may not be acceptable to turn a light on or off just to check if there is a CM15A at the end of the USB cable. As for the second, you may be interested in writing some sort of a server that is connected to the CM15A and can be reached on a local network or over the Internet. The user of a client application could not visually check for the presence of the CM15A.

To investigate the problem a little further, please download the expanded application cm15.exe.

found here (cm15.zip, 8861 bytes, 2013-08-09).

Using Other TActiveHome Methods toc

The TActiveHome class contains two procedures that on the face of it might tell us if a CM15A is connected or not:

procedure EnumerateInterfaces(var pCount: OleVariant); procedure GetInterfaceName(var pInterfaceName: OleVariant);

Unfortunately, both functions return an empty variable in all cases! You can verify this by clicking on Test EnumerateInterfaces and Test GetInterfaceName with the CM15A not connected and then connected. There is no difference. 

Similarly the ControlInterface and DefaultInterface properties of the component are always assigned. Or perhaps more to the point, they are assigned as long as the ahsdk.dll is found, whether a CM15A is connected or not.

Querying the State of a Device toc

The CM15A keeps tabs on the state of X10 devices. By using the command queryplc it is possible to know a device's status : on or off and dim/bright level if applicable. To find out if a device is on or off, the command sent is

res := ActiveHome1.SendAction('queryplc', 'A4 on');

where res is an OleVariant variable. It appears that only three results are possible :

res = -1 : the CM15A is not connected
res = 0 : device A4 is off (and the CM15A is connected)
res = 1 : device A4 is on (and the CM15A is connected).

Clearly this command could be used to test for the presence of the CM15A. Here is a very simple implementation for a method to be added to the public declaration of the TActiveHome class:

res := ActiveHome1.SendAction('queryplc', 'A4 on'); function TActiveHome.TransceiverPresent: boolean; var res: OleVariant; begin res := SendAction('queryplc', 'a1 on'); result := res <> -1; end;

Another, rather more complicated approach is to send a hailrequest and see if an answer comes back. The test application shows how; look at procedure TForm1.Button2Click(Sender: TObject);. It would be more difficult to include that in the component. Since TransceiverPresent seems to work, I have not looked at this possibility.

The complete modified imported type library can be downloaded here: ActiveHomeScriptLib.pas (12793 bytes, 2013-07-15).

What's Next? toc

This is the end of this discussion about using a CM15A with Delphi in Windows. But that is by no means all there is to know about that device. For example, error messages from the library, ahscript.dll, indicate that it wants to see one of the following commands

sendplc
sendrawplc
sendrf
sendsecurerf
sendsecurehomecontrolrf
queryplc
sendir

At least four of those were not used in cm15.exe. Trying "sendir a1 on" with the application's send anything function returned an error message 

ActiveScriptError: Expecting SendPLC [address] [command] [code] [keystate] [Transmit] [Delay]

that indicates that sendplc is much more complex than seems. Unfortunately, getting information about the CM15A and ahsdk.dll  is not easy. I'll mention two sources, but they are from the Linux world and, consequently, are not concerned with the ActiveX script server:

1. Neil Cherry's Linux Home Automation (http://www.linuxha.com/). There is a search function in the home page. Enter CM15 and you will pointers to a lot of information including the page X10 CM15A interface Communication Documentation that shows that the CM15A is similar to a CM11A if you bypass the ActiveX script server and talk directly to the device over the USB connexion.

2.  Brian Uechi's mochad ( http://sourceforge.net/apps/mediawiki/mochad/index.php?title=Main_Page) is a Linux deamon that talks directly to the CM15A over the USB connection. In essence, it replaces the ActiveX component. It works on a Beagleboard and on a Raspberry pi. Do an Internet search on "mochad raspberry pi" for many tutorials on getting mochad up on that surprising little computer on a chip. There are a couple on this site also.

Downloads-> <-Part 3 - Listening to the CM15A