VERSION 5.00 Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX" Begin VB.Form MainForm Caption = "REMOTE ACCES Sample" ClientHeight = 5055 ClientLeft = 60 ClientTop = 345 ClientWidth = 11175 LinkTopic = "Form1" ScaleHeight = 337 ScaleMode = 3 'Pixel ScaleWidth = 745 StartUpPosition = 3 'Windows Default Begin VB.Timer InTime Enabled = 0 'False Interval = 100 Left = 8160 Top = 120 End Begin VB.TextBox ReceivedMemo BeginProperty Font Name = "Courier New" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 2775 Left = 2280 MultiLine = -1 'True ScrollBars = 3 'Both TabIndex = 15 Top = 2160 Width = 8775 End Begin VB.TextBox SentMemo BeginProperty Font Name = "Courier New" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 2775 Left = 120 MultiLine = -1 'True ScrollBars = 3 'Both TabIndex = 14 Top = 2160 Width = 2055 End Begin VB.CommandButton HelpButton Caption = "Help" Height = 375 Left = 9480 TabIndex = 12 Top = 840 Width = 1575 End Begin VB.CommandButton FirmButton Caption = "Firmware Revision" Height = 375 Left = 7800 TabIndex = 11 Top = 840 Width = 1575 End Begin VB.CommandButton GreetButton Caption = "Greeting" Height = 375 Left = 6120 TabIndex = 10 Top = 840 Width = 1575 End Begin VB.CommandButton ResendButton Caption = "Resend" Height = 375 Left = 4440 TabIndex = 9 Top = 840 Width = 1575 End Begin VB.CommandButton SendButton Caption = "Send" Height = 375 Left = 2280 TabIndex = 8 Top = 840 Width = 735 End Begin VB.TextBox SendEdit Height = 315 Left = 120 TabIndex = 7 Top = 840 Width = 2055 End Begin VB.CommandButton ConnectButton Caption = "Connect" Height = 375 Left = 9240 TabIndex = 6 Top = 120 Width = 1575 End Begin VB.TextBox PortEdit Height = 315 Left = 6120 TabIndex = 5 Text = "5" Top = 120 Width = 495 End Begin VB.CommandButton BaudButton Caption = "28800" Height = 375 Index = 1 Left = 3360 TabIndex = 3 Top = 120 Width = 1095 End Begin VB.CommandButton BaudButton Caption = "9600" Height = 375 Index = 0 Left = 2160 TabIndex = 2 Top = 120 Width = 1095 End Begin MSCommLib.MSComm Commo Left = 3480 Top = 720 _ExtentX = 1005 _ExtentY = 1005 _Version = 393216 CommPort = 5 DTREnable = -1 'True RThreshold = 1 ParitySetting = 2 DataBits = 7 End Begin VB.Label SyncLabel Caption = "This sample inserts ellipses(...) for synchronization purposes. These are not actually transmitted or received." Height = 255 Left = 120 TabIndex = 17 Top = 1440 Width = 10935 End Begin VB.Label ReceivedLabel Alignment = 2 'Center Caption = "Received" Height = 375 Left = 2280 TabIndex = 16 Top = 1770 Width = 8775 End Begin VB.Label SentLabel Alignment = 2 'Center Caption = "Sent" Height = 375 Left = 120 TabIndex = 13 Top = 1770 Width = 2055 End Begin VB.Label PortLabel Alignment = 1 'Right Justify Caption = "COM Port:" Height = 375 Left = 4560 TabIndex = 4 Top = 120 Width = 1455 End Begin VB.Label BaudStatic Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "9600" Height = 255 Left = 1320 TabIndex = 1 Top = 180 Width = 735 End Begin VB.Label BaudLabel Alignment = 1 'Right Justify Caption = "Baud rate:" Height = 375 Left = 120 TabIndex = 0 Top = 120 Width = 1095 End End Attribute VB_Name = "MainForm" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim ExpectingLine As Boolean Dim InLin As String Private Sub BaudButton_Click(Index As Integer) Dim BaudStr As String Dim Timeout As Long BaudStr = BaudButton(Index).Caption If Commo.PortOpen Then Select Case BaudStr Case "1200" SendCommand "BAUD=000" Case "2400" SendCommand "BAUD=111" Case "4800" SendCommand "BAUD=222" Case "9600" SendCommand "BAUD=333" Case "14400" SendCommand "BAUD=444" Case "19200" SendCommand "BAUD=555" Case "28800" SendCommand "BAUD=666" Case "57600" SendCommand "BAUD=777" Case Else Exit Sub End Select 'Wait for incoming signal or until .1s have passed Timeout = Timer Do DoEvents Loop Until (Not ExpectingLine) Or Abs(Timer - Timeout) > 0.1 Commo.Settings = BaudStr + ",e,7,1" End If BaudStatic.Caption = BaudStr End Sub Private Sub Commo_OnComm() Dim I As Integer If Commo.CommEvent = comEvReceive Then InTime.Enabled = False InLin = InLin + Commo.Input Do I = InStr(InLin, vbCr) If I = 0 Then If InLin <> "" Then InTime.Enabled = True Exit Do End If ReceivedMemo.Text = ReceivedMemo.Text + Left$(InLin, I - 1) + vbCrLf InLin = Mid$(InLin, I + 1) ReceivedMemo.SelStart = Len(ReceivedMemo.Text) If ExpectingLine Then ExpectingLine = False Else SentMemo.Text = SentMemo.Text + "..." + vbCrLf SentMemo.SelStart = Len(SentMemo.Text) End If Loop End If End Sub Private Sub ConnectButton_Click() Static DoDisconnect As Boolean On Error Resume Next If DoDisconnect Then Commo.PortOpen = False ConnectButton.Caption = "Connect" DoDisconnect = False Else Commo.CommPort = PortEdit.Text If Err Then GoTo Complain Commo.PortOpen = True If Err Then GoTo Complain ConnectButton.Caption = "Disconnect" DoDisconnect = True Commo.Settings = BaudStatic.Caption + ",e,7,1" End If Exit Sub Complain: MsgBox _ "Failed to connect: " + Err.Description, _ vbApplicationModal Or vbExclamation Or vbMsgBoxSetForeground, _ "Can't Connect", 0, 0 End Sub Private Sub SendCommand(Data As String) If ExpectingLine Then ReceivedMemo.Text = ReceivedMemo.Text + "..." + vbCrLf ReceivedMemo.SelStart = Len(ReceivedMemo.Text) End If Commo.Output = Data + vbCr SentMemo.Text = SentMemo.Text + Data + vbCrLf SentMemo.SelStart = Len(SentMemo.Text) ExpectingLine = True End Sub Private Sub InTime_Timer() Dim I As Integer InTime.Enabled = False If InLin <> "" Then Do I = InStr(InLin, vbCr) If I = 0 Then If InLin <> "" Then ReceivedMemo.Text = ReceivedMemo.Text + InLin + vbCrLf InLin = "" ReceivedMemo.SelStart = Len(ReceivedMemo.Text) If ExpectingLine Then ExpectingLine = False Else SentMemo.Text = SentMemo.Text + "..." + vbCrLf SentMemo.SelStart = Len(SentMemo.Text) End If End If Exit Do End If ReceivedMemo.Text = ReceivedMemo.Text + Left$(InLin, I - 1) + vbCrLf InLin = Mid$(InLin, I + 1) ReceivedMemo.SelStart = Len(ReceivedMemo.Text) If ExpectingLine Then ExpectingLine = False Else SentMemo.Text = SentMemo.Text + "..." + vbCrLf SentMemo.SelStart = Len(SentMemo.Text) End If Loop End If End Sub Private Sub SendButton_Click() SendCommand SendEdit.Text End Sub Private Sub ResendButton_Click() SendCommand ("N") End Sub Private Sub GreetButton_Click() SendCommand ("H") End Sub Private Sub FirmButton_Click() SendCommand ("V") End Sub Private Sub HelpButton_Click() SendCommand ("?") End Sub