home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / pclvbw11 / logline.bas < prev    next >
Encoding:
BASIC Source File  |  1996-11-20  |  6.0 KB  |  241 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. Function GetDosMemory (SizeCode As Integer)
  65.   Dim Size As Long
  66.   Dim Value As Long
  67.   If SizeCode > Size32K Then
  68.     LOGIN.Print "SizeCode out of range"
  69.     GetDosMemory = 0
  70.     Exit Function
  71.   End If
  72.   Size = 2 ^ (SizeCode + 4)
  73.   Value = GlobalDosAlloc(Size)
  74.   If Value Then
  75.     'return selector
  76.     GetDosMemory = (&HFFFF& And Value)
  77.   Else
  78.     LOGIN.Print "Cannot allocate Dos memory ("; Size; ")"
  79.     GetDosMemory = 0
  80.   End If
  81.  
  82. End Function
  83.  
  84. Sub GetIncoming ()
  85.   Dim I As Integer
  86.   Dim TheChar As Integer
  87.   Dim Code As Integer
  88.   'is modem I/O (MIO) running ?
  89.   If MIOstate Then
  90.     'MIO is running
  91.     TheChar = mioDriver(ThePort)
  92.     If TheChar = MIO_IDLE Then
  93.       'time to go to next MIO state (since driver is idle)
  94.       Select Case MIOstate
  95.         '*** HANDSHAKE states ***
  96.         Case Handshake_1
  97.           'send "AT" to modem
  98.           Code = mioSendTo(ThePort, 100&, "!AT!")
  99.           MIOstate = Handshake_2
  100.         Case Handshake_2
  101.           'expect "OK" back
  102.           Code = mioWaitFor(ThePort, 3000&, 1, "OK")
  103.           MIOstate = Handshake_3
  104.         Case Handshake_3
  105.           'did we get expected result ("OK")
  106.           If mioResult(ThePort) Then
  107.             DisplayString (">>>OK was received")
  108.           Else
  109.             DisplayString (">>>OK was NOT received!")
  110.           End If
  111.           'all done
  112.           MIOstate = 0
  113.           LOGIN.menuStart.Enabled = True
  114.           LOGIN.menuBREAK.Enabled = False
  115.         '*** DIAL states ***
  116.         Case Dial_1
  117.           'dial modem
  118.           Code = mioSendTo(ThePort, 100&, "!ATDT880,9748!")
  119.           MIOstate = Dial_2
  120.         Case Dial_2
  121.           'expect "CONNECT" back (wait up to 60 seconds)
  122.           If mioWaitFor(ThePort, 60000, 1, "CONNECT") Then
  123.             MIOstate = Dial_3
  124.           Else
  125.             'error!
  126.             DisplayString (">>>mioWaitFor fails!")
  127.           End If
  128.         Case Dial_3
  129.           'did we get expected result ("CONNECT")
  130.           If mioResult(ThePort) Then
  131.             DisplayString (">>>CONNECT was received")
  132.           Else
  133.             DisplayString (">>>CONNECT was NOT received!")
  134.           End If
  135.           'all done
  136.           MIOstate = 0
  137.           LOGIN.menuBREAK.Enabled = False
  138.           LOGIN.menuStart.Enabled = True
  139.       End Select
  140.     Else
  141.       'MIO is not IDLE
  142.       If TheChar <> MIO_RUNNING Then
  143.         Call DisplayChar(TheChar)
  144.       End If
  145.     End If
  146.   Else
  147.   'MIO not in use
  148.     For I = 1 To 1000
  149.       TheChar = SioGetc(ThePort, 0)
  150.       If TheChar > 0 Then
  151.         Call DisplayChar(TheChar)
  152.         '''Call DisplayString("{" + Hex$(TheChar) + "}")
  153.       Else
  154.         Exit For
  155.       End If
  156.     Next I
  157.   End If
  158. End Sub
  159.  
  160. Sub GoOffLine ()
  161.   Dim Code As Integer
  162.   OnLineFlag = 0
  163.   'shut down port
  164.   Code = SioDone(ThePort)
  165.   'free DOS memory
  166.   If TxSelector <> 0 Then
  167.     '''Code = GlobalPageUnlock(TxSelector)
  168.     Code = GlobalDosFree(TxSelector)
  169.     TxSelector = 0
  170.   End If
  171.   If RxSelector <> 0 Then
  172.     '''Code = GlobalPageUnlock(RxSelector)
  173.     Code = GlobalDosFree(RxSelector)
  174.     RxSelector = 0
  175.   End If
  176.  
  177. End Sub
  178.  
  179. Sub GoOnLine ()
  180.   Dim I As Integer
  181.   If OnLineFlag Then
  182.     Exit Sub
  183.   End If
  184.   'allocating RX buffer
  185.   RxSelector = GetDosMemory(Size1024)
  186.   Code = SioRxBuf(ThePort, RxSelector, Size1024)
  187.   If Code < 0 Then
  188.     LOGIN.Print "Cannot allocate RX buffer"
  189.     Exit Sub
  190.   End If
  191.   'allocate TX buffer
  192.   TxSelector = GetDosMemory(Size128)
  193.   Code = SioTxBuf(ThePort, TxSelector, Size128)
  194.   If Code < 0 Then
  195.     LOGIN.Print "Cannot allocate TX buffer"
  196.     Exit Sub
  197.   End If
  198.   'reset the port
  199.   Code = SioReset(ThePort, TheBaudCode)
  200.   If Code < 0 Then
  201.     Call SioError(LOGIN, Code)
  202.     Exit Sub
  203.   End If
  204.   'call Aborting() if detect error after resetting port
  205.   Call DisplayString("COM" + LTrim$(Str$(1 + ThePort)) + " reset")
  206.   'set DTR & RTS
  207.   Code = SioDTR(ThePort, Asc("S"))
  208.   Code = SioRTS(ThePort, Asc("S"))
  209.   'turn on hardware flow control
  210.   Code = SioFlow(ThePort, 18)
  211.   Call DisplayString("RTS/CTS flow control on")
  212.   'turn on UART FIFO if 16550
  213.   Code = SioFIFO(ThePort, LEVEL_8)
  214.   If Code > 0 Then
  215.     Call DisplayString("16550 Detected")
  216.   End If
  217.   ' set parms
  218.   Code = SioParms(ThePort, TheParity, TheStopBits, TheDataBits)
  219.   ' we're online !
  220.   OnLineFlag = 1
  221. End Sub
  222.  
  223. Sub ShowConfig ()
  224.   Dim A As String
  225.   Dim B As String
  226.   Dim C As String
  227.   Dim D As String
  228.   Dim E As String
  229.   If OnLineFlag Then
  230.     A = " (Online)"
  231.   Else
  232.     A = " (Offline)"
  233.   End If
  234.   B = "COM" + LTrim$(Str$(ThePort + 1))
  235.   C = " @ " + BaudText(TheBaudCode) + " "
  236.   D = Str$(5 + TheDataBits) + ParityText(TheParity)
  237.   E = LTrim$(Str$(1 + TheStopBits))
  238.   LOGIN.Caption = "LOGIN: " + B + C + D + E + A
  239. End Sub
  240.  
  241.