建立一个工程,把全部代码拷入,即可测试。
Private Sub Command1_Click()
Text1.Text = ""
Text3.Text = ""
Label1.Caption = "动 态"
Label1.ForeColor = &HFF&
Timer1.Enabled = True
Timer3.Enabled = True
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.PortOpen = True
End Sub
Private Sub Timer1_Timer()
Dim buffer1, buffer2, buffer3
'buffer2用于保存缓冲区的数据
buffer2 = MSComm1.Input
buffer1 = " "
'查找存缓冲区的数据是否有空格出现因为空格后的数据为有用数据
buffer3 = InStr(buffer2, buffer1)
If buffer3 = 0 Then
Exit Sub
Else
'buffer3为空格出现的位置,加一后取6个长度就是称的读数
buffer3 = buffer3 + 1
Text1.Text = Mid(buffer2, buffer3, 6)
End If
End Sub
Private Sub Timer2_Timer()
Dim buffer1, buffer2, buffer3
buffer2 = MSComm1.Input
buffer1 = " "
buffer3 = InStr(buffer2, buffer1)
If buffer3 = 0 Then
Exit Sub
Else
buffer3 = buffer3 + 1
Text2.Text = Mid(buffer2, buffer3, 6)
End If
End Sub
Private Sub Timer3_Timer()
Dim buffer1, buffer2, buffer3
buffer2 = MSComm1.Input
buffer1 = " "
buffer3 = InStr(buffer2, buffer1)
If buffer3 = 0 Then
Exit Sub
Else
buffer3 = buffer3 + 1
Text3.Text = Mid(buffer2, buffer3, 6)
If Text1.Text = Text3.Text Then
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
Label1.Caption = "稳 态"
Label1.ForeColor = &HFF00&
End If
End If
End Sub
有关电子秤技术的问题,可直接与”郑州今迈衡器”联系,专业研发电子秤的商家.