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

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