home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: OtherApp
/
OtherApp.zip
/
house290.zip
/
HOUSE290.EXE
/
TIMEMOD.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-06-01
|
4KB
|
134 lines
/* 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
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'
TimeOn = '16:59:00' /* time in HH:MM:SS to turn A1 on (use 24hr time format) */
TimeOff = '16:59:30' /* time in HH:MM:SS to turn A1 off */
Waitflag = 0
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 A1 */
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 on A1 */
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'
EXIT