863
社区成员
发帖
与我相关
我的任务
分享
Private Sub Form_Load()
With MS1
.CommPort = 1
.Settings = "9600,N,8,1"
.InputLen = 0
.RThreshold = 1
.PortOpen = True
End With
End Sub
Private Sub MS1_OnComm()
Select Case MS1.CommEvent
Case 2
Text1 = ""
Text1.Text = Text1.Text + MS1.Input
End Select
End Sub
Private Sub Text1_Change()
Text1.SelStart = Len(Text1.Text)
End Sub
Private Sub Form_Load()
With MS1
.CommPort = 1
.Settings = "9600,N,8,1"
.InputLen = 0
.RThreshold = 1
.InputMode = comInputModeText
'.InputMode = comInputModeBinary
.PortOpen = True
End With
Text1 = ""
End Sub
Private Sub MS1_OnComm()
Select Case MS1.CommEvent
Case 2
Text1.Text = Text1.Text + MS1.Input
End Select
End Sub
如果有电子秤的通信协议,详细查看通信协议和来写代码。Option Explicit
Private strBuffer As String
Private Sub Form_Load()
' …………
End Sub
Private Sub MS1_OnComm()
Dim strTemp As String
'Select Case MS1.CommEvent
' 如果你只处理1个事件代码的话,没必要Select,用IF就行了。
If (2 = MS1.CommEvent) Then
strTemp = MS1.Input
' 可以用这个“确认”一下标志值是什么。在输出3个“48”之后,就是它了。
Debug.Print Asc(strTemp)
' 下面的xxx就是我提到的“标志”的ASCII码。最初随便写一个,确认之后更正。
If (xxx = Asc(strTemp)) Then
Text1.Text = strBuffer
strBuffer = ""
Else
strBuffer = strBuffer & strTemp
End If
End If
End Sub