Dim Newdata As String Private Sub Command35_Click() Text21.Text = MSComm1.Input End Sub Private Sub Command36_Click() Text20.Text = Val(MSComm1.Input) End Sub Private Sub Form_Load() MSComm1.Settings = "9600,N,8,1" MSComm1.CommPort = 8 MSComm1.InputLen = 1 MSComm1.PortOpen = True MSComm1.RThreshold = 1 Newdata = "" End Sub Private Sub Form_Unload(Cancel As Integer) MSComm1.PortOpen = False End Sub Private Sub MSComm1_OnComm() Dim Dat As String Dim I As Integer 'each incoming char Dim receive As String 'each received char Dim theinfo As String Select Case MSComm1.CommEvent Case comEventRxOver Case comEventTxFull Case comEvReceive Data = MSComm1.Input For I = 1 To Len(Dat) receive = Mid$(Dat, I, 1) If Asc(receive) = 13 Then theinfo = Mid$(Newdata, 2, 1) If theinfo = "I" Then InformationDisplay.SelLength = 0 InformationDisplay.SelStart = Len(InformationDisplay.Text) InformationDisplay.SelText = Newdata + vbCr + vbLf 'include a CR and LF to separate from next line placed in OutputDisplay InformationDisplay.SelLength = 0 ElseIf theinfo = "P" Then OutputDisplay.SelLength = 0 OutputDisplay.SelStart = Len(OutputDisplay.Text) OutputDisplay.SelText = Newdata + vbCr + vbLf 'include a CR and LF to separate from next line placed in OutputDisplay OutputDisplay.SelLength = 0 End If If Asc(theinfo) = 73 Then InformationDisplay.SelStart = Len(InformationDisplay.Text) InformationDisplay.SelText = Newdata + vbCr + vbLf Newdata = "" 'clear NewData so it can assemble the next packet Data.SelLength = 0 Data.SelStart = 2 Data.SelText = vbCrLf Data.SelLength = 0 ElseIf Asc(theChar) <> 10 Then 'ignore linefeeds Newdata = Newdata + theChar 'received a character -- append it to NewData Data.SelLength = 0 Data.SelStart = Len(Data.Text) Data.SelText = theChar Data.SelLength = 0 End If End If Next I Case comEvSend Case comEvEOF End Select End Sub
Data = MSComm1.Input For I = 1 To Len(Dat)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)