VB与电子秤(XK3190-A9)进行通讯,读取显示数值,希望了解的朋友可以提供给我些源代码,谢谢。

我的邮箱是:miracle323@126.com
2024-11-25 07:58:32
推荐回答(2个)
回答1:

建立一个工程,把全部代码拷入,即可测试。
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

回答2:

有关电子秤技术的问题,可直接与”郑州今迈衡器”联系,专业研发电子秤的商家.