这样的例子都没有人共享一下?
我先自己贴这个VB 串口的,希望能抛砖引玉:
Dim Instring As String, WeightValue As String, i As Integer, J As Integer
On Error GoTo MyErrHandler
MSComWeight.Output = "S" & Chr$(13) & Chr$(10)
Select Case
Case comEvReceive
DelayTimer.Enabled = False
Instring = vbNullString
Do While MSComWeight.InBufferCount <> 0
Instring = Instring & MSComWeight.Input
DoEvents
Loop
i = InStr(Instring, " g")
J = InStr(1, Instring, "S S ", vbTextCompare)
If J > 0 And i > 0 Then
txtInputData.Text = Instring
WeightValue = GetWeightValue(Mid(Instring, J + 4, i - J - 2))
txtWeight.Text = WeightValue
txtWeight.BackColor = &HC0C0FF
End If
txtBatchID.SetFocus
DelayTimer.Enabled = True
End Select
Exit Sub
MyErrHandler:
DelayTimer.Enabled = True
'MsgBox "Error: " & Err.Description, vbOKOnly + vbCritical, "Error"