home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / closecom.zip / CLOSECOM.CMD next >
OS/2 REXX Batch file  |  1997-04-03  |  2KB  |  68 lines

  1. /*********************************************************************
  2.  ** CLOSECOM.CMD
  3.  ** Created: 3.18.97; revised 4.3.97
  4.  ** Author: DAVID ECKMAN
  5.  ** Description:  Closes COM port if not in use, so other apps can use
  6.  **    it.  For use with DOS/Win apps that capture the port and don't
  7.  **    release it.
  8.  *********************************************************************/
  9.  
  10. SIGNAL ON Halt
  11.  
  12. CALL SysCLS
  13. com = ''
  14. wait = ''
  15.  
  16. PARSE UPPER ARG com wait
  17. IF com = '' THEN DO
  18.   SAY
  19.   SAY 'CLOSECOM requires the COM port number:'
  20.   SIGNAL Help
  21. END /* do */
  22. com = STRIP( com, T, ':')
  23. IF LEFT( com, 3) = 'COM' THEN com = RIGHT( com, LENGTH( com)-3)
  24. IF DATATYPE( com) <> 'NUM' THEN DO
  25.   SAY
  26.   SAY 'An invalid value was used for the COM port number (see example):'
  27.   SIGNAL Help
  28. END /* do */
  29. IF wait = '' THEN wait = 120
  30. IF DATATYPE( wait) <> 'NUM' THEN DO
  31.   SAY
  32.   SAY 'An invalid value was used for the wait period (see example):'
  33.   SIGNAL Help
  34. END /* do */
  35.  
  36. DO FOREVER
  37.   'SU' com 'DCD > NUL'
  38.   IF rc = 0 THEN DO
  39.     'SU' com 'close'
  40.   END /* do */
  41.   ELSE DO
  42.     SAY
  43.     SAY 'The port is in use; did not try to close it.'
  44.   END /* do */
  45.   SAY 'Time:' TIME('N')
  46.   CALL SysSleep wait
  47. END /* do forever */
  48.  
  49.  
  50. Halt:
  51.   SAY 'Ctrl+Break pressed. Exiting...'
  52.   EXIT
  53.  
  54. Help:
  55.   SAY
  56.   SAY '   USAGE: CLOSECOM <#_of_COM_port> [<seconds>]'
  57.   SAY '   Option: Add the number of <seconds> the program is to wait between calls'
  58.   SAY '           to check whether the COM port is being used.  The default is 120.'
  59.   SAY
  60.   SAY '   Examples: CLOSECOM 2 or CLOSECOM COM1 60'
  61.   SAY
  62.   SAY 'To terminate CLOSECOM, hit Ctrl+Break or Ctrl+C.'
  63.   SAY
  64.   SAY 'Use of this program is conditioned on agreement to the terms stated in '
  65.   SAY 'CLOSECOM.DOC, which is included in CLOSECOM.ZIP with this program.'
  66.   EXIT
  67.  
  68.