Messages recieved from arduino finish in vbcrlf
Private Function PortRead() As String
Dim msg As String = ""
If Not IsNothing(com1) AndAlso com1.IsOpen Then
tick = True
'string format Capacity tester *C5;V3.22;C102.30;E
'string format 150A tester *!5;V3.22;C102.30;E
Dim MsgIn As String = ""
Try
Try
MsgIn = com1.ReadTo(vbcrlf)
Catch ex As Exception
'Stop
End Try
If MsgIn.Length >= 0 Then
MsgIn = MsgIn.Replace(vbCrLf, "").Trim()
If cb_Date.Checked Then rtb_Serial.Text += DateTime.Now.ToString()
rtb_Serial.Text = MsgIn + vbCrLf + rtb_Serial.Text
If MsgIn.StartsWith("*C") Or MsgIn.StartsWith("*!") Then
Try
Process_Data(MsgIn)
Catch ex As Exception
MessageBox.Show("Message Processing Fail" + vbCrLf + MsgIn, "A15")
End Try
End If
Return MsgIn
Else
Return ""
End If
Catch e As Exception
If Not e.Message = "The operation has timed out." Then
MessageBox.Show("Error Reading Port: " + com1.PortName + vbCrLf + e.Message + vbCrLf + "Port " + com1.PortName + " Closed", "A13")
com1.Close()
End If
End Try
End If
rtb_Serial.Update()
Return msg
End Function
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…