home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / filerx11.zip / COM.CMD next >
OS/2 REXX Batch file  |  1995-02-10  |  16KB  |  451 lines

  1. /******************************************************************
  2.  * COM.CMD
  3.  *
  4.  * This program calls the various REXX external functions provided in the FILEREXX DLL.
  5.  *
  6.  * Demonstrates using FileOpen(), FileRead(), FileWrite(), and FileDevIOCtl() upon a
  7.  * COM driver that has a modem attached to it. In other words, the FileDevIOCtl()
  8.  * Catagory is for the Async (RS232-C) Control; Catagory 1.
  9.  *******************************************************************/
  10.  
  11. /* Change this to whatever COM port your modem is attached to */
  12. port = 'COM2'
  13.  
  14. /* Change this to desired bit rate */
  15. bitrate = '9600'
  16.  
  17. /* Change this to desired # of data bits (ie, 5, 6, 7, or 8) */
  18. databits = '8'
  19.  
  20. /* Change this to desired parity (ie, 0=none, 1=odd, 2=even, 3=mark, 4=space) */
  21. parity = '0'
  22.  
  23. /* Change this to desired # of stop bits (ie, 0=1 bit, 1=1.5 bits, 2=2 bits) */
  24. stopbits = '0'
  25.  
  26.  
  27.  
  28.  
  29. /* ============================ Init stuff =============================== */
  30. /* The FileLoadFuncs loads all the rest of the REXX functions in the FILEREXX DLL. */
  31. /* So, we don't have to make calls to RxFuncAdd to add each one of those functions. Of */
  32. /* course, in order to call FileLoadFuncs, we have to add that one. */
  33. CALL RxFuncAdd 'FileLoadFuncs', 'FILEREXX', 'FileLoadFuncs'
  34. CALL FileLoadFuncs
  35.  
  36.  
  37.  
  38.  
  39. /* ============================== FileOpen =============================== */
  40. /** Open the device driver.
  41.  **/
  42. handle = FileOpen(port, 'rws')
  43. IF handle <> 0 THEN DO
  44.  
  45.  
  46.  
  47.  
  48.     /* =========================== FileDevIOCtl =========================== */
  49.     /** Perform a device specific function.
  50.      **/
  51.  
  52.     /* ============ Set Bit Rate =========== */
  53.     REQ.0 = 2
  54.     REQ.1 = '2' bitrate
  55.     err = FileDevIOCtl(handle, 1, 65, 'REQ')
  56.     IF err <> 0 THEN SAY "ERROR setting Bit Rate:" err
  57.  
  58.     /* ===== Set Line Characteristics (ie, parity, data and stop bits) ===== */
  59.     REQ.0 = 3
  60.     REQ.1 = '1' databits parity stopbits
  61.     /* Note that if we wanted to specify each of the above separately, we
  62.        could do:
  63.     REQ.1 = '1' databits
  64.     REQ.2 = '1' parity
  65.     REQ.3 = '1' stopbits
  66.     */
  67.     err = FileDevIOCtl(handle, 1, 66, 'REQ')
  68.     IF err <> 0 THEN SAY "ERROR setting Line Characteristics:" err
  69.  
  70.     SAY '/* ========== Query Extended Bit Rate =========== */'
  71.     REQ.0 = 15
  72.     REQ.1 = '4.1' /* current bit rate */
  73.     REQ.2 = '1.1' /* fraction of current bit rate */
  74.     REQ.3 = '4.1' /* minimum rate supported */
  75.     REQ.4 = '1.1' /* fraction of minimum rate supported */
  76.     REQ.5 = '4.1' /* maximum rate supported */
  77.     REQ.6 = '1.1' /* fraction of maximum rate supported */
  78.     err = FileDevIOCtl(handle, 1, 99, ,'REQ', 'd')
  79.     IF err = 0 THEN DO
  80.     SAY 'Bit Rate =' REQ.1
  81.     SAY 'Fractional rate =' REQ.2
  82.  
  83.     SAY 'Minimum Supported Rate =' REQ.3
  84.     SAY 'Minimum Supported Fractional rate =' REQ.4
  85.  
  86.     SAY 'Maximum Supported Rate =' REQ.5
  87.     SAY 'Maximum Supported Fractional rate =' REQ.6
  88.     END
  89.     ELSE DO
  90.     SAY '/* =============== Query Bit Rate =============== */'
  91.     REQ.0 = 2
  92.     REQ.1 = '2.1'
  93.     err = FileDevIOCtl(handle, 1, 97, , 'REQ', 'd')
  94.     IF err <> 0 THEN SAY "ERROR querying Bit Rate:" err
  95.     ELSE SAY 'Bit Rate =' REQ.1
  96.     END
  97.  
  98.     SAY '/* ========= Query Line Characteristics ========= */'
  99.     REQ.0 = 4
  100.     REQ.1 = '1.1' /* databits */
  101.     REQ.2 = '1.1' /* parity */
  102.     REQ.3 = '1.1' /* stopbits */
  103.     REQ.4 = '1.1' /* a 1 if currently transmitting a break, a 0 if not */
  104.     err = FileDevIOCtl(handle, 1, 98, ,'REQ', 'd')
  105.     IF err <> 0 THEN SAY "ERROR querying Line Characteristics:" err
  106.     ELSE DO
  107.     SAY 'Data Bits =' REQ.1
  108.  
  109.     IF REQ.2 = 0 THEN parity = 'None'
  110.     IF REQ.2 = 1 THEN parity = 'Odd'
  111.     IF REQ.2 = 2 THEN parity = 'Even'
  112.     IF REQ.2 = 3 THEN parity = 'Mark (always 1)'
  113.     IF REQ.2 = 4 THEN parity = 'Space (always 0)'
  114.     SAY 'Parity =' parity
  115.  
  116.     IF REQ.3 = 0 THEN stopbits = '1'
  117.     IF REQ.3 = 1 THEN stopbits = '1.5'
  118.     IF REQ.3 = 2 THEN stopbits = '2'
  119.     SAY 'Stop Bits =' stopbits
  120.  
  121.     IF REQ.4 = 1 THEN SAY 'Transmitting break'
  122.     END
  123.  
  124.     SAY '/* ============== Query COM Status ============== */'
  125.     REQ.0 = 1
  126.     REQ.1 = 'B1.1' /* Return it in BINARY (each bit is a 1 or 0) */
  127.     err = FileDevIOCtl(handle, 1, 100, , 'REQ', 'd')
  128.     IF err <> 0 THEN SAY "ERROR querying COM Status:" err
  129.     ELSE DO
  130.     /* Each bit of the returned 8-bit char is for a different aspect of
  131.        the COM status. So, we need to test each bit */
  132.     IF FileBit(REQ.1, 0) THEN SAY 'Transmit status (Tx) waiting for CTS to be turned on.'
  133.     IF FileBit(REQ.1, 1) THEN SAY 'Tx waiting for DSR to be turned on.'
  134.     IF FileBit(REQ.1, 2) THEN SAY 'Tx waiting for DCD to be turned on.'
  135.     IF FileBit(REQ.1, 3) THEN SAY 'Tx waiting because XOFF received.'
  136.     IF FileBit(REQ.1, 4) THEN SAY 'Tx waiting because XOFF transmitted.'
  137.     IF FileBit(REQ.1, 5) THEN SAY 'Tx waiting because break being transmitted.'
  138.     IF FileBit(REQ.1, 6) THEN SAY 'Character waiting to transmit immediately.'
  139.     IF FileBit(REQ.1, 7) THEN SAY 'Receive waiting for DSR to be turned on.'
  140.     END
  141.  
  142.     SAY '/* ========= Query Transmit Data Status ========= */'
  143.     REQ.0 = 1
  144.     REQ.1 = 'B1.1'
  145.     err = FileDevIOCtl(handle, 1, 101, , 'REQ', 'd')
  146.     IF err <> 0 THEN SAY "ERROR querying Transmit Data Status:" err
  147.     ELSE DO
  148.     /* Each bit of the returned 8-bit char is for a different aspect of
  149.        the Transmit Status. So, we need to test each bit */
  150.     IF FileBit(REQ.1, 0) THEN SAY 'Write Request Packets in progress or queued.'
  151.     IF FileBit(REQ.1, 1) THEN SAY 'Data in driver transmit queue.'
  152.     IF FileBit(REQ.1, 2) THEN SAY 'Hardware is currently transmitting data.'
  153.     IF FileBit(REQ.1, 3) THEN SAY 'Character waiting to be transmitted immediately.'
  154.     IF FileBit(REQ.1, 4) THEN SAY 'Waiting to automatically transmit an XON.'
  155.     IF FileBit(REQ.1, 5) THEN SAY 'Waiting to automatically transmit an XOFF.'
  156.     END
  157.  
  158.     SAY '/* ========= Query Modem Output Signals ========= */'
  159.     REQ.0 = 1
  160.     REQ.1 = 'B1.1'
  161.     err = FileDevIOCtl(handle, 1, 102, , 'REQ', 'd')
  162.     IF err <> 0 THEN SAY "ERROR querying Modem Output Signals:" err
  163.     ELSE DO
  164.     /* Each bit of the returned 8-bit char is for a different signal. So,
  165.        we need to check each bit */
  166.     CALL CHAROUT ,'Data Terminal Ready (DTR) is '
  167.     IF FileBit(REQ.1, 0) THEN SAY 'on.'
  168.     ELSE SAY 'off.'
  169.  
  170.     CALL CHAROUT ,'Request To Send (RTS) is '
  171.     IF FileBit(REQ.1, 1) THEN SAY 'on.'
  172.     ELSE SAY 'off.'
  173.     END
  174.  
  175.     SAY '/* ========= Query Modem Input Signals ========== */'
  176.     REQ.0 = 1
  177.     REQ.1 = 'B1.1'
  178.     err = FileDevIOCtl(handle, 1, 103, , 'REQ', 'd')
  179.     IF err <> 0 THEN SAY "ERROR querying Modem Input Signals:" err
  180.     ELSE DO
  181.     /* Each bit of the returned 8-bit char is for a different signal. So,
  182.        we need to check each bit */
  183.     CALL CHAROUT ,'Clear To Send (CTS) is '
  184.     IF FileBit(REQ.1, 4) THEN SAY 'on.'
  185.     ELSE SAY 'off.'
  186.  
  187.     CALL CHAROUT ,'Data Set Ready (DSR) is ' /* 6th bit */
  188.     IF FileBit(REQ.1, 5) THEN SAY 'on.'
  189.     ELSE SAY 'off.'
  190.  
  191.     CALL CHAROUT ,'Ring Indicator (RI) is '
  192.     IF FileBit(REQ.1, 6) THEN SAY 'on.'
  193.     ELSE SAY 'off.'
  194.  
  195.     CALL CHAROUT ,'Data Carrier Detect (DCD) is '
  196.     IF FileBit(REQ.1, 7) THEN SAY 'on.'
  197.     ELSE SAY 'off.'
  198.     END
  199.  
  200.     SAY '/* ============ Query Receive Queue ============= */'
  201.     REQ.0 = 4
  202.     REQ.1 = '2.1'  /* Number of chars currently in receive queue */
  203.     REQ.2 = '2.1'  /* Size of receive queue */
  204.     err = FileDevIOCtl(handle, 1, 104, , 'REQ', 'd')
  205.     IF err <> 0 THEN SAY "ERROR querying Receive Queue:" err
  206.     ELSE DO
  207.     SAY 'Number of chars currently in receive queue:' REQ.1
  208.     SAY 'Size of receive queue:' REQ.2
  209.     END
  210.  
  211.     SAY '/* ============ Query Transmit Queue ============ */'
  212.     REQ.0 = 4
  213.     REQ.1 = '2.1'  /* Number of chars currently in transmit queue */
  214.     REQ.2 = '2.1'  /* Size of transmit queue */
  215.     err = FileDevIOCtl(handle, 1, 105, , 'REQ', 'd')
  216.     IF err <> 0 THEN SAY "ERROR querying Transmit Queue:" err
  217.     ELSE DO
  218.     SAY 'Number of chars currently in transmit queue:' REQ.1
  219.     SAY 'Size of transmit queue:' REQ.2
  220.     END
  221.  
  222.     SAY '/* ============= Query COM Error ============= */'
  223.     REQ.0 = 2
  224.     REQ.1 = 'B2.1'
  225.     err = FileDevIOCtl(handle, 1, 109, , 'REQ', 'd')
  226.     IF err <> 0 THEN SAY "ERROR querying COM Error:" err
  227.     ELSE DO
  228.     /* Each bit of the returned 16-bit ushort is for a different error. So,
  229.        we need to check each bit */
  230.     IF FileBit(REQ.1, 0) THEN SAY 'Receive queue overrun.'
  231.     IF FileBit(REQ.1, 1) THEN SAY 'Receive hardware overrun.'
  232.     IF FileBit(REQ.1, 2) THEN SAY 'Parity error.'
  233.     IF FileBit(REQ.1, 3) THEN SAY 'Framing error.'
  234.     END
  235.  
  236.     SAY '/* ============= Query COM Event ============= */'
  237.     REQ.0 = 2
  238.     REQ.1 = 'B2.1'
  239.     err = FileDevIOCtl(handle, 1, 114, , 'REQ', 'd')
  240.     IF err <> 0 THEN SAY "ERROR querying COM Event:" err
  241.     ELSE DO
  242.     /* Each bit of the returned 16-bit ushort is for a different event. So,
  243.        we need to check each bit */
  244.     IF FileBit(REQ.1, 0) THEN SAY 'Character read from receive hardware and placed into queue.'
  245.     IF FileBit(REQ.1, 1) THEN SAY 'Receive hardware timed out.'
  246.     IF FileBit(REQ.1, 2) THEN SAY 'Current write request (transmit) complete.'
  247.     IF FileBit(REQ.1, 3) THEN SAY 'Clear To Send (CTS) changed state.'
  248.     IF FileBit(REQ.1, 4) THEN SAY 'Data Set Ready (DSR) changed state.'
  249.     IF FileBit(REQ.1, 5) THEN SAY 'Data Carrier Detect (DCD) changed state.'
  250.     IF FileBit(REQ.1, 6) THEN SAY 'Break is detected.'
  251.     IF FileBit(REQ.1, 7) THEN SAY 'Framing, Parity, or receive hardware/queue overrun error.'
  252.     IF FileBit(REQ.1, 8) THEN SAY 'Trailing edge of Ring Indicator detected.'
  253.     END
  254.  
  255.     SAY '/* ========== Query DCB Parameters =========== */'
  256.     REQ.0 = 11
  257.     REQ.1 = '2.1'    /* Write Timeout (in tenths of a second, where 0 = .01 secs) */
  258.     REQ.2 = '2.1'    /* Read Timeout */
  259.     REQ.3 = 'B1.1' /* Flags1 */
  260.     REQ.4 = 'B1.1' /* Flags1 */
  261.     REQ.5 = 'B1.1' /* Flags1 */
  262.     REQ.6 = '1.1'   /* Error replacement char */
  263.     REQ.7 = '1.1'   /* Break replacement char */
  264.     REQ.8 = '1.1'   /* XON char */
  265.     REQ.9 = '1.1'   /* XOFF char */
  266.     err = FileDevIOCtl(handle, 1, 115, , 'REQ', 'd')
  267.     IF err <> 0 THEN SAY "ERROR querying DCB Parameters:" err
  268.     ELSE DO
  269.     SAY 'Write Timeout =' REQ.1
  270.     SAY 'Read Timeout =' REQ.2
  271.  
  272.     /* Each bit of Flags1 is for a different aspect. So, we need to check each bit */
  273.     CALL CHAROUT ,'DTR Control Mode = '
  274.     err = FileBit(REQ.3, 0 2, 'XTRT')  /* Extract the first 2 bits */
  275.     IF err = '00' THEN SAY 'disabled'
  276.     IF err = '01' THEN SAY 'enabled'
  277.     IF err = '10' THEN SAY 'input handshaking'
  278.     IF err = '11' THEN SAY  /* Invalid. You should never get this */
  279.  
  280.     IF FileBit(REQ.3, 3) THEN SAY 'Output handshaking using CTS.'
  281.     IF FileBit(REQ.3, 4) THEN SAY 'Output handshaking using DSR.'
  282.     IF FileBit(REQ.3, 5) THEN SAY 'Output handshaking using DCD.'
  283.     IF FileBit(REQ.3, 6) THEN SAY 'Input sensitivity using DSR.'
  284.  
  285.     /* Each bit of Flags2 is for a different aspect. So, we need to check each bit */
  286.     IF FileBit(REQ.4, 0) THEN SAY 'Automatic Flow Control (XON/XOFF) on transmit.'
  287.     IF FileBit(REQ.4, 1) THEN SAY 'Automatic Flow Control (XON/XOFF) on receive.'
  288.     IF FileBit(REQ.4, 2) THEN SAY 'Error Replacement Char is enabled.'
  289.     IF FileBit(REQ.4, 3) THEN SAY 'Null (zero byte) stripping is enabled.'
  290.     IF FileBit(REQ.4, 4) THEN SAY 'Break Replacement Char is enabled.'
  291.  
  292.     CALL CHAROUT ,'Receive Duplex = '
  293.     IF FileBit(REQ.4, 5) THEN SAY 'full.'
  294.     ELSE SAY 'normal.'
  295.  
  296.     CALL CHAROUT ,'RTS Control Mode = '
  297.     err = FileBit(REQ.4, 6 2, 'XTRT')
  298.     IF err = '00' THEN SAY 'disabled'
  299.     IF err = '01' THEN SAY 'enabled'
  300.     IF err = '10' THEN SAY 'input handshaking'
  301.     IF err = '11' THEN SAY 'toggle on transmit'
  302.  
  303.     /* Each bit of Flags3 is for a different aspect. So, we need to check each bit */
  304.     IF FileBit(REQ.5, 0) THEN SAY 'Infinite timeout for writes.'
  305.  
  306.     CALL CHAROUT ,'Read timeout mode = '
  307.     err = FileBit(REQ.5, 1 2, 'XTRT')
  308.     IF err = '00' THEN SAY /* Invalid */
  309.     IF err = '01' THEN SAY 'normal timeout'
  310.     IF err = '10' THEN SAY 'wait for something'
  311.     IF err = '11' THEN SAY 'no waiting'
  312.  
  313.     CALL CHAROUT ,'Extended hardware buffering = '
  314.     err = FileBit(REQ.5, 3 2, 'XTRT')
  315.     IF err = '00' THEN SAY 'not supported'
  316.     IF err = '01' THEN SAY 'disabled'
  317.     IF err = '10' THEN SAY 'enabled'
  318.     IF err = '11' THEN SAY 'automatic protocol override'
  319.  
  320.     CALL CHAROUT ,'Receive trigger level = '
  321.     err = FileBit(REQ.5, 5 2, 'XTRT')
  322.     IF err = '00' THEN SAY '1 char'
  323.     IF err = '01' THEN SAY '4 chars'
  324.     IF err = '10' THEN SAY '8 chars'
  325.     IF err = '11' THEN SAY '14 chars'
  326.  
  327.     CALL CHAROUT ,'Transmit buffer load count = '
  328.     IF FileBit(REQ.5, 7) THEN SAY '16 chars'
  329.     ELSE SAY '1 char'
  330.  
  331.     /* Error replacement char */
  332.     SAY 'Error replacement char (as an ascii number) =' REQ.6
  333.  
  334.     /* Break replacement char */
  335.     SAY 'Break replacement char (as an ascii number) =' REQ.7
  336.  
  337.     /* XON char */
  338.     SAY 'XON char (as an ascii number) =' REQ.8
  339.  
  340.     /* XOFF char */
  341.     SAY 'XOFF char (as an ascii number) =' REQ.9
  342.     END
  343.  
  344.  
  345.     SAY '/* ====== Query Enhanced Mode Parameters ===== */'
  346.     REQ.0 = 5
  347.     REQ.1 = 'B1.1' /* Flags */
  348.     REQ.2 = '4.1'   /* Reserved */
  349.     err = FileDevIOCtl(handle, 1, 116, , 'REQ', 'd')
  350.     IF err <> 0 THEN SAY "ERROR querying Enhanced Mode Parameters:" err
  351.     ELSE DO
  352.     /* Each bit of Flags is for a different aspect. So, we need to check each bit */
  353.  
  354.     CALL CHAROUT ,'Enhanced Mode is '
  355.  
  356.     /* Is Enhanced Mode supported by the driver? */
  357.     IF FileBit(REQ.1, 0) THEN DO
  358.         SAY 'supported'
  359.  
  360.         /* Is Enhanced Mode enabled? */
  361.         IF FileBit(REQ.1, 1) THEN DO
  362.          SAY ', and enabled.'
  363.  
  364.          /* DMA Receive Operation */
  365.          CALL CHAROUT ,'DMA Receive Operation = '
  366.          err = FileBit(REQ.1, 2 2, 'XTRT')
  367.          IF err = '00' THEN SAY 'disabled'
  368.          IF err = '01' THEN SAY 'enabled'
  369.          IF err = '10' THEN SAY 'dedicated DMA channel'
  370.          IF err = '11' THEN SAY  /* Invalid. You should never get this */
  371.  
  372.          /* DMA Transmit Operation */
  373.          CALL CHAROUT ,'DMA Transmit Operation = '
  374.          err = FileBit(REQ.1, 4 2, 'XTRT')
  375.          IF err = '00' THEN SAY 'disabled'
  376.          IF err = '01' THEN SAY 'enabled'
  377.          IF err = '10' THEN SAY 'dedicated DMA channel'
  378.          IF err = '11' THEN SAY  /* Invalid. You should never get this */
  379.  
  380.          /* Receive or Transmit DMA Operation in progress? */
  381.          IF FileBit(REQ.1, 6) THEN SAY 'Receive currently doing DMA Operation.'
  382.          IF FileBit(REQ.1, 7) THEN SAY 'Transmit currently doing DMA Operation.'
  383.         END
  384.  
  385.         /* Enhanced Mode not enabled */
  386.         ELSE SAY ', but not enabled.'
  387.     END
  388.  
  389.     /* Enhanced Mode not supported */
  390.     ELSE SAY 'not supported.'
  391.     END
  392.  
  393.  
  394.  
  395.     SAY "/* ====== Clear out driver's input queue ===== */"
  396.     /* Clear out any queued input waiting to be read before we do the
  397.        write and read operations below. We don't want FileGets to have
  398.        to wade through anything except what the modem sends AFTER
  399.        we do the FilePuts */
  400.     REQ.0 = 1
  401.     REQ.1 = '1.1.0'   /* Command. Must be 0 */
  402.     DATA.0 = 1
  403.     DATA.1 = '1.1.0'  /* Reserved */
  404.     err = FileDevIOCtl(handle, 11, 1, 'REQ', 'DATA')
  405.     IF err <> 0 THEN SAY "ERROR flushing input queue:" err
  406.  
  407.  
  408.  
  409.     /* ============================ FilePuts ============================= */
  410.     /* Send the Hayes command string 'ATZ' (followed by a line feed, so we use FilePuts
  411.     to automatically send that terminating line feed) to the modem */
  412.     SAY '/* ====== Send the modem reset string ===== */'
  413.     err = FilePuts(handle, 'ATZ')
  414.     IF err <> 5 THEN SAY 'Error sending ATZ'
  415.  
  416.  
  417.  
  418.     /* ============================ FileGets ============================= */
  419.     /** Read the "OK" line that we expect back from the modem. The modem
  420.       would send this with a line feed character at the end, so we can use
  421.       FileGets
  422.      **/
  423.     SAY '/* ====== Wait for "OK" response from the modem ===== */'
  424.     DO UNTIL err = 'OK'
  425.     err = FileGets(handle, 'tsc')
  426.     SAY err  /* Print out the line that we read from the modem */
  427.     END
  428.  
  429.  
  430.  
  431.     /* ============================ FileClose ============================= */
  432.     /** Close the device driver.
  433.      **/
  434.     err = FileClose(handle)
  435.  
  436. END
  437.  
  438.  
  439.  
  440. /* Error opening the driver */
  441. ELSE SAY "ERROR: Can't open 'port' driver"
  442.  
  443.  
  444.  
  445. /* ============================== clean up =============================== */
  446. /* Drop the functions in FileRexx */
  447. CALL FileDropFuncs
  448.  
  449. /* Done */
  450. EXIT
  451.