home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxasyn20.zip / RXTEST.CMD < prev    next >
OS/2 REXX Batch file  |  1994-12-26  |  10KB  |  342 lines

  1. /* RXASYNC.cmd - Test if RXASYNC.dll works   */
  2.  
  3. call on error
  4.  
  5. Regular    = 2
  6. Critical   = 3
  7. NormalLvl  = 0
  8. PortName   = 'COM4'
  9. PortHandle = ''
  10. OldBaud    = 0
  11. OldData    = 0
  12. OldParity  = ''
  13. OldStop    = 0
  14. NewBaud    = 0
  15. NewData    = 0
  16. NewParity  = ''
  17. NewStop    = 0
  18. InpStr     = ''
  19. Remaining  = 0
  20. WriteLim   = 0
  21. ReadLim    = 0
  22. Flags1     = ''
  23. Flags2     = ''
  24. Flags3     = ''
  25. ErrChar    = ''
  26. BrkChar    = ''
  27. XonChar    = ''
  28. XoffChar   = ''
  29. EnhParms   = ''
  30. True       = 1
  31. False      = 0
  32. crlf       = D2C(13)''D2C(10)
  33.  
  34. say '====================================================='
  35.  
  36. /* setup */
  37.  
  38. call RxFuncAdd 'RxAsyncLoadFuncs', 'RXASYNC', 'RxAsyncLoadFuncs'
  39. call RxAsyncLoadFuncs
  40. Say 'RxAsyncLoadFuncs is complete.'
  41.  
  42. /* set session priority */
  43.  
  44. rc = RxAsyncPriority( Critical, NormalLvl )
  45. if rc <> 0
  46.    then say 'RxAsyncPriority failed with rc=>'rc'<'
  47.    else say 'RxAsyncPriority set, Class=>'Critical'<, Level=>'NormalLvl'<'
  48.  
  49. /*=====================================================================*/
  50.  
  51. /* open device */
  52.  
  53. rc = RxAsyncOpen( PortName, 'PortHandle' )
  54. if rc <> 0
  55.    then say 'RxAsyncOpen failed with rc=>'rc'<'
  56.    else say 'RxAsyncOpen opened the device handle=>'PortHandle'<'
  57.  
  58. /* get dcb info */
  59.  
  60. rc = RxAsyncGetDcbInfo( PortHandle, 'WriteLim', 'ReadLim', 'Flags1', 'Flags2', 'Flags3', 'ErrChar', 'BrkChar', 'XonChar', 'XoffChar' )
  61. if rc <> 0
  62.    then say 'RxAsyncGetDcbInfo failed with rc=>'rc'<'
  63.    else say 'RxAsyncGetDcbInfo returned okay.'
  64.  
  65. say 'Write Timeout  was >'WriteLim'<'
  66. say 'Read  Timeout  was >'ReadLim'<'
  67. say 'F1 HandShake   was >'X2B(Flags1)'<'
  68. say 'F2 FlowReplace was >'X2B(Flags2)'<'
  69. say 'F3 Timeout     was >'X2B(Flags3)'<'
  70. say 'Error Replace  was >'ErrChar'<'
  71. say 'Break Replace  was >'BrkChar'<'
  72. say 'Xon character  was >'XonChar'<'
  73. say 'Xoff character was >'XoffChar'<'
  74.  
  75. rc = RxAsyncSetDcbInfo( PortHandle, 50,  50, '00001001', '10100000', '11010010', '00', '00', '11', '13' )
  76. /* rc = RxAsyncSetDcbInfo( PortHandle,  ,  , '01001001', '10100000', '11010010', '', '', '11', '13' ) */
  77. if rc <> 0
  78.    then say 'RxAsyncSetDcbInfo failed with rc=>'rc'<'
  79.    else say 'RxAsyncSetDcbInfo returned okay.'
  80.  
  81. rc = RxAsyncDcbInfo( PortHandle )
  82. if rc <> 0
  83.    then say 'RxAsyncDcbInfo failed with rc=>'rc'<'
  84.    else say 'RxAsyncDcbInfo returned okay.'
  85.  
  86. /* get enhanced parms */
  87.  
  88. rc = RxAsyncGetEnhParm( PortHandle, 'EnhParms' )
  89. if rc <> 0
  90.    then say 'RxAsyncGetEnhParm failed with rc=>'rc'<'
  91.    else say 'RxAsyncGetEnhParm returned okay.'
  92.  
  93. say 'Enhanced Parms was >'X2B(EnhParms)'<'
  94.  
  95. /* get original settings */
  96.  
  97. rc = RxAsyncGetLnCtrl( PortHandle, 'OldBaud', 'OldData', 'OldParity', 'OldStop' )
  98. if rc <> 0
  99.    then say 'RxAsyncGetLnCtrl failed with rc=>'rc'<'
  100.    else say 'RxAsyncGetLnCtrl saved the original settings'
  101.  
  102. say 'Baudrate was >'OldBaud'<'
  103. say 'Databits was >'OldData'<'
  104. say 'Parity   was >'OldParity'<'
  105. say 'Stopbits was >'OldStop'<'
  106.  
  107. /* set required settings */
  108.  
  109. rc = RxAsyncSetLnCtrl( PortHandle, 19200, 8, 'N', 1 )
  110. if rc <> 0
  111.    then say 'RxAsyncSetLnCtrl failed with rc=>'rc'<'
  112.    else say 'RxAsyncSetLnCtrl has set the new settings'
  113.  
  114. /* get new settings */
  115.  
  116. rc = RxAsyncGetLnCtrl( PortHandle, 'NewBaud', 'NewData', 'NewParity', 'NewStop' )
  117. if rc <> 0
  118.    then say 'RxAsyncGetLnCtrl failed with rc=>'rc'<'
  119.    else say 'RxAsyncGetLnCtrl queried the new settings'
  120.  
  121. say 'Baudrate was >'NewBaud'<'
  122. say 'Databits was >'NewData'<'
  123. say 'Parity   was >'NewParity'<'
  124. say 'Stopbits was >'NewStop'<'
  125.  
  126. /* write modem reset string */
  127.  
  128. rc = RxAsyncWrite( PortHandle, 0, 'ATZ'||D2C(13), 'Remaining' )
  129. if rc <> 0
  130.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  131.    else say 'RxAsyncWrite output ATZ<cr>'
  132.  
  133. /* read modem response */
  134.  
  135. InpStr = ""
  136. GetOk = True
  137. do while GetOk
  138.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  139.    GetOk = False
  140.    select
  141.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  142.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  143.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  144.      otherwise
  145.         say 'RxAsyncRead returned >'InpStr'<'
  146.         GetOk = True
  147.    end
  148. end
  149.  
  150. /* write modem reset string */
  151.  
  152. rc = RxAsyncWrite( PortHandle, 0, 'AT'D2C(13), 'Remaining' )
  153. if rc <> 0
  154.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  155.    else say 'RxAsyncWrite output AT<cr>'
  156.  
  157. /* read modem response */
  158.  
  159. InpStr = ""
  160. GetOk = True
  161. do while GetOk
  162.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  163.    GetOk = False
  164.    select
  165.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  166.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  167.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  168.      otherwise
  169.         say 'RxAsyncRead returned >'InpStr'<'
  170.         GetOk = True
  171.    end
  172. end
  173.  
  174. /* write modem reset string */
  175.  
  176. rc = RxAsyncWrite( PortHandle, 0, 'AT CAUSE AN ERROR'||D2C(13), 'Remaining' )
  177. if rc <> 0
  178.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  179.    else say 'RxAsyncWrite output AT CAUSE AN ERROR<cr>'
  180.  
  181. /* read modem response */
  182.  
  183. InpStr = ""
  184. GetOk = True
  185. do while GetOk
  186.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  187.    GetOk = False
  188.    select
  189.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  190.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  191.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  192.      otherwise
  193.         say 'RxAsyncRead returned >'InpStr'<'
  194.         GetOk = True
  195.    end
  196. end
  197.  
  198. /* write modem reset string */
  199.  
  200. rc = RxAsyncWrite( PortHandle, 0, 'ATS7?'||D2C(13), 'Remaining' )
  201. if rc <> 0
  202.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  203.    else say 'RxAsyncWrite output ATS7?<cr>'
  204.  
  205. /* read modem response */
  206.  
  207. InpStr = ""
  208. GetOk = True
  209. do while GetOk
  210.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  211.    GetOk = False
  212.    select
  213.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  214.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  215.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  216.      otherwise
  217.         say 'RxAsyncRead returned >'InpStr'<'
  218.         GetOk = True
  219.    end
  220. end
  221.  
  222. /* write modem attention string */
  223.  
  224. rc = RxAsyncWrite( PortHandle, 0, 'AT'D2C(13), 'Remaining' )
  225. if rc <> 0
  226.    then say 'Modem may not be turned on, >'Remaining'< chars unwritten'
  227.    else say 'RxAsyncWrite output AT<cr>'
  228.  
  229. /* wait a second or until there is data to be read */
  230.  
  231. say 'Wait for data 'time()
  232. rc = RxAsyncWait( PortHandle, 3000 )
  233. say 'Waited enough 'time()
  234. if rc = 0
  235.    then say 'RxAsyncWait detected input'
  236.    else if rc = -1
  237.            then say 'RxAsyncWait timed out'
  238.            else say 'RxAsyncWait returned rc=>'rc'<'
  239.  
  240. say 'Wait for carrier'
  241. rc = RxAsyncCarrier( PortHandle, 3000 )
  242. say 'Waited enough'
  243. if rc = 0
  244.    then say 'RxAsyncCarrier detected DCD'
  245.    else if rc = -1
  246.            then say 'RxAsyncCarrier timed out'
  247.            else say 'RxAsyncCarrier returned rc=>'rc'<'
  248.  
  249. say 'Test for carrier'
  250. rc = RxAsyncCarrier( PortHandle )
  251. if rc = 0
  252.    then say 'RxAsyncCarrier detected DCD'
  253.    else if rc = -2
  254.            then say 'RxAsyncCarrier did not detect DCD'
  255.            else say 'RxAsyncCarrier returned rc=>'rc'<'
  256.  
  257. /* read modem response */
  258.  
  259. InpStr = ""
  260. GetOk = True
  261. do while GetOk
  262.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  263.    GetOk = False
  264.    select
  265.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  266.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  267.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  268.      otherwise
  269.         say 'RxAsyncRead returned >'InpStr'<'
  270.         GetOk = True
  271.    end
  272. end
  273.  
  274. /* write modem reset string */
  275.  
  276. rc = RxAsyncWrite( PortHandle, 0, 'ATS1?'||D2C(13), 'Remaining' )
  277. if rc <> 0
  278.    then say 'Modem not turned on, >'Remaining'< chars unwritten'
  279.    else say 'RxAsyncWrite output ATS1?<cr>'
  280.  
  281. /* read modem response */
  282.  
  283. InpStr = ""
  284. GetOk = True
  285. do while GetOk
  286.    rc = RxAsyncRead( PortHandle, 0, 3000, 'InpStr' )
  287.    GetOk = False
  288.    select
  289.      when rc <> 0                 then say 'RxAsyncRead failed with rc=>'rc'<'
  290.      when InpStr == "OK"||crlf    then say 'RxAsyncRead returned >'InpStr'<'
  291.      when InpStr == "ERROR"||crlf then say 'RxAsyncRead returned >'InpStr'<'
  292.      otherwise
  293.         say 'RxAsyncRead returned >'InpStr'<'
  294.         GetOk = True
  295.    end
  296. end
  297.  
  298. /* send a break */
  299.  
  300. BreakTime = 500
  301. rc = RxAsyncBreak( PortHandle, BreakTime )
  302. if rc <> 0
  303.    then say 'RxAsyncBreak failed with rc=>'rc'<'
  304.    else say 'RxAsyncBreak sent break for 'BreakTime' milliseconds'
  305.  
  306. /* reset to original settings */
  307.  
  308. rc = RxAsyncSetLnCtrl( PortHandle, OldBaud, OldData, OldParity, OldStop )
  309. if rc <> 0
  310.    then say 'RxAsyncSetLnCtrl failed with rc=>'rc'<'
  311.    else say 'RxAsyncSetLnCtrl restored the original settings'
  312.  
  313. /* close the device */
  314.  
  315. rc = RxAsyncClose( PortHandle )
  316. if rc <> 0
  317.    then say 'RxAsyncClose failed with rc=>'rc'<'
  318.    else say 'RxAsyncClose closed the device'
  319.  
  320. /*=====================================================================*/
  321.  
  322. /* reset session priority */
  323.  
  324. rc = RxAsyncPriority( Regular, NormalLvl )
  325. if rc <> 0
  326.    then say 'RxAsyncPriority failed with rc=>'rc'<'
  327.    else say 'RxAsyncPriority set, Class=>'Regular'<, Level=>'NormalLvl'<'
  328.  
  329. /* cleanup */
  330.  
  331. call RxAsyncDropFuncs
  332. Say 'RxAsyncDropFuncs is complete.'
  333.  
  334. say '====================================================='
  335.  
  336. exit
  337.  
  338. error:
  339.    call RxAsyncClose PortHandle
  340.    exit
  341.  
  342.