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

  1. /* MODCTRL.CMD - Controls module whenever this program is run. */
  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. rc = CLOpenPipe(pipename)
  19. IF rc = 0 then
  20.   DO
  21.     rc =  CLPeekPipe('0')
  22.     IF Right(rc, 1) = 3 THEN
  23.       SAY 'Connected to Comm Engine.'
  24.     ELSE
  25.       DO
  26.        SAY 'Comm Engine unavailable, closing.'
  27.        rc = CLClosePipe('0')
  28.        SAY 'Press any key to exit...'
  29.        PARSE PULL keyhit
  30.        Signal ExitError
  31.       END
  32.   END
  33. ELSE
  34.   DO
  35.    SAY 'Comm Engine not available.'
  36.    SAY 'Press any key to exit...'
  37.    PARSE PULL keyhit
  38.    Signal ExitError
  39.   END
  40.  
  41. /* change address, function and dim level here */
  42. Module = 'A1'    /* House and device code */
  43. Command = 'ON'   /* X-10 function: ON, OFF, DIM */
  44. DimLevel = 0     /* Percentage 0-100 */
  45.  
  46. temp = '}ID1 ' || Module || ' ' || Command || ' ' || DimLevel  /* send command */
  47. rc = CLWritePipe(temp)   /* write data to pipe */
  48.  
  49. Loop = 0
  50. DO WHILE Loop < 5  /* wait for confirmation */
  51.   call SysSleep(1)      /* wait one second */
  52.   rc = CLPeekPipe('0')  /* peek into pipe */
  53.   PARSE VALUE rc WITH rcPeekNPipe ' ' BytesWait ' ' PipeState
  54.   IF BytesWait > 0 THEN  /* pipe has data */
  55.     DO
  56.       rc = CLReadPipe('0')  /* read pipe */
  57.       IF POS('{0  }ID1', rc) > 0 THEN  /* no error */
  58.         DO
  59.           IF Command = 'DIM' THEN
  60.              SAY rc || ' ' || Module || ' set to ' || Command || '. Level = ' || DimLevel || '%'
  61.           ELSE
  62.              SAY rc || ' ' || Module || ' set to ' || Command
  63.           Loop = 10
  64.         END
  65.       ELSE  /* Comm Engine reports errors */
  66.         DO
  67.           SAY 'Direct command ERROR: ' || rc
  68.           Loop = 11
  69.         END
  70.     END
  71.   Loop = Loop + 1
  72. END  /* While Loop */
  73.  
  74. IF Loop = 5 THEN
  75.   SAY 'Comm Engine did not respond. Time out.'
  76.  
  77. ExitNow:
  78. rc = CLClosePipe('0')
  79.  
  80. ExitError:
  81. call X10LDropFuncs
  82.  
  83. EXIT
  84.  
  85.