Welcome to the next if not very old information on my usage of the ActiveHome ahcmd.exe program and ActiveHome SDK. I use it for controlling things on my computer. I use it to control the following:

H16 – controls all my controllers.

H1 – Radios since I am an Amateur Radio operator and turns on/off the power supply.

H2 – Amateur Radio charger for my HT charger.

H3 – battery charger for my rechargeable chargers.

H4 – for a self-powered USB 7 port Hub.

H5 – for another self-powered USB 7 port Hub.

H6 – for yet another self-powered USB 4 port Hub.

H7 – power strip that has several other wall-warts for various items (external power supplies plugged into the wall

).

H8 – another HT radio charger for the Wouxun 144MHz and 220MHz handheld radio’s two different places. Using two X10 controllers in different rooms.

The reason for the self-powered USB Hubs to be on X10 appliance modules is that it keeps the power load  of USB devices off the computer itself. I have downloaded the ActiveHome SDK at http://www.authinx.com/manuals/activehome/ahsdk_install.exe  and the CM-15A controller from the same X10 site. I know there are better ways, but I did not want to waste any of my time in looking or thinking about those more elegant way, I just wanted it done with little or no research.The control program I use are DoStartUp.bat and DoShutdown.bat included as follows.

DoStratUp.bat

———————————————-cut ————————————-

#REM shut down X10 units.

perl “D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\X10cmd.pl” -h H -u 8 -c Off -e 1 -r 1 -d up -sl 2
shutdown.exe -s -t 10

#REM done

———————————————-cut ————————————-

Then there is the DoShutDown.bat

Do ShutDown.bat

———————————————-cut ————————————-

#REM shut down X10 units.

perl “D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\X10cmd.pl” -h H -u 8 -c Off -e 1 -r 1 -d up -sl 2
shutdown.exe -s -t 10

#REM done

———————————————-cut ————————————-

This is linked using a shortcut link which can be created by going to the desktop screen and right clicking on an open space, then selecting NEW and then select SHORTCUT. This opens up a window that asks for the location. I placed my DoStartup.bat and DoShutdown.bat in the root directory of the C:\ directory. then it will ask for the name, choose a name you prefer mine as you know were dostartup and doshutdown. Next you will need to open the shortcut and modify its actions. Right Click on the shortcut and change the Target and or Start In. I just changed the Target to c:\DoStartup.bat and the shutdown similarly. Close it and add in the Batch files to your location. in both the startup and shutdown batch files I call a command perl “D:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\X10cmd.pl and should be the path of your choosing. I just happen to have Apache HTTP Server running on my machine and choose to locate it at my perl scripting and CGI paths for me to keep things in my mind simple. 

Continued later.

The work of course requires Perl to be installed on your machine. The perl program that allows this all to function is X10cmd.pl.

Listing for X10cmd.pl

I have highlighted certain line numbers that the number can be removed, but I will later use the numbers to discuss what is going on in the program. This by no means is to be used as a programming tool as I am not a perl programmer and my code shows it in itself.

 Lines 1-11 just describe what my intentions were to control devices.

Lines 12-14 are global variables.

line 16 is setting a long declarations for get options.

Line 18-25 show the abbreviations I used in the code:

housecode,    h=s,
unitcode,        u=i,
command,      c=s,
endloop,          e=i,
repetitions,     r=i,
direction,        d=s,
sleeptime,       sl=i,

Lines 28-46 a description on meaning and abbreviations of variables.

Lines 49-66 parse the batch string command that is passed to the program IE: -h H -u 8 -c On -e 1 -r 2 -d down -sl 3

-h is for housecode in the X10 command set.

-u is  for unit codes.

-c is command code on or off, could be others as used in my camera control program.

-e where to stop program from running.

-r repetitions for command to be executed.

-d direction, sometimes you want to go from 1-8 other times you may want 8-1.

-sl is the sleep time.

 SLEEP.exe is an external program. I just googled sleep.exe and found one that suited my needs.

 Lines 68-83  just print the parsed command out on a couple lines. Could be removed, just use it to verify what was sent to program and that it was interpreted correctly.

Lines 88-90 is just checking if a On or on command. It then calls the sub-routine mastercontrol at lines 133-142.

Lines 93-105 do the up direction command, there are two loops, one nested for the repetitions of how many times to do the command.

Lines 108-120 are similar as in lines 93-105 except they iterate down, also having a nested loop for repetition of command.

Lines 123-125 are for the Off or off commands. Then it calls the mastercontrol subroutine at lines 132-142

Lines 127-131 Added in a couple additional commands in here since everything else is finished, using my X10 remote control pan & tilt on the camera O send the same command twice to tell the camera to go to a pre-programmed location.

———————————————-cut ————————————-

1. !perl

# Program is used to start up(turn on) X10 units that control
# radio’s,battery,USB power supplys and interfaces.
# charger, speakers, hub power supplys, TINI unit etc.
# Program by: Benny D. Miller Jr. ARS W4QED
# program name: X10cmd.pl
# Date: 07/28/2010

10. # use strict;

my %parms;
my $e,$r,$u;
my $Pgm_Name;

use Getopt::Long;

18. if (!&GetOptions(\%parms, “help”,
“housecode=s”, “h=s”,
“unitcode=i”, “u=i”,
“command=s”, “c=s”,
“endloop=i”, “e=i”,
“repetitions=i”, “r=i”,
“direction=s”, “d=s”,
“sleeptime=i”, “sl=i”, “debug”) or @ARGV == 0 or $parms{help}) {
26. #   print<<eof;

# $Pgn_Name = “X10cmd.pl”;

#  Usage:

#  $Pgm_Name [options]

#    -h  or -housecode   => This House Code text (A-P).
#    -u  or -unitcode    => This is the Unit Code, integer (1-16).
#    -c  or -command     => This is the command to pass (On,on,Off,off).
#    -e  or -endloop     => Last Unit Code, integer (1-15).
#    -r  or -repetitions => How many times you want command sent, integer (1…).
#    -d  or -direction   => Direction up, down to do commands.
#    -sl or -sleeptime   => how many seconds to pause between commands.

#  Example:
#    perl $Pgm_Name -h H -u 8 -c On -e 1 -r 2 -d down -sl 5

#eof
46. #    exit 1;
}

49. x10command {
$parms{housecode} = “A” unless $parms{housecode};
$parms{h} = $parms{housecode} unless $parms{h};
$parms{unitcode} = ‘1’ unless $parms{unitcode};
$parms{u} =  $parms{unitcode} unless $parms{u};
$u = $parms{u};
$parms{command} = “Off” unless $parms{command};
$parms{c} =  $parms{command} unless $parms{c};
$parms{endloop} = ‘0’ unless $parms{endloop};
$parms{e} = $parms{endloop} unless $parms{e};
$e = $parms{e};
$parms{repetitions} = ‘4’ unless $parms{repetitions};
$parms{r} = $parms{repetitions} unless $parms{r};
$r = $parms{r};
$parms{direction} = “up” unless $parms{direction};
$parms{d} = $parms{direction} unless $parms{d};
$parms{sleeptime} = ‘5’ unless $parms{sleeptime};
$parms{sl} = $parms{sleeptime} unless $parms{sl};

68.  print $parms{housecode};
print $parms{unitcode};
print $parms{command};
print $parms{endloop};
print $parms{repetitions};
print $parms{direction};
print $parms{sleeptime};
print “\n”;
print $parms{h};               # house code
print $u;                      # start unit code
print $parms{c};               # command  on/off
print $e;                      # end unit code
print $r;                      # repetitions
print $parms{d};               # direction up/down
print $parms{sl};              # sleep time in seconds
print “\n”;

# ######################## main program ##################################

87. # ####################### master control On ##############################
if(($parms{c} eq “On”) or ($parms{c} eq “on”)) {
&mastercontrol();                        # turn on master unit
}

92. # ############################# up #######################################
if ($parms{d} eq “up”) {
$u = $parms{u};
while ($e lt ($u+1)) {
$r = $parms{r};
while($r gt 0) {
system “ahcmd.exe sendplc $parms{h}$e $parms{c}”;
print “$parms{h}$e $parms{c} sleep $parms{sl}\n”;
sleep $parms{sl};
$r–;
}
$e++;
}
}

107. # ############################ down ######################################
if($parms{d} eq “down”) {
$u = $parms{u};
while ($u ne ($e-1)) {
$r = $parms{r};
while($r gt 0) {
system “ahcmd.exe sendplc $parms{h}$u $parms{c}”;
print “$parms{h}$u $parms{c} sleep $parms{sl}\n”;
sleep $parms{sl};
$r–;
}
$u–;
}
}

122. # ####################### master control Off #############################
if(($parms{c} eq “Off”) or ($parms{c} eq off)) {
&mastercontrol();                        # turn off master unit
}

system “ahcmd.exe sendplc $parms{h}$e+1 $parms{c}”;
sleep($sl);
system “ahcmd.exe sendplc $parms{h}$e+1 $parms{c}”;
sleep($sl);
exit 0;

sub mastercontrol {
$u = 16;
$r = $parms{r};
while($r gt 0) {
system “ahcmd.exe sendplc $parms{h}$u $parms{c}”;
print “$parms{h}$u $parms{c} sleep $parms{sl}\n”;
sleep $parms{sl};
$r–;
}
}
143. }

———————————————-cut ————————————-

Not intentionally adding in any errors, this should work. If by chance you have any problems with this program or any others I have blogged about, please let me know either here or if I do not reply in a timely manner at my email: bmiller@eecs.ucf.edu, please use the Subject CODE in the title. Also in the body let me know the title of the blog and I will attempt to help you in a timely manner. I have been away from the blog for a while as I have been ill, so the email may catch my attention the quickest.

Advertisements