home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MODEM / CHKMODEM.ZIP / CHKMODEM.BAS next >
Encoding:
BASIC Source File  |  1990-06-21  |  14.3 KB  |  485 lines

  1. '******************************************************************************
  2. '
  3. '       File:   CHKMODEM.BAS
  4. '
  5. '       Date:   06/21/90
  6. '
  7. '         By:   Gary G. Hendershot
  8. '               Soft Sale Limited BBS
  9. '               (703) 569-6876
  10. '
  11. '    Purpose:   Utility program to find HAYES command compatible
  12. '               modems on COM1 thru COM4.  Report maximum possible
  13. '               baud rate for all modems found.  Test a selected
  14. '               modem for DTR and CD line settings.
  15. '
  16. '               This utility is part of an installation program
  17. '               under development which when finished will
  18. '               automate the installation of a commercial
  19. '               vertical market micro to mainframe dialup
  20. '               communications program.
  21. '
  22. '               The intent is to make the installation of the
  23. '               program as idiot proof as possible. In this program
  24. '               segment no configuration file is created.  Responses
  25. '               are sent to the screen only.
  26. '
  27. '       Note:   Both the EXECUTABLE and SOURCE files are included.
  28. '               The program conpiles under MS-BASIC Ver. 7.0 and
  29. '               MS-QuickBASIC 4.5.
  30. '
  31. '               The program makes CALLs to a Serial I/O Library called
  32. '               QBSERIAL Ver. 1.5.  This Library was written by
  33. '               Jeff Sumberg and was obtained from the SailBoard BBS
  34. '               at (201) 831-8152
  35. '
  36. '               I do not intend to provide any support or upgrades to
  37. '               this program.  It is offered AS IS to anyone interested
  38. '               in communications programming as an example of what
  39. '               compiled BASIC can do with a little help.
  40. '
  41. '               I would of course appreciate any comments or mods others
  42. '               might offer that would enhance the capabilities of this
  43. '               program to deliver the results described above.  Please
  44. '               leave any comments or mods addressed to the SYSOP at
  45. '               (703) 569-6876 or in writting to
  46. '                       Gary G. Hendershot
  47. '                       7218 Reservoir Road
  48. '                       Springfield, VA  22150
  49. '
  50. '******************************************************************************
  51. '
  52. '       These DECLAREs are required by QBSERIAL.LIB
  53. '
  54. DECLARE SUB OpenComm CDECL ALIAS "_open_comm" (BYVAL Port%, BYVAL Wlen%, BYVAL Parity%, BYVAL Baud&, BYVAL HS%)
  55. DECLARE SUB CloseComm CDECL ALIAS "_close_comm" ()
  56. DECLARE FUNCTION WriteChar% CDECL (BYVAL Ascii%)
  57. DECLARE FUNCTION ReadChar% CDECL ()
  58. DECLARE SUB Transmit CDECL ALIAS "_transmit_string" (addr$)
  59. DECLARE FUNCTION DataWaiting% CDECL ALIAS "_data_waiting" ()
  60. DECLARE SUB ClearInputBuffer CDECL ALIAS "_clear_input_buffer" ()
  61. DECLARE SUB CarrierDetect CDECL ALIAS "_carrier_detect_flag" (BYVAL OnOff%)
  62. DECLARE SUB CDtrap CDECL ALIAS "_trap_mode" (BYVAL OnOff%)
  63. DECLARE FUNCTION CarrierLost% CDECL ALIAS "_carrier_state" ()
  64. DECLARE SUB DTRcontrol CDECL ALIAS "_dtr" (BYVAL OnOff%)
  65. '
  66. '$STATIC
  67. '
  68. DIM Report%(4,4)
  69. DIM FoundPort%(4)
  70. DIM Init%(4,60)
  71. DIM ModemPort%(4)
  72. DIM Respond$(30)
  73. '
  74. DEFINT A-Z
  75. '
  76. CONST   True = -1
  77. CONST   False = 0
  78. '
  79. Verbal:
  80.         Respond$(0)  = "OK"
  81.         Respond$(1)  = "CONNECT"
  82.         Respond$(2)  = "RING"
  83.         Respond$(3)  = "NO CARRIER"
  84.         Respond$(4)  = "ERROR"
  85.         Respond$(5)  = "CONNECT 1200"
  86.         Respond$(6)  = "NO DIALTONE"
  87.         Respond$(7)  = "BUSY"
  88.         Respond$(8)  = "NO ANSWER"
  89.         Respond$(9)  = "RESERVED"
  90.         Respond$(10) = "CONNECT 2400"
  91. '
  92. Numeric:
  93.         Respond$(20) = "0"
  94.         Respond$(21) = "1"
  95.         Respond$(22) = "2"
  96.         Respond$(23) = "3"
  97.         Respond$(24) = "4"
  98.         Respond$(25) = "5"
  99.         Respond$(26) = "6"
  100.         Respond$(27) = "7"
  101.         Respond$(28) = "8"
  102.         Respond$(29) = "9"
  103.         Respond$(30) = "10"
  104. '
  105. Main:
  106.         CLS
  107. '
  108.         Length = 8
  109.         Parity = 0
  110.         HS = 0
  111.         Send$ = "AT" + CHR$(13)
  112.         NextPort% = 0
  113.         PrevPort% = 0
  114.         ModemAvail% = 0
  115.  '
  116.         GOSUB TestPort1
  117.         GOSUB TestPort2
  118.         GOSUB TestPort3
  119.         GOSUB TestPort4
  120.         GOSUB PortReport
  121.         GOSUB HowManyModems
  122.         GOSUB ChooseActivePort
  123.         GOSUB CheckCDLine
  124.         GOSUB CheckDTRLine
  125.         DTRControl 0
  126.         CloseComm
  127. '
  128.         END
  129. '
  130. TestPort1:
  131.         Port = 1
  132.         Rate& = 0
  133.         GOSUB TickleIt
  134.         RETURN
  135. '
  136. TestPort2:
  137.         Port = 2
  138.         Rate& = 0
  139.         GOSUB TickleIt
  140.         RETURN
  141. '
  142. TestPort3:
  143.         Port = 3
  144.         Rate& = 0
  145.         GOSUB TickleIt
  146.         RETURN
  147. '
  148. TestPort4:
  149.         Port = 4
  150.         Rate& = 0
  151.         GOSUB TickleIt
  152.         RETURN
  153. '
  154. PortReport:
  155.         CLS
  156.         LOCATE 4, 15, 0
  157.         PRINT "An Ok marks a useable PORT/MODEM at a given BAUD"
  158.         LOCATE 8, 15
  159.         PRINT "300 BAUD"
  160.         LOCATE 8, 30
  161.         PRINT "1200 BAUD"
  162.         LOCATE 8, 45
  163.         PRINT "2400 BAUD"
  164.         LOCATE 8, 60
  165.         PRINT "9600 BAUD"
  166.         LOCATE 11, 5
  167.         PRINT "COM1:"
  168.         LOCATE 13, 5
  169.         PRINT "COM2:"
  170.         LOCATE 15, 5
  171.         PRINT "COM3:"
  172.         LOCATE 17, 5
  173.         PRINT "COM4:"
  174.         FOR X% = 1 TO 4
  175.                 FOR Y% = 1 TO 4
  176.                         LOCATE (X% * 2) + 9, (Y% * 15) + 3
  177.                         IF Y% = 1 THEN
  178.                                 Speed% = 300
  179.                         ELSEIF Y% = 2 THEN
  180.                                 Speed% = 1200
  181.                         ELSEIF Y% = 3 THEN
  182.                                 Speed% = 2400
  183.                         ELSEIF Y% = 4 THEN
  184.                                 Speed% =9600
  185.                         END IF
  186.                         IF Report%(X%,Y%) THEN
  187.                                 PRINT "Ok";
  188.                                 FoundPort%(X%) = Speed%
  189.                         END IF
  190.                 NEXT Y%
  191.         NEXT X%
  192.         LOCATE 20, 30
  193.         PRINT "Press Any Key to Continue"
  194.         A$=""
  195.         WHILE A$=""
  196.                 A$=INKEY$
  197.         WEND
  198.         RETURN
  199. '
  200. HowManyModems:
  201.         ModemAvail%=0
  202.         FOR X% = 1 TO 4
  203.                 IF FoundPort%(X%) THEN
  204.                         ModemAvail% = ModemAvail% + 1
  205.                         ModemPort%(ModemAvail%) = X%
  206.                 END IF
  207.         NEXT X%
  208.         RETURN
  209. '
  210. ChooseActivePort:
  211.         CLS
  212.         PRINT
  213.         PRINT
  214.         PRINT
  215.         IF ModemAvail% = 0 THEN
  216.                 PRINT
  217.                 PRINT "No MODEM found that responds to HAYES AT commands"
  218.                 PRINT
  219.                 PRINT
  220.                 PRINT "Press any key to exit program"
  221.                 PRINT
  222.                 A$ = ""
  223.                 WHILE A$ = ""
  224.                         A$ = INKEY$
  225.                 WEND
  226.                 RETURN
  227.         ELSEIF ModemAvail% > 0 THEN
  228.                 FOR X% = 1 TO ModemAvail%
  229.                         PRINT
  230.                         PRINT "There is a MODEM on COM";
  231.                         PRINT STR$(ModemPort%(X%));":";
  232.                         PRINT " responding properly at ";
  233.                         PRINT STR$(FoundPort%(ModemPort%(X%)));" Baud"
  234.                         PRINT
  235.                 NEXT X%
  236.                 GOSUB ChooseModem
  237.                 IF ChosenModem% = 0 THEN SYSTEM
  238.         END IF
  239.         OpenComm Port, Length, Parity, Rate&, HS
  240.         CarrierDetect 0
  241.         SOUND 32767,15:SOUND 32767,1
  242.         DTRcontrol 1
  243.         SOUND 32767,15:SOUND 32767,1
  244.         RETURN
  245. '
  246. CheckCDLine:
  247.         CLS
  248.         PRINT
  249.         PRINT
  250.         PRINT "Testing Carrier Detect"
  251.         PRINT
  252.         CarrierDetect 0
  253.         SOUND 32767,15:SOUND 32767,1
  254.         DTRControl 1
  255.  
  256.         SOUND 32767,15:SOUND 32767,1
  257.         Send$ = "ATQ0E0V1X1" + CHR$(13)
  258.         SOUND 32767,15:SOUND 32767,1
  259.         Transmit Send$
  260.         SOUND 32767,15:SOUND 32767,1
  261.         GOSUB GetResponse
  262.  
  263.         IF Response% = 5 THEN
  264.                 CD% = 0
  265.                 RETURN
  266.         END IF
  267.  
  268.         SOUND 32767,15:SOUND 32767,1
  269.         Send$ = "ATA" + CHR$(13)
  270.         Transmit Send$
  271.  
  272.         Response% = 0
  273.         CounterVal! = TIMER + 60
  274.         DO WHILE Response% <> 4 AND TIMER < CounterVal!
  275.                GOSUB GetResponse
  276.         LOOP
  277.  
  278.         IF Response% <> 4 THEN
  279.                 CD% = 0
  280.                 PRINT
  281.                 PRINT "Carrier Detect Test FAILED !!!!!"
  282.         ELSE
  283.                 CD% = 1
  284.                 PRINT
  285.                 PRINT "Carrier Detect Test Successful !"
  286.         END IF
  287.         CarrierDetect  1
  288.         IF CarrierLost THEN
  289.                 PRINT
  290.                 PRINT "CARRIERLOST Routine shows NO CARRIER"
  291.         ELSE
  292.                 PRINT
  293.                 PRINT "CARRIERLOST Routine shows CARRIER PRESENT"
  294.         END IF
  295.         CarrierDetect  0
  296.  
  297.         SOUND 32767,15:SOUND 32767,1
  298.         Send$ = "ATH0" + CHR$(13)
  299.         Transmit Send$
  300.         SOUND 32767,15:SOUND 32767,1
  301.         GOSUB GetResponse
  302.  
  303.         SOUND 32767,15:SOUND 32767,1
  304.         Send$ = "AT &F" + CHR$(13)
  305.         Transmit Send$
  306.         SOUND 32767,15:SOUND 32767,1
  307.         GOSUB GetResponse
  308.         SOUND 32767,15:SOUND 32767,1
  309.         DTRControl 0
  310.         TriggerVal! = TIMER + 10
  311.         WHILE TIMER < TriggerVal!
  312.         WEND
  313.         RETURN
  314. '
  315. CheckDTRLine:
  316.         PRINT
  317.         PRINT
  318.         PRINT
  319.         PRINT
  320.         PRINT "Testing Data Terminal Ready"
  321.         PRINT
  322.  
  323.         DTRControl 1
  324.         SOUND 32767,15:SOUND 32767,1
  325.         Send$ = "ATA" + CHR$(13)
  326.         Transmit Send$
  327.         SOUND 32767,15:SOUND 32767,1
  328.         DTRControl 0
  329.         SOUND 32767,15:SOUND 32767,1
  330.         GOSUB GetResponse
  331.         IF Response% = 1 THEN DTR = True ELSE DTR = False
  332.  
  333.         DTRControl 1
  334.         SOUND 32767,15:SOUND 32767,1
  335.         Send$ = "ATH0" + CHR$(13)
  336.         Transmit Send$
  337.         SOUND 32767,15:SOUND 32767,1
  338.         GOSUB GetResponse
  339.         DTRControl 0
  340.  
  341.         IF DTR THEN
  342.                 PRINT
  343.                 PRINT "Modem follows TRUE STATE of DTR"
  344.                 PRINT
  345.         ELSE
  346.                 PRINT
  347.                 PRINT "Modem may not follow TRUE STATE of DTR"
  348.                 PRINT
  349.         END IF
  350.         RETURN
  351. '
  352. TickleIt:
  353.         GOSUB CycleRate
  354.         ReportX% = Port
  355.         Notice$ = "Initialize MODEM on COM" + STR$(Port) + ": at "
  356.         Notice$ = Notice$ + STR$(Rate&) + " Baud"
  357.         PRINT Notice$
  358.         OpenComm Port, Length, Parity, Rate&, HS
  359.         CarrierDetect 0
  360.         SOUND 32767,15:SOUND 32767,1
  361.         DTRcontrol 1
  362.         SOUND 32767,15:SOUND 32767,1
  363.         C$=""
  364.         Response% = 0
  365.         Transmit Send$
  366.         GOSUB GetResponse
  367.         DTRcontrol 0
  368.         SOUND 32767,15:SOUND 32767,1
  369.         CloseComm
  370.         PRINT
  371.         IF Response% > 0 AND Response% <> 5 THEN
  372.                 PRINT "Attempt to ";Notice$;" SUCCEEDED !!";CHR$(13)
  373.                 Report%(ReportX%,ReportY%) = 1
  374.         ELSE
  375.                 PRINT "Attempt to ";Notice$;" FAILED !!";CHR$(13)
  376.                 Report%(ReportX%,ReportY%) = 0
  377.         END IF
  378.         PRINT
  379.         PRINT
  380.         IF Rate& < 9600 THEN GOTO TickleIt
  381.         RETURN
  382. '
  383. CycleRate:
  384.         IF Rate& = 0 THEN
  385.                 Rate& = 300
  386.                 ReportY% = 1
  387.         ELSEIF  Rate& = 300 THEN
  388.                 Rate& = 1200
  389.                 ReportY% = 2
  390.         ELSEIF  Rate& = 1200 THEN
  391.                 Rate& = 2400
  392.                 ReportY% = 3
  393.         ELSEIF  Rate& = 2400 THEN
  394.                 Rate& = 9600
  395.                 ReportY% = 4
  396.         ELSEIF  Rate& = 9600 THEN
  397.                 ReportY% = 0
  398.         END IF
  399.         RETURN
  400. '
  401. ChooseModem:
  402.         PRINT
  403.         PRINT
  404.         PRINT "Choose the port number you wish to test from above list!"
  405.         A$ = ""
  406.         WHILE A$ = ""
  407.                 A$ = INKEY$
  408.         WEND
  409.         ChosenModem% = VAL(A$)
  410.         Rate& = FoundPort%(ChosenModem%)
  411.         Port = ChosenModem%
  412.         RETURN
  413. '
  414. GetResponse:
  415.         C$ = ""
  416.         Response% = 0
  417.         Accept% = 0
  418.         TriggerVal! = TIMER + 1
  419.         DO
  420.                 DO WHILE DataWaiting
  421.                         A$=CHR$(ReadChar)
  422.                         A% = ASC(A$)
  423.                         GOSUB GoodChar
  424.                         IF Accept% = True THEN
  425.                                 C$ = C$ + A$
  426.                         ELSEIF Accept% = 99 THEN
  427.                                 C$ = C$ + CHR$(32)
  428.                         END IF
  429.                 LOOP
  430.                 GOSUB ResponseCatagory
  431.         LOOP UNTIL TIMER > TriggerVal! OR Response% > 0 OR Accept% = 99
  432.         IF Response% THEN
  433.                 PRINT
  434.                 PRINT "Modem Response:  ";C$;
  435.                 PRINT
  436.         ELSEIF Accept% = 99 THEN
  437.                 GOTO GetResponse
  438.         END IF
  439.         RETURN
  440. '
  441. ResponseCatagory:
  442.         IF INSTR(C$,Respond$(0)) OR INSTR(C$,Respond$(20)) THEN
  443.                 Response% = 1
  444.         ELSEIF INSTR(C$,Respond$(1)) OR INSTR(C$,Respond$(21)) THEN
  445.                 Response% = 2
  446.         ELSEIF INSTR(C$,Respond$(2)) OR INSTR(C$,Respond$(22)) THEN
  447.                 Response% = 3
  448.         ELSEIF INSTR(C$,Respond$(3)) OR INSTR(C$,Respond$(23)) THEN
  449.                 Response% = 4
  450.         ELSEIF INSTR(C$,Respond$(4)) OR INSTR(C$,Respond$(24)) THEN
  451.                 Response% = 5
  452.         ELSEIF INSTR(C$,Respond$(5)) OR INSTR(C$,Respond$(25)) THEN
  453.                 Response% = 6
  454.         ELSEIF INSTR(C$,Respond$(6)) OR INSTR(C$,Respond$(26)) THEN
  455.                 Response% = 7
  456.         ELSEIF INSTR(C$,Respond$(7)) OR INSTR(C$,Respond$(27)) THEN
  457.                 Response% = 8
  458.         ELSEIF INSTR(C$,Respond$(8)) OR INSTR(C$,Respond$(28)) THEN
  459.                 Response% = 9
  460.         ELSEIF INSTR(C$,Respond$(8)) OR INSTR(C$,Respond$(29)) THEN
  461.                 Response% = 10
  462.         ELSEIF INSTR(C$,Respond$(10)) OR INSTR(C$,Respond$(30)) THEN
  463.                 Response% = 11
  464.         ELSEIF VAL(C$) > 0 THEN
  465.                 Response% = CINT(VAL(LEFT$(C$,INSTR(C$,CHR$(13)))))
  466.         ELSE
  467.                 Response% = 0
  468.         END IF
  469.         RETURN
  470. '
  471. GoodChar:
  472.         IF A% = 13 THEN
  473.                 Accept% = 99
  474.         ELSEIF A% = 32 THEN
  475.                 Accept% = True
  476.         ELSEIF (A% > 47) AND (A% < 58) THEN
  477.                 Accept% = True
  478.         ELSEIF (A% > 64) AND (A% < 91) THEN
  479.                 Accept% = True
  480.         ELSE
  481.                 Accept% = False
  482.         END IF
  483.         RETURN
  484. '
  485.