home *** CD-ROM | disk | FTP | other *** search
/ CD Shareware Magazine 1996 December / CD_shareware_12-96.iso / WIN / Programa / WSC4VB10.ZIP / LOGLINE.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-08-26  |  5.0 KB  |  195 lines

  1. ' LOGIN.BAS
  2. Option Explicit
  3.  
  4. Dim FatalFlag As Integer
  5. Dim Code As Integer
  6.  
  7. Sub Aborting ()
  8.   Dim Code As Integer
  9.   LOGIN.Print "Fatal Error, Aborting..."
  10.   Code = SioDone(ThePort)
  11.   End
  12. End Sub
  13.  
  14. Sub DisplayChar (ByVal C As Integer)
  15.   Dim Row As Integer
  16.   Dim Col As Integer
  17.   C = &H7F And C
  18.   'process char
  19.   If C = 13 Then
  20.     'carriage control
  21.     CurrentCol = 0
  22.     'plus assumed line feed
  23.     If CurrentRow < 23 Then
  24.       CurrentRow = CurrentRow + 1
  25.       'print CR+LF
  26.       LOGIN.Print
  27.     Else
  28.       'scroll !
  29.       LOGIN.Cls
  30.       For Row = 0 To 22
  31.         'print row
  32.         ScreenBuffer(Row) = ScreenBuffer(Row + 1)
  33.         LOGIN.Print ScreenBuffer(Row)
  34.       Next Row
  35.       'clear bottom row
  36.       ScreenBuffer(23) = Space$(80)
  37.     End If
  38.   ElseIf C = 10 Then
  39.     'throw away line feeds
  40.   Else
  41.     'not CR or LF
  42.     CurrentCol = CurrentCol + 1
  43.     If CurrentCol > 79 Then
  44.       'throw away !
  45.       Exit Sub
  46.     Else
  47.       'save in screen buffer & display
  48.       Mid$(ScreenBuffer(CurrentRow), CurrentCol, 1) = Chr$(C)
  49.       LOGIN.Print Chr$(C);
  50.     End If
  51.   End If
  52. End Sub
  53.  
  54. Sub DisplayString (Text As String)
  55.   Dim i As Integer
  56.   Dim Length As Integer
  57.   Length = Len(Text)
  58.   For i = 1 To Length
  59.     Call DisplayChar(Asc(Mid$(Text, i, 1)))
  60.   Next i
  61.   Call DisplayChar(13)
  62. End Sub
  63.  
  64. Sub GetIncoming ()
  65.   Dim i As Integer
  66.   Dim TheChar As Integer
  67.   Dim Code As Integer
  68.   'is modem I/O (MIO) running ?
  69.   If MIOstate Then
  70.     'MIO is running
  71.     TheChar = mioDriver(ThePort)
  72.     If TheChar = MIO_IDLE Then
  73.       'time to go to next MIO state (since driver is idle)
  74.       Select Case MIOstate
  75.         '*** HANDSHAKE states ***
  76.         Case Handshake_1
  77.           'send "AT" to modem
  78.           Code = mioSendTo(ThePort, 100&, "!AT!")
  79.           MIOstate = Handshake_2
  80.         Case Handshake_2
  81.           'expect "OK" back
  82.           Code = mioWaitFor(ThePort, 3000&, 1, "OK")
  83.           MIOstate = Handshake_3
  84.         Case Handshake_3
  85.           'did we get expected result ("OK")
  86.           If mioResult(ThePort) Then
  87.             DisplayString (">>>OK was received")
  88.           Else
  89.             DisplayString (">>>OK was NOT received!")
  90.           End If
  91.           'all done
  92.           MIOstate = 0
  93.           LOGIN.menuStart.Enabled = True
  94.           LOGIN.menuBREAK.Enabled = False
  95.         '*** DIAL states ***
  96.         Case Dial_1
  97.           'dial modem [edit to call local BBS]
  98.           Code = mioSendTo(ThePort, 100&, "!ATDT1,205,880,9748!")
  99.           MIOstate = Dial_2
  100.         Case Dial_2
  101.           'expect "CONNECT" back (wait up to 60 seconds)
  102.           If mioWaitFor(ThePort, 60000, 1, "CONNECT") Then
  103.             MIOstate = Dial_3
  104.           Else
  105.             'error!
  106.             DisplayString (">>>mioWaitFor fails!")
  107.           End If
  108.         Case Dial_3
  109.           'did we get expected result ("CONNECT")
  110.           If mioResult(ThePort) Then
  111.             DisplayString (">>>CONNECT was received")
  112.           Else
  113.             DisplayString (">>>CONNECT was NOT received!")
  114.           End If
  115.           'all done
  116.           MIOstate = 0
  117.           LOGIN.menuBREAK.Enabled = False
  118.           LOGIN.menuStart.Enabled = True
  119.       End Select
  120.     Else
  121.       'MIO is not IDLE
  122.       If TheChar <> MIO_RUNNING Then
  123.         Call DisplayChar(TheChar)
  124.       End If
  125.     End If
  126.   Else
  127.   'MIO not in use
  128.     For i = 1 To 1000
  129.       TheChar = SioGetc(ThePort)
  130.       If TheChar > 0 Then
  131.         Call DisplayChar(TheChar)
  132.         '''Call DisplayString("{" + Hex$(TheChar) + "}")
  133.       Else
  134.         Exit For
  135.       End If
  136.     Next i
  137.   End If
  138. End Sub
  139.  
  140. Sub GoOffLine ()
  141.   Dim Code As Integer
  142.   OnLineFlag = 0
  143.   'shut down port
  144.   Code = SioDone(ThePort)
  145. End Sub
  146.  
  147. Sub GoOnLine ()
  148.   Dim i As Integer
  149.   Dim RxQueSize As Integer
  150.   Dim TxQueSize As Integer
  151.   If OnLineFlag Then
  152.     Exit Sub
  153.   End If
  154.   'reset the port (1024 byte RX buffer & 128 byte TX buffer)
  155.   RxQueSize = 1024
  156.   TxQueSize = 128
  157.   Code = SioReset(ThePort, RxQueSize, TxQueSize)
  158.   If Code < 0 Then
  159.     Call SayError(LOGIN, Code)
  160.     Exit Sub
  161.   End If
  162.   ''' set baud rate
  163.   Code = SioBaud(ThePort, TheBaudCode)
  164.   'call Aborting() if detect error after resetting port
  165.   Call DisplayString("COM" + LTrim$(Str$(1 + ThePort)) + " reset")
  166.   'set DTR & RTS
  167.   Code = SioDTR(ThePort, Asc("S"))
  168.   Code = SioRTS(ThePort, Asc("S"))
  169.   'turn on hardware flow control
  170.   Code = SioFlow(ThePort, ASC("H"))
  171.   Call DisplayString("RTS/CTS flow control on")
  172.   ' set parms
  173.   Code = SioParms(ThePort, TheParity, TheStopBits, TheDataBits)
  174.   ' we're online !
  175.   OnLineFlag = 1
  176. End Sub
  177.  
  178. Sub ShowConfig ()
  179.   Dim A As String
  180.   Dim B As String
  181.   Dim C As String
  182.   Dim D As String
  183.   Dim E As String
  184.   If OnLineFlag Then
  185.     A = " (Online)"
  186.   Else
  187.     A = " (Offline)"
  188.   End If
  189.   B = "COM" + LTrim$(Str$(ThePort + 1))
  190.   C = " @ " + BaudText(TheBaudCode) + " "
  191.   D = Str$(TheDataBits) + ParityText(TheParity)
  192.   E = LTrim$(Str$(1 + TheStopBits))
  193.   LOGIN.Caption = "LOGIN: " + B + C + D + E + A
  194. End Sub
  195.