home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: OtherApp / OtherApp.zip / cm17ce.zip / fcinst.EXE / timemod.cmd < prev    next >
OS/2 REXX Batch file  |  2000-01-18  |  5KB  |  142 lines

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