The sample program below shows how to use the Comm Engine's REXX features to turn a module on and then off at a certain time. This program is also part of the HOUSE/290 distribution and is named TIMEMOD.CMD. More examples are included in MODCTRL.CMD which turns on a module as soon as the program is run, and RSTCP290.CMD which uploads timer events into the CP290 from a pre-defined file.

These examples require the Comm Engine to be running and connection made to the CP290.


/* TIMEMOD.CMD - Start Module at a certain time, then turn it off at a certain time. */
/* Written by A. Schwarz. See http://home.att.net/~ASchw */
/* This is an example to show how to access the HOUSE/290 Comm Engine functions. */

/* Load X10LDLL.DLL */
call RxFuncAdd 'X10LLoadFuncs', 'X10LDLL', 'X10LLoadFuncs'
call X10LLoadFuncs

/* Load REXXUTIL.DLL */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

pipename = '\PIPE\HOUSE290' /* single backslashes only when using on single computer */

/* Note: If running over a network, precede the pipe name with the computer name as shown below. */
/* pipename = '\\CLIENT527\PIPE\HOUSE290' */ /* note the _two_ backslashes preceding the computer name */

SAY ' '
SAY 'This program turns module A1 on and off at a certain time.'
SAY 'The Comm Engine must be running and be connected to'
SAY 'the CP290 for this program to work.'
SAY ' '
SAY 'Press C to continue, any other key to exit...'
PARSE PULL keyhit

IF keyhit <> 'c' & keyhit <> 'C' THEN
EXIT

/* Check if pipe is available and connect to it */
rc = CLOpenPipe(pipename)
IF rc = 0 then
DO
rc = CLPeekPipe('0')
IF Right(rc, 1) = 3 THEN
SAY 'Connected to Comm Engine.'
ELSE
DO
SAY 'Comm Engine unavailable, closing.'
rc = CLClosePipe('0')
SAY 'Press any key to exit...'
PARSE PULL keyhit
Signal ExitError1
END
END
ELSE
DO
SAY 'Comm Engine not available.'
SAY 'Press any key to exit...'
PARSE PULL keyhit
Signal ExitError1
END

Module = 'A1' /* module house and device code */
TimeOn = '11:29:00' /* time in HH:MM:SS to turn A1 on */
TimeOff = '11:29:30' /* time in HH:MM:SS to turn A1 off */
Waitflag = 0 /* Waitflag = 0 wait for ON time, Waitflag = 1 wait for OFF time */

SAY ' '
SAY "Waiting to turn " || Module || " on at " || TimeOn
SAY "Press CTRL-Break to Exit..."

DO FOREVER

call SysSleep(1) /* wait one second */
CurrentTime = TIME()
IF CurrentTime = TimeOn & Waitflag = 0 THEN
DO
temp = '}ID1 ' || Module || " ON 0" /* turn on module */
rc = CLWritePipe(temp) /* write data to pipe */
Loop = 0
DO WHILE Loop < 5 /* wait for confirmation */
call SysSleep(1) /* wait one second */
rc = CLPeekPipe('0') /* peek into pipe */
PARSE VALUE rc WITH rcPeekNPipe ' ' BytesWait ' ' PipeState
IF BytesWait > 0 THEN /* pipe has data */
DO
rc = CLReadPipe('0') /* read pipe */
IF POS('{0 }ID1', rc) > 0 THEN /* no error */
DO
SAY rc || Module || ' turned on. Waiting to turn off at ' || TimeOff || ' ...'
Loop = 10
Waitflag = 1 /* set flag to wait for turn-off */
END
ELSE /* Comm Engine reports errors */
DO
SAY 'Direct command ERROR: ' || rc
Signal ExitError
END
END
Loop = Loop + 1
END /* While Loop */
END /* IF CurrentTime = TimeOn */

IF CurrentTime = TimeOff & Waitflag = 1 THEN
DO
temp = '}ID1 ' || Module || " OFF 0" /* turn off module */
rc = CLWritePipe(temp) /* write data to pipe */
Loop = 0
DO WHILE Loop < 5 /* wait for confirmation */
call SysSleep(1) /* wait one second */
rc = CLPeekPipe('0') /* peek into pipe */
PARSE VALUE rc WITH rcPeekNPipe ' ' BytesWait ' ' PipeState
IF BytesWait > 0 THEN /* pipe has data */
DO
rc = CLReadPipe('0') /* read pipe */
IF POS('{0 }ID1', rc) > 0 THEN /* no error */
DO
SAY rc || "Waiting to turn " || Module || " on at " || TimeOn
SAY "Press CTRL-Break to Exit..."
Loop = 10 /* exit the while loop */
Waitflag = 0 /* set flag to wait for turn-on */
END
ELSE /* Comm Engine reports errors */
DO
SAY 'Direct command ERROR: ' || rc
Signal ExitError
END
END
Loop = Loop + 1
END /* While Loop */
END /* IF CurrentTime = TimeOff */

END

ExitError:
rc = CLClosePipe('0')

ExitError1:
call X10LDropFuncs

EXIT