home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxasync2.zip / RXASYNC.CMD < prev    next >
OS/2 REXX Batch file  |  1994-12-27  |  28KB  |  740 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*  MODULE         RXASYNC.cmd                                               */
  4. /*                                                                           */
  5. /*  VERSION        Version 2.0 - 26th Dec 1994                               */
  6. /*                                                                           */
  7. /*  COPYRIGHT      Copyright (c) 1993, 1994 by Crucial Applications          */
  8. /*                              All rights reserved.                         */
  9. /*                                                                           */
  10. /*  AUTHOR         Ian Timms                                                 */
  11. /*                                                                           */
  12. /*  DESCRIPTION                                                              */
  13. /*                                                                           */
  14. /*    Test the essential RXASYNC.DLL functions to make sure they work.       */
  15. /*                                                                           */
  16. /*    NOTE: Only those functions indicated with '+' are tested by this       */
  17. /*          routine.                                                         */
  18. /*                                                                           */
  19. /*  FUNCTIONS                                                                */
  20. /*                                                                           */
  21. /*       House keeping                                                       */
  22. /*                                                                           */
  23. /*  + RxAsyncDropFuncs     -   Drop the functions from REXX                  */
  24. /*  + RxAsyncLoadFuncs     -   Load the functions into REXX                  */
  25. /*                                                                           */
  26. /*       Process control                                                     */
  27. /*                                                                           */
  28. /*  + RxAsyncPriority      -   Set Rexx process priority                     */
  29. /*  + RxAsyncSleep         -   Wait for some defined period                  */
  30. /*                                                                           */
  31. /*       ASYNC IOCTL interface                                               */
  32. /*                                                                           */
  33. /*  + RxAsyncGetDcbInfo    -   Get the device control block info             */
  34. /*  + RxAsyncSetDcbInfo    -   Set the device control block info             */
  35. /*  + RxAsyncGetEnhParm    -   Get the enhanced parameters                   */
  36. /*  + RxAsyncSetEnhParm    -   Set the enhanced parameters                   */
  37. /*  + RxAsyncGetLnCtrl     -   Get the comms port settings                   */
  38. /*  + RxAsyncSetLnCtrl     -   Set the comms port settings                   */
  39. /*                                                                           */
  40. /*    RxAsyncSetBreakOff   -   Turn break off                                */
  41. /*    RxAsyncSetBreakOn    -   Turn break on                                 */
  42. /*    RxAsyncTxImmediate   -   Transmit byte immediately                     */
  43. /*    RxAsyncTxStop        -   Stop transmission (ala XOFF)                  */
  44. /*    RxAsyncTxStart       -   Start transmission (ala XON)                  */
  45. /*    RxAsyncGetComStatus  -   Get COM status                                */
  46. /*    RxAsyncGetTxStatus   -   Get Transmit status                           */
  47. /*    RxAsyncGetMdmOutput  -   Get modem output signals                      */
  48. /*    RxAsyncGetMdmInput   -   Get modem input signals                       */
  49. /*  + RxAsyncSetMdmOutput  -   Set modem output signals                      */
  50. /*    RxAsyncGetRxCount    -   Get size and number of chars in RX queue      */
  51. /*    RxAsyncGetTxCount    -   Get size and number of chars in TX queue      */
  52. /*    RxAsyncGetComError   -   Get the COM Error Word                        */
  53. /*    RxAsyncGetComEvent   -   Get the COM Event Word                        */
  54. /*                                                                           */
  55. /*       Extensions                                                          */
  56. /*                                                                           */
  57. /*  + RxAsyncOpen          -   Open the specified comms port                 */
  58. /*  + RxAsyncClose         -   Close the specified comms port                */
  59. /*  + RxAsyncWait          -   Wait for receipt of input                     */
  60. /*  + RxAsyncWatch         -   Wait for receipt of specified strings         */
  61. /*  + RxAsyncRead          -   Read data and wait if necessary               */
  62. /*  + RxAsyncWrite         -   Write data to the comms port                  */
  63. /*  + RxAsyncCarrier       -   Test/Wait for Data Carrier Detect (DCD)       */
  64. /*  + RxAsyncBreak         -   Send break for defined period                 */
  65. /*  + RxAsyncDcbInfo       -   Print the device control block info           */
  66. /*  + RxAsyncActive        -   Test for active modem signal                  */
  67. /*  + RxAsyncRaise         -   Raise specified modem signal                  */
  68. /*  + RxAsyncLower         -   Lower specified modem signal                  */
  69. /*                                                                           */
  70. /*       File handling                                                       */
  71. /*                                                                           */
  72. /*  + RxAsyncFileExists    -   Test for file(s) existence                    */
  73. /*  + RxAsyncFileDelete    -   Delete specified file                         */
  74. /*  + RxAsyncFileCopy      -   Copy specified file                           */
  75. /*  + RxAsyncFileMove      -   Move specified file                           */
  76. /*  + RxAsyncFileRename    -   Rename specified file                         */
  77. /*  + RxAsyncFileNameIs    -   Determine file name                           */
  78. /*  + RxAsyncFilePathIs    -   Determine file path                           */
  79. /*  + RxAsyncDirectory     -   Query/Change directory/drive                  */
  80. /*                                                                           */
  81. /*       Miscellaneous                                                       */
  82. /*                                                                           */
  83. /*  + RxAsyncPrint         -   Print string on stdout                        */
  84. /*    RxAsyncMsgBox        -   Display PM message box (PM use only)          */
  85. /*                                                                           */
  86. /*  HISTORY                                                                  */
  87. /*     IT940607 - Added comment re non-16550, thanks to Andre Boisvert for   */
  88. /*                pointing this one out.                                     */
  89. /*     IT941226 - Updated for version 2.0.                                   */
  90. /*                                                                           */
  91. /*****************************************************************************/
  92.  
  93. call on error
  94.  
  95. /*--------------------------------------------------------------*/
  96. /* NOTE: Adjust the following as required by your configuration */
  97. /*       If you do NOT have a 16550 UART then set newFlags3     */
  98. /*       to '00000010'. (see the RXASYNC.tip for more info.)    */
  99. /*--------------------------------------------------------------*/
  100.  
  101. PortName      = 'COM4'
  102. newBaud       = 19200
  103. newData       = 8
  104. newParity     = 'N'
  105. newStop       = 1
  106. newWriteLim   = 50
  107. newReadLim    = 50
  108. newFlags1     = '00001001'
  109. newFlags2     = '10100000'
  110. newFlags3     = '11010010'
  111. newErrChar    = '00'
  112. newBrkChar    = '00'
  113. newXonChar    = '11'
  114. newXoffChar   = '13'
  115. newEnhParms   = '00000010'
  116.  
  117. PortHandle    = ''
  118. old.Baud      = 0
  119. old.Data      = 0
  120. old.Parity    = ''
  121. old.Stop      = 0
  122. old.WriteLim  = 0
  123. old.ReadLim   = 0
  124. old.Flags1    = ''
  125. old.Flags2    = ''
  126. old.Flags3    = ''
  127. old.ErrChar   = ''
  128. old.BrkChar   = ''
  129. old.XonChar   = ''
  130. old.XoffChar  = ''
  131. old.EnhParms  = ''
  132.  
  133. True          = 1
  134. False         = 0
  135. Regular       = 2
  136. Critical      = 3
  137. NormalLvl     = 0
  138. InpStr        = ''
  139. Remaining     = 0
  140. crlf          = D2C(13)''D2C(10)
  141. none_on       = '00'
  142. dtr_on        = '01'
  143. rts_on        = '02'
  144. both_on       = '03'
  145. none_off      = 'FF'
  146. dtr_off       = 'FE'
  147. rts_off       = 'FD'
  148. both_off      = 'FC'
  149.  
  150. /*=====================================================================*/
  151. /* setup                                                               */
  152. /*=====================================================================*/
  153.  
  154. call RxFuncAdd 'RxAsyncLoadFuncs', 'RXASYNC', 'RxAsyncLoadFuncs'
  155. say 'RxAsyncRc =>'RxAsyncRc'<'
  156. call RxAsyncLoadFuncs
  157. Say 'RxAsyncLoadFuncs is complete'
  158. say 'RxAsyncRc =>'RxAsyncRc'<'
  159.  
  160. /*=====================================================================*/
  161. /* initialisation                                                      */
  162. /*=====================================================================*/
  163.  
  164. /* set session priority */
  165.  
  166. rc = RxAsyncPriority( Critical, NormalLvl )
  167. if rc <> 0
  168.    then say 'RxAsyncPriority failed with rc=>'rc'<'
  169.    else say 'RxAsyncPriority set, Class=>'Critical'<, Level=>'NormalLvl'<'
  170.  
  171. /* open device */
  172.  
  173. rc = RxAsyncOpen( PortName, 'PortHandle' )
  174. if rc <> 0
  175.    then say 'RxAsyncOpen failed with rc=>'rc'<'
  176.    else say 'RxAsyncOpen opened the device handle=>'PortHandle'<'
  177.  
  178. /*=====================================================================*/
  179. /* line control handling                                               */
  180. /*=====================================================================*/
  181.  
  182. /* save original line control settings */
  183.  
  184. rc = RxAsyncGetLnCtrl( PortHandle, 'old.Baud', 'old.Data', 'old.Parity', 'old.Stop' )
  185. if rc <> 0
  186.    then say 'RxAsyncGetLnCtrl failed with rc=>'rc'<'
  187.    else say 'RxAsyncGetLnCtrl saved the original settings'
  188.  
  189. say 'Baudrate >'old.Baud'<'
  190. say 'Databits >'old.Data'<'
  191. say 'Parity   >'old.Parity'<'
  192. say 'Stopbits >'old.Stop'<'
  193.  
  194. /* set new line control settings */
  195.  
  196. rc = RxAsyncSetLnCtrl( PortHandle, newBaud, newData, newParity, newStop )
  197. if rc <> 0
  198.    then say 'RxAsyncSetLnCtrl failed with rc=>'rc'<'
  199.    else say 'RxAsyncSetLnCtrl set the new settings'
  200.  
  201. /* query new line control settings */
  202.  
  203. rc = RxAsyncGetLnCtrl( PortHandle, 'newBaud', 'newData', 'newParity', 'newStop' )
  204. if rc <> 0
  205.    then say 'RxAsyncGetLnCtrl failed with rc=>'rc'<'
  206.    else say 'RxAsyncGetLnCtrl queried the new settings'
  207.  
  208. say 'Baudrate >'newBaud'<'
  209. say 'Databits >'newData'<'
  210. say 'Parity   >'newParity'<'
  211. say 'Stopbits >'newStop'<'
  212.  
  213. /*=====================================================================*/
  214. /* device control block handling                                       */
  215. /*=====================================================================*/
  216.  
  217. /* save original dcb info settings */
  218.  
  219. rc = RxAsyncGetDcbInfo( PortHandle, 'old.WriteLim', 'old.ReadLim', 'old.Flags1', 'old.Flags2', 'old.Flags3', 'old.ErrChar', 'old.BrkChar', 'old.XonChar', 'old.XoffChar' )
  220. if rc <> 0
  221.    then say 'RxAsyncGetDcbInfo failed with rc=>'rc'<'
  222.    else say 'RxAsyncGetDcbInfo saved the original settings'
  223.  
  224. old.Flags1 = X2B(old.Flags1)
  225. old.Flags2 = X2B(old.Flags2)
  226. old.Flags3 = X2B(old.Flags3)
  227.  
  228. say 'Write Timeout  >'old.WriteLim'<'
  229. say 'Read  Timeout  >'old.ReadLim'<'
  230. say 'F1 HandShake   >'old.Flags1'<'
  231. say 'F2 FlowReplace >'old.Flags2'<'
  232. say 'F3 Timeout     >'old.Flags3'<'
  233. say 'Error Replace  >'old.ErrChar'<'
  234. say 'Break Replace  >'old.BrkChar'<'
  235. say 'Xon character  >'old.XonChar'<'
  236. say 'Xoff character >'old.XoffChar'<'
  237.  
  238. /* set new dcb info settings */
  239.  
  240. rc = RxAsyncSetDcbInfo( PortHandle, newWriteLim, newReadLim, newFlags1, newFlags2, newFlags3, newErrChar, newBrkChar, newXonChar, newXoffChar )
  241. if rc <> 0
  242.    then say 'RxAsyncSetDcbInfo failed with rc=>'rc'<'
  243.    else say 'RxAsyncSetDcbInfo set the new settings'
  244.  
  245. /* query new dcb info settings */
  246.  
  247. rc = RxAsyncGetDcbInfo( PortHandle, 'newWriteLim', 'newReadLim', 'newFlags1', 'newFlags2', 'newFlags3', 'newErrChar', 'newBrkChar', 'newXonChar', 'newXoffChar' )
  248. if rc <> 0
  249.    then say 'RxAsyncGetDcbInfo failed with rc=>'rc'<'
  250.    else say 'RxAsyncGetDcbInfo queried the new settings'
  251.  
  252. newFlags1 = X2B(newFlags1)
  253. newFlags2 = X2B(newFlags2)
  254. newFlags3 = X2B(newFlags3)
  255.  
  256. say 'Write Timeout  >'newWriteLim'<'
  257. say 'Read  Timeout  >'newReadLim'<'
  258. say 'F1 HandShake   >'newFlags1'<'
  259. say 'F2 FlowReplace >'newFlags2'<'
  260. say 'F3 Timeout     >'newFlags3'<'
  261. say 'Error Replace  >'newErrChar'<'
  262. say 'Break Replace  >'newBrkChar'<'
  263. say 'Xon character  >'newXonChar'<'
  264. say 'Xoff character >'newXoffChar'<'
  265.  
  266. /*=====================================================================*/
  267. /* enhanced parameter handling                                         */
  268. /*=====================================================================*/
  269.  
  270. /* save original enhanced parms settings */
  271.  
  272. rc = RxAsyncGetEnhParm( PortHandle, 'old.EnhParms' )
  273. if rc <> 0
  274.    then say 'RxAsyncGetEnhParm failed with rc=>'rc'<'
  275.    else say 'RxAsyncGetEnhParm saved the original settings'
  276.  
  277. old.EnhParms = X2B(old.EnhParms)
  278.  
  279. say 'Enhanced Parms >'old.EnhParms'<'
  280.  
  281. /* set new enhanced parms settings */
  282.  
  283. rc = RxAsyncSetEnhParm( PortHandle, newEnhParms )
  284. if rc <> 0
  285.    then say 'RxAsyncSetEnhParm failed with rc=>'rc'<'
  286.    else say 'RxAsyncSetEnhParm set the new settings'
  287.  
  288. /* query new enhanced parms settings */
  289.  
  290. rc = RxAsyncGetEnhParm( PortHandle, 'newEnhParms' )
  291. if rc <> 0
  292.    then say 'RxAsyncGetEnhParm failed with rc=>'rc'<'
  293.    else say 'RxAsyncGetEnhParm queried the new settings'
  294.  
  295. newEnhParms = X2B(newEnhParms)
  296.  
  297. say 'Enhanced Parms >'newEnhParms'<'
  298.  
  299. /*=====================================================================*/
  300. /* test read, write and wait functions                                 */
  301. /*=====================================================================*/
  302.  
  303. /* write modem reset string */
  304.  
  305. rc = RxAsyncWrite( PortHandle, 0, 'ATZ'||D2C(13), 'Remaining' )
  306. if rc <> 0
  307.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  308.    else say 'RxAsyncWrite output ATZ<cr>'
  309.  
  310. /* read modem response */
  311.  
  312. InpStr = ""
  313. GetOk = True
  314. Tries = 10
  315. do while GetOk
  316.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  317.    GetOk = False
  318.    select
  319.      when Tries <= 0 then nop
  320.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  321.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  322.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  323.      otherwise
  324.         say 'RxAsyncRead returned >'InpStr'<'
  325.         GetOk = True
  326.         Tries = Tries - 1
  327.    end
  328. end
  329.  
  330. /* write modem display settings string */
  331.  
  332. call RxAsyncWrite PortHandle, 0, 'AT&V0'||D2C(13), 'Remaining'
  333. if RxAsyncRc <> 0
  334.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  335.    else say 'RxAsyncWrite output AT&V0<cr>'
  336. say 'RxAsyncRc =>'RxAsyncRc'<'
  337.  
  338. /* read the rest */
  339.  
  340. InpStr = ""
  341. GetOk = True
  342. Tries = 60
  343. do while GetOk
  344.    call RxAsyncRead PortHandle, 0, 3000, 'InpStr'
  345.    GetOk = False
  346.    select
  347.      when Tries <= 0 then nop
  348.      when RxAsyncRc <> 0             then say 'RxAsyncRead failed with rc=>'RxAsyncRc'<'
  349.      when InpStr == "OK"||crlf       then say 'RxAsyncRead returned >'InpStr'<'
  350.      when InpStr == "ERROR"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  351.      otherwise
  352.         say 'RxAsyncRead returned >'InpStr'<'
  353.         GetOk = True
  354.         Tries = Tries - 1
  355.    end
  356. end
  357. say 'RxAsyncRc =>'RxAsyncRc'<'
  358.  
  359. /* write modem display settings string */
  360.  
  361. rc = RxAsyncWrite( PortHandle, 0, 'AT&V0'||D2C(13), 'Remaining' )
  362. if rc <> 0
  363.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  364.    else say 'RxAsyncWrite output AT&V0<cr>'
  365.  
  366. /* watch for 'Auto','&L','Fixed' modem response */
  367.  
  368. MatchStr.0 = 3
  369. MatchStr.1 = '&l'
  370. MatchStr.2 = 'FiXeD'
  371. MatchStr.3 = 'AuTo'
  372. InpStr = ''
  373. NumFound = 0
  374. rc =  RxAsyncWatch( PortHandle, 'MatchStr', 'Y', 3000, 'InpStr', 'NumFound' )
  375. if rc = 0
  376.    then do
  377.           say 'RxAsyncWatch returned >'InpStr'<'
  378.           say 'Index of string found was >'NumFound'<'
  379.         end
  380.    else if rc = -1
  381.            then say 'RxAsyncWatch timed out'
  382.            else say 'RxAsyncWatch failed rc=>'rc'<'
  383.  
  384. /* read the rest */
  385.  
  386. InpStr = ""
  387. GetOk = True
  388. Tries = 60
  389. do while GetOk
  390.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  391.    GetOk = False
  392.    select
  393.      when Tries <= 0 then nop
  394.      when rc <> 0                    then say 'RxAsyncRead failed with rc=>'rc'<'
  395.      when InpStr == "OK"||crlf       then say 'RxAsyncRead returned >'InpStr'<'
  396.      when InpStr == "ERROR"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  397.      otherwise
  398.         say 'RxAsyncRead returned >'InpStr'<'
  399.         GetOk = True
  400.         Tries = Tries - 1
  401.    end
  402. end
  403.  
  404. /* write AT<cr> string */
  405.  
  406. rc = RxAsyncWrite( PortHandle, 0, 'AT'D2C(13), 'Remaining' )
  407. if rc <> 0
  408.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  409.    else say 'RxAsyncWrite output AT<cr>'
  410.  
  411. /* read modem response */
  412.  
  413. InpStr = ""
  414. GetOk = True
  415. Tries = 10
  416. do while GetOk
  417.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr', , d2c(13) )
  418.    GetOk = False
  419.    select
  420.      when Tries <= 0 then nop
  421.      when rc <> 0                    then say 'RxAsyncRead failed with rc=>'rc'<'
  422.      when InpStr == "OK"||d2c(13)    then say 'RxAsyncRead returned >'InpStr'<'
  423.      when InpStr == "ERROR"||d2c(13) then say 'RxAsyncRead returned >'InpStr'<'
  424.      otherwise
  425.         say 'RxAsyncRead returned >'InpStr'<'
  426.         GetOk = True
  427.         Tries = Tries - 1
  428.    end
  429. end
  430.  
  431. /* consume following linefeed */
  432.  
  433. InpStr = ""
  434. GetOk = True
  435. Tries = 10
  436. do while GetOk
  437.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  438.    GetOk = False
  439.    select
  440.      when Tries <= 0 then nop
  441.      when rc <> 0              then say 'RxAsyncRead failed with rc=>'rc'<'
  442.      when InpStr == d2c(10)    then say 'RxAsyncRead returned >'InpStr'<'
  443.      otherwise
  444.         say 'RxAsyncRead returned >'InpStr'<'
  445.         GetOk = True
  446.         Tries = Tries - 1
  447.    end
  448. end
  449.  
  450. /* write bad string */
  451.  
  452. rc = RxAsyncWrite( PortHandle, 0, 'AT CAUSE AN ERROR'||D2C(13), 'Remaining' )
  453. if rc <> 0
  454.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  455.    else say 'RxAsyncWrite output AT CAUSE AN ERROR<cr>'
  456.  
  457. /* read modem response */
  458.  
  459. InpStr = ""
  460. GetOk = True
  461. Tries = 10
  462. do while GetOk
  463.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  464.    GetOk = False
  465.    select
  466.      when Tries <= 0 then nop
  467.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  468.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  469.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  470.      otherwise
  471.         say 'RxAsyncRead returned >'InpStr'<'
  472.         GetOk = True
  473.         Tries = Tries - 1
  474.    end
  475. end
  476.  
  477. /* write a query string */
  478.  
  479. rc = RxAsyncWrite( PortHandle, 0, 'ATS7?'||D2C(13), 'Remaining' )
  480. if rc <> 0
  481.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  482.    else say 'RxAsyncWrite output ATS7?<cr>'
  483.  
  484. /* read modem response */
  485.  
  486. InpStr = ""
  487. GetOk = True
  488. Tries = 10
  489. do while GetOk
  490.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  491.    GetOk = False
  492.    select
  493.      when Tries <= 0 then nop
  494.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  495.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  496.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  497.      otherwise
  498.         say 'RxAsyncRead returned >'InpStr'<'
  499.         GetOk = True
  500.         Tries = Tries - 1
  501.    end
  502. end
  503.  
  504. /* write modem attention string */
  505.  
  506. rc = RxAsyncWrite( PortHandle, 0, 'AT'D2C(13), 'Remaining' )
  507. if rc <> 0
  508.    then say 'Modem may not be turned on, >'Remaining'< chars unwritten'
  509.    else say 'RxAsyncWrite output AT<cr>'
  510.  
  511. /* wait three seconds or until there is data to be read */
  512.  
  513. say 'Wait for data 'time()
  514. rc = RxAsyncWait( PortHandle, 3000 )
  515. say 'Waited enough 'time()
  516. if rc = 0
  517.    then say 'RxAsyncWait detected input'
  518.    else if rc = -1
  519.            then say 'RxAsyncWait timed out'
  520.            else say 'RxAsyncWait returned rc=>'rc'<'
  521.  
  522. /* wait for carrier signal */
  523.  
  524. say 'Wait for carrier'
  525. rc = RxAsyncCarrier( PortHandle, 3000 )
  526. say 'Waited enough'
  527. if rc = 0
  528.    then say 'RxAsyncCarrier detected DCD'
  529.    else if rc = -1
  530.            then say 'RxAsyncCarrier timed out'
  531.            else say 'RxAsyncCarrier returned rc=>'rc'<'
  532.  
  533. /* test for carrier signal */
  534.  
  535. say 'Test for carrier'
  536. rc = RxAsyncCarrier( PortHandle )
  537. if rc = 0
  538.    then say 'RxAsyncCarrier detected DCD'
  539.    else if rc = -2
  540.            then say 'RxAsyncCarrier did not detect DCD'
  541.            else say 'RxAsyncCarrier returned rc=>'rc'<'
  542.  
  543. /* read modem response */
  544.  
  545. InpStr = ""
  546. GetOk = True
  547. Tries = 10
  548. do while GetOk
  549.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  550.    GetOk = False
  551.    select
  552.      when Tries <= 0 then nop
  553.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  554.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  555.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  556.      otherwise
  557.         say 'RxAsyncRead returned >'InpStr'<'
  558.         GetOk = True
  559.         Tries = Tries - 1
  560.    end
  561. end
  562.  
  563. /* write query string */
  564.  
  565. rc = RxAsyncWrite( PortHandle, 0, 'ATS1?'||D2C(13), 'Remaining' )
  566. if rc <> 0
  567.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  568.    else say 'RxAsyncWrite output ATS1?<cr>'
  569.  
  570. /* read modem response */
  571.  
  572. InpStr = ""
  573. GetOk = True
  574. Tries = 10
  575. do while GetOk
  576.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  577.    GetOk = False
  578.    select
  579.      when Tries <= 0 then nop
  580.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  581.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  582.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  583.      otherwise
  584.         say 'RxAsyncRead returned >'InpStr'<'
  585.         GetOk = True
  586.         Tries = Tries - 1
  587.    end
  588. end
  589.  
  590. /*=====================================================================*/
  591. /* miscellaneous                                                       */
  592. /*=====================================================================*/
  593.  
  594. /* send break for half a second */
  595.  
  596. BreakTime = 500
  597. rc = RxAsyncBreak( PortHandle, BreakTime )
  598. if rc <> 0
  599.    then say 'RxAsyncBreak failed with rc=>'rc'<'
  600.    else say 'RxAsyncBreak sent break for 'BreakTime' milliseconds'
  601.  
  602. /* print dcb info */
  603.  
  604. rc = RxAsyncDcbInfo( PortHandle )
  605. if rc <> 0
  606.    then say 'RxAsyncDcbInfo failed with rc=>'rc'<'
  607.    else say 'RxAsyncDcbInfo returned okay'
  608.  
  609. /* print something on stdout */
  610.  
  611. call RxAsyncPrint crlf||'Well, how do you like it so far.<g>'||crlf
  612.  
  613. /* turn DTR off (DTR is normally on once port is open) */
  614.  
  615. rc = RxAsyncSetMdmOutput( PortHandle, none_on, dtr_off )
  616. if rc <> 0
  617.    then say 'RxAsyncSetMdmOutput failed with rc=>'rc'<'
  618.    else say 'RxAsyncSetMdmOutput disabled DTR'
  619.  
  620. /* sleep 2 seconds for modem to recognise DTR toggle */
  621.  
  622. call RxAsyncSleep 2000
  623.  
  624. /* turn DTR on */
  625.  
  626. rc = RxAsyncSetMdmOutput( PortHandle, dtr_on, none_off )
  627. if rc <> 0
  628.    then say 'RxAsyncSetMdmOutput failed with rc=>'rc'<'
  629.    else say 'RxAsyncSetMdmOutput enabled DTR'
  630.  
  631. /* Test if CTS active */
  632.  
  633. if RxAsyncActive( PortHandle, "CTS" )
  634.    then say 'RxAsyncActive said CTS was active'
  635.    else say 'RxAsyncActive said CTS was NOT active'
  636.  
  637. /* DTR toggle a different way */
  638.  
  639. rc = RxAsyncLower( PortHandle, "DTR" )
  640. if rc <> 0
  641.    then say 'RxAsyncLower failed with rc=>'rc'<'
  642.    else say 'RxAsyncLower dropped DTR'
  643.  
  644. rc = RxAsyncRaise( PortHandle, "DTR" )
  645. if rc <> 0
  646.    then say 'RxAsyncRaise failed with rc=>'rc'<'
  647.    else say 'RxAsyncRaise enabled DTR'
  648.  
  649. /*=====================================================================*/
  650. /* test file and directory handling                                    */
  651. /*=====================================================================*/
  652.  
  653. fdir = RxAsyncDirectory('.')
  654. fnam = fdir||'RXASYNC'
  655.  
  656. if RxAsyncFileExists( fnam'.cmd' )
  657.    then say 'File 'fnam'.cmd was found'
  658.    else say 'File 'fnam'.cmd was not found'
  659.  
  660. if RxAsyncFileCopy( fnam'.cmd', fnam'.xxx' )
  661.    then say 'File 'fnam'.cmd copied to 'fnam'.xxx'
  662.    else say 'File 'fnam'.cmd not copied to 'fnam'.xxx'
  663.  
  664. if RxAsyncFileMove( fnam'.xxx', fnam'.yyy' )
  665.    then say 'File 'fnam'.xxx was moved to 'fnam'.yyy'
  666.    else say 'File 'fnam'.xxx was not moved to 'fnam'.yyy'
  667.  
  668. if RxAsyncFileRename( fnam'.yyy', fnam'.xxx' )
  669.    then say 'File 'fnam'.yyy was renamed to 'fnam'.xxx'
  670.    else say 'File 'fnam'.yyy was not renamed to 'fnam'.xxx'
  671.  
  672. if RxAsyncFileDelete( fnam'.xxx' )
  673.    then say 'File 'fnam'.xxx was deleted'
  674.    else say 'File 'fnam'.xxx was not deleted'
  675.  
  676. say 'Path is 'RxAsyncFilePathIs( fnam'.cmd' )
  677.  
  678. say 'Name is 'RxAsyncFileNameIs( fnam'.cmd' )
  679.  
  680. /*=====================================================================*/
  681. /* reset changes made to port settings                                 */
  682. /*=====================================================================*/
  683.  
  684. /* reset to original enhanced parms settings */
  685.  
  686. rc = RxAsyncSetEnhParm( PortHandle, old.EnhParms )
  687. if rc <> 0
  688.    then say 'RxAsyncSetEnhParm failed with rc=>'rc'<'
  689.    else say 'RxAsyncSetEnhParm restored the original settings'
  690.  
  691. /* reset to original dcb info settings */
  692.  
  693. rc = RxAsyncSetDcbInfo( PortHandle, old.WriteLim, old.ReadLim, old.Flags1, old.Flags2, old.Flags3, old.ErrChar, old.BrkChar, old.XonChar, old.XoffChar )
  694. if rc <> 0
  695.    then say 'RxAsyncSetDcbInfo failed with rc=>'rc'<'
  696.    else say 'RxAsyncSetDcbInfo restored the original settings'
  697.  
  698. /* reset to original line control settings */
  699.  
  700. rc = RxAsyncSetLnCtrl( PortHandle, old.Baud, old.Data, old.Parity, old.Stop )
  701. if rc <> 0
  702.    then say 'RxAsyncSetLnCtrl failed with rc=>'rc'<'
  703.    else say 'RxAsyncSetLnCtrl restored the original settings'
  704.  
  705. /*=====================================================================*/
  706. /* termination                                                         */
  707. /*=====================================================================*/
  708.  
  709. /* close the device */
  710.  
  711. rc = RxAsyncClose( PortHandle )
  712. if rc <> 0
  713.    then say 'RxAsyncClose failed with rc=>'rc'<'
  714.    else say 'RxAsyncClose closed the device'
  715.  
  716. /* reset session priority */
  717.  
  718. rc = RxAsyncPriority( Regular, NormalLvl )
  719. if rc <> 0
  720.    then say 'RxAsyncPriority failed with rc=>'rc'<'
  721.    else say 'RxAsyncPriority set, Class=>'Regular'<, Level=>'NormalLvl'<'
  722.  
  723. /*=====================================================================*/
  724. /* cleanup                                                             */
  725. /*=====================================================================*/
  726.  
  727. call RxAsyncDropFuncs
  728. Say 'RxAsyncDropFuncs is complete'
  729. exit
  730.  
  731. /*=====================================================================*/
  732. /* just in case                                                        */
  733. /*=====================================================================*/
  734.  
  735. error:
  736.    call RxAsyncClose PortHandle
  737.    call RxAsyncDropFuncs
  738.    exit
  739.  
  740.