home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / house290.zip / HOUSE290.EXE / TIMEMOD.CMD < prev    next >
OS/2 REXX Batch file  |  1999-06-01  |  4KB  |  134 lines

  1. /* TIMEMOD.CMD - Start Module at a certain time, then turn it off at a certain time. */
  2. /*               Written by A. Schwarz. See http://home.att.net/~ASchw  */
  3. /*               This is an example to show how to access the HOUSE/290 Comm Engine functions. */
  4.  
  5. /* Load X10LDLL.DLL */
  6. call RxFuncAdd 'X10LLoadFuncs', 'X10LDLL', 'X10LLoadFuncs'
  7. call X10LLoadFuncs
  8.  
  9. /* Load REXXUTIL.DLL */
  10. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  11. call SysLoadFuncs
  12.  
  13. pipename = '\PIPE\HOUSE290'  /* single backslashes only when using on single computer */
  14.  
  15. /* Note: If running over a network, precede the pipe name with the computer name as shown below. */
  16. /* pipename = '\\CLIENT527\PIPE\HOUSE290' */  /* note the _two_ backslashes preceding the computer name */
  17.  
  18. SAY ' '
  19. SAY 'This program turns module A1 on and off at a certain time.'
  20. SAY 'The Comm Engine must be running and be connected to'
  21. SAY 'the CP290 for this program to work.'
  22. SAY ' ' 
  23. SAY 'Press C to continue, any other key to exit...'
  24. PARSE PULL keyhit
  25.  
  26. IF keyhit <> 'c' & keyhit <> 'C' THEN
  27.   EXIT
  28.  
  29. rc = CLOpenPipe(pipename)
  30. IF rc = 0 then
  31.   DO
  32.     rc =  CLPeekPipe('0')
  33.     IF Right(rc, 1) = 3 THEN
  34.       SAY 'Connected to Comm Engine.'
  35.     ELSE
  36.       DO
  37.        SAY 'Comm Engine unavailable, closing.'
  38.        rc = CLClosePipe('0')
  39.        SAY 'Press any key to exit...'
  40.        PARSE PULL keyhit
  41.        Signal ExitError1
  42.       END
  43.   END
  44. ELSE
  45.   DO
  46.    SAY 'Comm Engine not available.'
  47.    SAY 'Press any key to exit...'
  48.    PARSE PULL keyhit
  49.    Signal ExitError1
  50.   END
  51.  
  52. Module = 'A1'
  53. TimeOn = '16:59:00'   /* time in HH:MM:SS to turn A1 on (use 24hr time format) */
  54. TimeOff = '16:59:30'  /* time in HH:MM:SS to turn A1 off */
  55. Waitflag = 0
  56.  
  57. SAY ' '
  58. SAY "Waiting to turn " || Module || " on at " || TimeOn
  59. SAY "Press CTRL-Break to Exit..."
  60.  
  61. DO FOREVER
  62.  
  63.      call SysSleep(1)      /* wait one second */
  64.      CurrentTime = TIME()
  65.      IF CurrentTime = TimeOn & Waitflag = 0 THEN
  66.        DO
  67.          temp = '}ID1 ' || Module || " ON 0"  /* turn on A1 */
  68.          rc = CLWritePipe(temp)   /* write data to pipe */
  69.          Loop = 0
  70.          DO WHILE Loop < 5  /* wait for confirmation */
  71.            call SysSleep(1)      /* wait one second */
  72.            rc = CLPeekPipe('0')  /* peek into pipe */
  73.            PARSE VALUE rc WITH rcPeekNPipe ' ' BytesWait ' ' PipeState
  74.            IF BytesWait > 0 THEN  /* pipe has data */
  75.              DO
  76.                rc = CLReadPipe('0')  /* read pipe */
  77.                IF POS('{0  }ID1', rc) > 0 THEN  /* no error */
  78.                  DO
  79.                     SAY rc || Module || ' turned on. Waiting to turn off at ' || TimeOff || ' ...'
  80.                     Loop = 10
  81.                     Waitflag = 1  /* set flag to wait for turn-off */
  82.                  END
  83.                ELSE  /* Comm Engine reports errors */
  84.                  DO
  85.                    SAY 'Direct command ERROR: ' || rc
  86.                    Signal ExitError
  87.                  END
  88.              END
  89.            Loop = Loop + 1
  90.          END  /* While Loop */
  91.        END /* IF CurrentTime = TimeOn */
  92.  
  93.      IF CurrentTime = TimeOff & Waitflag = 1 THEN
  94.        DO
  95.          temp = '}ID1 ' || Module || " OFF 0"  /* turn on A1 */
  96.          rc = CLWritePipe(temp)   /* write data to pipe */
  97.          Loop = 0
  98.          DO WHILE Loop < 5  /* wait for confirmation */
  99.            call SysSleep(1)      /* wait one second */
  100.            rc = CLPeekPipe('0')  /* peek into pipe */
  101.            PARSE VALUE rc WITH rcPeekNPipe ' ' BytesWait ' ' PipeState
  102.            IF BytesWait > 0 THEN  /* pipe has data */
  103.              DO
  104.                rc = CLReadPipe('0')  /* read pipe */
  105.                IF POS('{0  }ID1', rc) > 0 THEN  /* no error */
  106.                  DO
  107.                     SAY rc || "Waiting to turn " || Module || " on at " || TimeOn
  108.                     SAY "Press CTRL-Break to Exit..."
  109.                     Loop = 10  /* exit the while loop */
  110.                     Waitflag = 0  /* set flag to wait for turn-on */
  111.                  END
  112.                ELSE  /* Comm Engine reports errors */
  113.                  DO
  114.                    SAY 'Direct command ERROR: ' || rc
  115.                    Signal ExitError
  116.                  END
  117.              END
  118.            Loop = Loop + 1
  119.          END  /* While Loop */
  120.        END /* IF CurrentTime = TimeOff */
  121.  
  122. END
  123.  
  124. ExitError:
  125. rc = CLClosePipe('0')
  126.  
  127. ExitError1:
  128. call X10LDropFuncs
  129.  
  130. 'EXIT'
  131.  
  132. EXIT
  133.  
  134.