home *** CD-ROM | disk | FTP | other *** search
/ Chip 1999 August / Chip_1999-08_cd.bin / sharewar / wscmclib / TERMLINE.BAS < prev    next >
BASIC Source File  |  1999-06-01  |  7KB  |  268 lines

  1. ' TERM.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.   TERM.Print "Fatal Error, Aborting..."
  10.   Code = SioDone(ThePort)
  11.   End
  12. End Sub
  13.  
  14. Sub GetIncoming ()
  15.   Dim i As Integer
  16.   Dim TheChar As Integer
  17.   Dim Code As Integer
  18.   Dim S As String
  19.   'is modem I/O (MIO) running ?
  20.   If mioState <> 0 Then
  21.     'run Modem I/O driver
  22.     Call RunMIO
  23.     Exit Sub
  24.   End If
  25.   'is ASCII driver running ?
  26.   If asState <> 0 Then
  27.     'run ascDriver
  28.     Call RunAS
  29.     Exit Sub
  30.   End If
  31.   'is XMODEM / YMODEM driver running ?
  32.   If xyState <> 0 Then
  33.     'run xyDriver
  34.     Call RunXY
  35.     Exit Sub
  36.   End If
  37.   'get all incoming serial
  38.   For i = 1 To 1000
  39.     TheChar = SioGetc(ThePort)
  40.     If TheChar > 0 Then
  41.       Call DisplayChar(TERM, TheChar)
  42.     Else
  43.       Exit For
  44.     End If
  45.   Next i
  46. End Sub
  47.  
  48. Sub GoOffLine ()
  49.   Dim Code As Integer
  50.   If OnLineFlag = 1 Then
  51.     OnLineFlag = 0
  52.     'release xyDriver
  53.     Code = xyAbort(ThePort)
  54.     Code = xyRelease()
  55.     'shut down port
  56.     Code = SioDone(ThePort)
  57.   End If
  58. End Sub
  59.  
  60. Sub GoOnLine ()
  61.   Dim i As Integer
  62.   Dim RxQueSize As Integer
  63.   Dim TxQueSize As Integer
  64.   If OnLineFlag Then
  65.     Exit Sub
  66.   End If
  67.   'reset the port
  68.   RxQueSize = RX_QUE_SIZE
  69.   TxQueSize = TX_QUE_SIZE
  70.   Code = SioReset(ThePort, RxQueSize, TxQueSize)
  71.   If Code < 0 Then
  72.     Call SayError(TERM, Code)
  73.     Exit Sub
  74.   End If
  75.   ''' set baud rate
  76.   Code = SioBaud(ThePort, TheBaudCode)
  77.   'call Aborting() if detect error after resetting port
  78.   Call DisplayLine(TERM, "COM" + LTrim$(Str$(1 + ThePort)) + " reset")
  79.   'set DTR & RTS
  80.   Code = SioDTR(ThePort, Asc("S"))
  81.   Code = SioRTS(ThePort, Asc("S"))
  82.   'turn on hardware flow control
  83.   Code = SioFlow(ThePort, Asc("H"))
  84.   Call DisplayLine(TERM, "Setting hardware flow control.")
  85.   If SioCTS(ThePort) = 0 Then
  86.     Call DisplayLine(TERM, "WARNING: Flow control not enabled on modem [CTS=0]")
  87.   End If
  88.   ' set parms
  89.   Code = SioParms(ThePort, TheParity, TheStopBits, TheDataBits)
  90.   'acquire xyDriver
  91.   Code = xyAcquire(ThePort, ThePort)
  92.   'set xyDriver debug level
  93.   Code = xyDebug(DebugLevel)
  94.   Call ShowXYversion
  95.   ' we're online !
  96.   OnLineFlag = 1
  97.   ' check that other side has set DSR
  98.   If SioDSR(ThePort) = 0 Then
  99.     Call DisplayLine(TERM, "WARNING: DSR is not set.")
  100.   End If
  101. End Sub
  102.  
  103. Sub RunAS ()
  104.   Dim Code As Integer
  105.   Dim Buffer As String * 81
  106.   Dim Text As String
  107.   Dim Packet As Integer
  108.   ' any messages from xyDriver ?
  109.   While ascGetMessage(Buffer, 80) > 0
  110.     Text = Buffer
  111.     Call DisplayLine(TERM, Text)
  112.   Wend
  113.   ' run the driver
  114.   Code = ascDriver()
  115.   If Code <> 0 Then
  116.     'time to go to next ASCII state (since driver is idle)
  117.     Select Case asState
  118.       '*** ASDRIVER states ***
  119.       Case TX_AS 'Send ASCII
  120.         Code = ascInit(ThePort, RX_QUE_SIZE, 0)
  121.         Code = ascStartTX(TERM.AcceptText.Text, 10, 0, 1)
  122.         asState = RUN_AS
  123.       Case RX_AS 'Receive ASCII
  124.         Code = ascInit(ThePort, RX_QUE_SIZE, 0)
  125.         Code = ascStartRX(TERM.AcceptText.Text, 0, 30, 3, 1)
  126.         'prompt sender with CR
  127.         Code = SioPutc(ThePort, 13)
  128.         asState = RUN_AS
  129.       Case RUN_AS 'ASDRIVER is done
  130.         Call DisplayLine(TERM, "ascDriver is done.")
  131.         asState = 0
  132.         TERM.menuSend.Enabled = True
  133.         TERM.menuReceive.Enabled = True
  134.         TERM.menuBreak.Enabled = False
  135.     End Select
  136.   End If
  137. End Sub
  138.  
  139. Sub RunMIO ()
  140.   Dim i As Integer
  141.   Dim TheChar As Integer
  142.   Dim Code As Integer
  143.   Dim S As String
  144.   'MIO is running
  145.   TheChar = mioDriver(ThePort)
  146.   If TheChar = MIO_IDLE Then
  147.     'time to go to next MIO state (since driver is idle)
  148.     Select Case mioState
  149.       '*** DIAL states ***
  150.       Case Dial_1
  151.         'dial modem [edit to call local BBS]
  152.         S = "!!ATDT" + TERM.AcceptText.Text + "!"
  153.         Call DisplayLine(TERM, S)
  154.         Code = mioSendTo(ThePort, 100&, S)
  155.         mioState = Dial_2
  156.       Case Dial_2
  157.         'expect "CONNECT" back (wait up to 60 seconds)
  158.         If mioWaitFor(ThePort, 60000, "CONNECT") Then
  159.           mioState = Dial_3
  160.         Else
  161.           'error!
  162.           Call DisplayLine(TERM, ">>>mioWaitFor fails!")
  163.           TERM.menuDial.Enabled = True
  164.           mioState = 0
  165.         End If
  166.       Case Dial_3
  167.         'did we get expected result ("CONNECT")
  168.         If mioResult(ThePort) Then
  169.           Call DisplayLine(TERM, ">>>CONNECT was received")
  170.         Else
  171.           Call DisplayLine(TERM, ">>>CONNECT was NOT received!")
  172.         End If
  173.         'all done
  174.         mioState = 0
  175.         TERM.menuBreak.Enabled = False
  176.       End Select
  177.     Else
  178.       'MIO is not IDLE (it's running)
  179.       If TheChar <> MIO_RUNNING Then
  180.         Call DisplayChar(TERM, TheChar)
  181.       End If
  182.     End If
  183. End Sub
  184.  
  185. '
  186. '
  187. Sub RunXY ()
  188.   Dim Code As Integer
  189.   Dim Buffer As String * 81
  190.   Dim Text As String
  191.   Dim Packet As Integer
  192.   ' any messages from xyDriver ?
  193.   While xyGetMessage(ThePort, Buffer, 80) > 0
  194.     Text = Buffer
  195.     Call DisplayLine(TERM, Text)
  196.   Wend
  197.   ' run the driver
  198.   Code = xyDriver(ThePort)
  199.   If Code = XY_IDLE Then
  200.     'time to go to next XY state (since driver is idle)
  201.     TERM.bProgress.Caption = "Ready     "
  202.     TERM.bProgress.Visible = True
  203.     Select Case xyState
  204.       '*** XYDRIVER states ***
  205.       Case TX_XM 'Send XMODEM
  206.         Code = xyStartTX(ThePort, TERM.AcceptText.Text, 0, XMODEM)
  207.         xyState = RUN_XY
  208.       Case RX_XM 'Receive XMODEM
  209.         Code = xyStartRX(ThePort, TERM.AcceptText.Text, NAK, XMODEM)
  210.         xyState = RUN_XY
  211.       Case TX_YM 'Send YMODEM
  212.         Code = xyStartTX(ThePort, TERM.AcceptText.Text, 1, YMODEM)
  213.         xyState = RUN_XY
  214.       Case RX_YM 'Receive YMODEM
  215.         Code = xyStartRX(ThePort, TERM.AcceptText.Text, Asc("C"), YMODEM)
  216.         xyState = RUN_XY
  217.       Case RUN_XY 'XYDRIVER is done
  218.         Call DisplayLine(TERM, "xyDriver is done.")
  219.         xyState = 0
  220.         TERM.menuSend.Enabled = True
  221.         TERM.menuReceive.Enabled = True
  222.         TERM.menuBreak.Enabled = False
  223.         TERM.bProgress.Visible = False
  224.     End Select
  225.  
  226.   Else
  227.     'xyDriver is running
  228.     Packet = xyGetParameter(ThePort, XY_GET_PACKET)
  229.      If Packet <> LastPacket Then
  230.        ''Call DisplayLine(TERM, "Packet " + Str$(Packet))
  231.        TERM.bProgress.Caption = "Packet " + Str$(Packet)
  232.        LastPacket = Packet
  233.      End If
  234.    End If
  235. End Sub
  236.  
  237. Sub ShowConfig ()
  238.   Dim A As String
  239.   Dim B As String
  240.   Dim C As String
  241.   Dim D As String
  242.   Dim E As String
  243.   If OnLineFlag Then
  244.     A = " (Online)"
  245.   Else
  246.     A = " (Offline)"
  247.   End If
  248.   B = "COM" + LTrim$(Str$(ThePort + 1))
  249.   C = " @ " + BaudText(TheBaudCode) + " "
  250.   D = Str$(TheDataBits) + ParityText(TheParity)
  251.   E = LTrim$(Str$(1 + TheStopBits))
  252.   TERM.Caption = "TERM: " + B + C + D + E + A
  253. End Sub
  254.  
  255. Sub ShowXYversion ()
  256.   Dim Version As Integer
  257.   Dim A, B, C As String
  258.   Version = xyGetParameter(ThePort, XY_GET_VERSION)
  259.   '''Call DisplayLine(TERM, Hex$(Version))
  260.   C = Hex$(&HF And Version)
  261.   Version = Version / 16
  262.   B = Hex$(&HF And Version)
  263.   Version = Version / 16
  264.   A = Hex$(&HF And Version)
  265.   Call DisplayLine(TERM, "XYDRV Version " + A + "." + B + "." + C)
  266. End Sub
  267.  
  268.