hi ,
I have a code as below. It receive data from PLC machine through rs232. This machine have 3 stations that will be sending out data once testing completed. all the 3 station will be tested simultaneously or 1 by 1.
It was working fine until I notice that recently i have missing data. Assume that i supposed to receive 100 data but receive only about 90% of it. Any idea how i can prevent from missing data when receiving ?
I have a code as below. It receive data from PLC machine through rs232. This machine have 3 stations that will be sending out data once testing completed. all the 3 station will be tested simultaneously or 1 by 1.
It was working fine until I notice that recently i have missing data. Assume that i supposed to receive 100 data but receive only about 90% of it. Any idea how i can prevent from missing data when receiving ?
Code:
Private Sub MSComm1_OnComm()
Dim i As Long
Dim strInput As String
Dim strEnd As String
Dim strNow As String
i = 0
strInput = ""
strNow = ""
Label7.Caption = ""
Label7.BackColor = vbYellow
strTerminalCharacter = vbCrLf
Do
strInput = strInput & MSComm1.Input
DoEvents
i = i + 1
strEnd = Right(strInput, 2) 'Incase want to check Terminal Characters
Text3.Text = i
If MSComm1.PortOpen Then Shape1.BackColor = vbGreen Else Shape1.BackColor = vbRed
DoEvents
Loop Until (i > 3000) Or (strEnd = strTerminalCharacter)
If (Len(strInput) >= nTotalLengthReceive) And (strEnd = strTerminalCharacter) Then
If (List1.ListCount >= nAutoSaveData) Then Call Command2_Click 'Auto save data after how many scan
Text1.Text = Left(strInput, nDataLength)
Label7.Caption = Left(strInput, nDataLength)
If Check1.Value = 1 Then
Clipboard.Clear
Clipboard.SetText (Label7.Caption)
End If