home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxdlg11.zip / com.cmd next >
OS/2 REXX Batch file  |  1995-03-01  |  6KB  |  167 lines

  1. /* An example of device input (ie, using FILEREXX.DLL too) */
  2.  
  3. /* The FileLoadFuncs loads all the rest of the REXX functions in the FILEREXX DLL.
  4.  So, we don't have to make calls to RxFuncAdd to add each one of those functions. Of
  5.  course, in order to call FileLoadFuncs, we have to add that one */
  6. CALL RxFuncAdd 'FileLoadFuncs', 'FILEREXX', 'FileLoadFuncs'
  7. CALL FileLoadFuncs
  8.  
  9. /* Change this to whatever COM port your modem is attached to */
  10. port = 'COM2'
  11.  
  12. /* Open the COM device driver for reading/writing. Let it be shared with other programs */
  13. RXHANDLE = FileOpen(port, 'rws')
  14. IF RXHANDLE = 0 THEN DO
  15.     RXSAY "Error opening" port "device!"
  16.     EXIT
  17. END
  18.  
  19. /* Trap ERROR and FAILURE */
  20. SIGNAL ON ERROR
  21. SIGNAL ON FAILURE
  22.  
  23.  
  24.  
  25.  
  26. /* ====================== 'Main Window' ======================= */
  27. /* First Group is TEXT */
  28. RXTYPE.1 = 'TEXT'
  29.  
  30. /* Default */
  31. RXFLAGS.1 = ' '
  32.  
  33. /* Text lines */
  34. RXLABEL.1 = "COM device input. Here's the received line:"
  35.  
  36. /* TotalPhrases, PhrasesPerLine, WidthOfPhrase, BetweenPhrases */
  37. RXINFO.1 = '1 1 0 0'
  38.  
  39. /* Position */
  40. RXX.1 = 10
  41. RXY.1 = 30
  42.  
  43. /* Use another TEXT Group to display the device input byte */
  44. RXTYPE.2 = 'TEXT'
  45.  
  46. /* Default */
  47. RXFLAGS.2 = ' '
  48.  
  49. /* Text lines */
  50. RXLABEL.2 = ' '
  51.  
  52. /* TotalPhrases, PhrasesPerLine, WidthOfPhrase, BetweenPhrases. Note that
  53.  we deliberately set WidthOfPhrase non-0 to allow enough width to accomodate
  54.  a range of text */
  55. RXINFO.2 = '1 1 255 0'
  56.  
  57. /* Position */
  58. RXX.2 = 10
  59. RXY.2 = 10
  60.  
  61. /* Default size and position (also gives us sizing and max button) */
  62. RXWINMAIN = ' '
  63. RXDLG 2 '"Main Window"' 'RXWINMAIN' 'NOCLOSE|RESULT'
  64.  
  65.  
  66.  
  67.  
  68. /* ============= Open device for input ================ */
  69. /* Trim off the start or end patterns */
  70. RXFLAGS = 'TRIM'
  71.  
  72. /* Default input buffer size and count limit */
  73. RXCOUNT = ' '
  74.  
  75. /* File handle */
  76. RXINFO = RXHANDLE
  77.  
  78. /* No Start string to match (ie, null string). End string contains 1 pattern;
  79.     a Line Feed and Carriage Return. We set the TRIM flag, so this is
  80.     removed from the returned input */
  81. RXSTARTPAT = ' '
  82. RXENDPAT = 'D 13 10'
  83.  
  84. /* The input is returned to me in this variable */
  85. RXLABEL = 'MYINPUT'
  86.  
  87. RXDEV 'COM INIT'
  88.  
  89.  
  90.  
  91. more:
  92.    /* Do user interaction (and also device input). We go to sleep while user
  93.       manipulates the window, until such time as the user presses ESC or
  94.       ENTER if the window's RESULT Flag is set, or tries to close a dialog
  95.       using its CLOSE ICON, or uses a RESULT Group, or uses some Group with
  96.       its END Flag set, or presses a key if the window's KEYS Flag is set, or
  97.       the timer times out, or device input is received */
  98.    RXDLG  /* NOTE: No window title means "use Main Window". No operation
  99.            specified means an operation of 0 (ie, PROCESS) */
  100.  
  101.    /* RXWIND now specifies which window or device woke us up */
  102.  
  103.    /* Did user press ESC or click on the CLOSE ICON? Note that we haven't set
  104.       the KEYS flag of any window, so we don't need to check for particular
  105.       negative values of RXID because the only 2 we ever receive here are
  106.       for the ESC key and CLOSE ICON */
  107.    IF RXID < 0 THEN DO
  108.       /* Done */
  109.       EXIT
  110.    END
  111.  
  112.    /* If user didn't abort, then check if this is device input */
  113.    IF RXID >= 1000 THEN DO
  114.        /* RXSUBID is the number of bytes returned. RXSTARTPAT and
  115.        RXENDPAT are the number of the matching start and end
  116.        patterns, or 0 if none. RXWIND is the device name */
  117.  
  118.        /* Print the received input (ie, may be the modem echoing back the
  119.        ATZ, or the OK from the ATZ command, or some line that it
  120.        received from some other host */
  121.        RXSET '"Main Window"' 2 1 'VAL' MYINPUT.0
  122.    END
  123.  
  124.    /* NOTE: We have no RESULT Group nor any Groups with the END Flag set,
  125.       so there's no need to further check for RXID being anything but -1 or 0,
  126.       and therefore what we must have here is the ENTER key (ie, RXID=0,
  127.       RXSUBID=10). Ignore it */
  128.    ELSE DO
  129.        /* ====== Clear out driver's input queue ===== */
  130.        /* Clear out any queued input waiting to be read before we do the
  131.       write and operation below. We don't want RXDLG to have to wade
  132.       through anything except what the modem sends AFTER we do the
  133.       FilePuts */
  134.        REQ.0 = 1
  135.        REQ.1 = '1.1.0'   /* Command. Must be 0 */
  136.        DATA.0 = 1
  137.        DATA.1 = '1.1.0'  /* Reserved */
  138.        err = FileDevIOCtl(RXHANDLE, 11, 1, 'REQ', 'DATA')
  139.        IF err <> 0 THEN RXSAY "ERROR flushing input queue:" err
  140.  
  141.        /* ====== Send the modem reset string ===== */
  142.        /* Send the Hayes command string 'ATZ' (followed by a line feed, so
  143.        we use FilePuts to automatically send that terminating line feed)
  144.        to the modem */
  145.        err = FilePuts(RXHANDLE, 'ATZ')
  146.        IF err <> 5 THEN RXSAY 'Error sending ATZ'
  147.    END
  148.  
  149.  
  150. /* Do another message loop */
  151. SIGNAL more
  152.  
  153. /* ========================== Done ========================== */
  154.  
  155. FAILURE:
  156.     /* NOTE: the variable RC contains the returned error message (not a number,
  157.     unless we use RXERR to set up Rexx Dialog to return error numbers instead).
  158.     Because we used the default severity level, Rexx Dialog has already displayed
  159.     this error message to the enduser */
  160. ERROR:
  161.     /* NOTE: the variable RC contains the returned error message (not a number,
  162.     unless we use RXERR to set up Rexx Dialog to return error numbers instead).
  163.     Because we used the default severity level, Rexx Dialog has already displayed
  164.     this error message to the enduser */
  165.  
  166.     EXIT
  167.