VB中读取电子称的值
我想请教一下,在读取电子称的值得时候,如何读取。我没有搞过这个东东,看了一下别人写的代码,我看不明白,请高手指点一下,帮我解释一下。代码是这样的:(重点帮我分析一下红色字体的代码,我有点看不懂)。Private Sub GetWeight_Value()
On Error Resume Next
Dim BytesReceived() As Byte
Dim buffer As String
Dim HData As String
Dim i As Integer
buffer = Comm1.Input '接收数据至字符串中
BytesReceived() = buffer '将数据转入Byte数组中
For i = 0 To UBound(BytesReceived) '显示结果以十六进制显示
If Len(Hex(BytesReceived(i))) = 1 Then
HData = HData & "0" & Hex(BytesReceived(i))
Else
HData = HData & Hex(BytesReceived(i))
End If
Recievedata = HData
Next
Call Calculatescale
End Sub
Public Sub Calculatescale()
Dim a, b, c, d, e As Integer
e = Mid(Recievedata, 18, 1)
a = Mid(Recievedata, 20, 1)
b = Mid(Recievedata, 24, 1)
c = Mid(Recievedata, 26, 1)
d = Mid(Recievedata, 28, 1)
Weight_value = (e * 10000 + a * 1000 + b * 100 + c * 10 + d * 1) / 1000
Weight_value = Format(Weight_value, "0.0000")
Comm1.OutBufferCount = 0 '清除发送缓冲区
Comm1.InBufferCount = 0 '清除接收缓冲区
Comm1.PortOpen = False
End Sub