Private Sub jiaoyan()
sum1 = 0
For i = 1 To 5
sum1 = sum1 + out1(i)
Next
c(0) = Asc(Hex(sum1 \ (16 ^ 3)))
num5 = sum1 Mod (16 ^ 3)
c(1) = Asc(Hex(num3 \ (16 ^ 2)))
num6 = num5 Mod (16 ^ 2)
c(2) = Asc(Hex(num6 \ 16))
c(3) = Asc(Hex(num6 Mod (16 ^ 1)))
End Sub
Private Sub Command3_Click()
Dim inf As Variant, j As Integer
flag = 1
out1(0) = 5
out1(1) = 48
out1(2) = 49
out1(3) = 54
out1(4) = 70
out1(5) = 49
Call jiaoyan
out1(6) = c(2)
out1(7) = c(3)
MSComm1.Output = out1
MSComm1.InputMode = 1
MSComm1.RThreshold = 10
End Sub
Private Sub Command4_Click()
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub Command6_Click()
out2(0) = 5
out2(1) = 48
out2(2) = 49
out2(3) = 70
out2(4) = 65
out2(5) = 49
out2(6) = 55
out2(7) = 55
out2(8) = 56
out2(9) = 55
MSComm1.Output = out2
MSComm1.RThreshold = 1
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
End Sub
Private Sub MSComm1_OnComm()
Dim Buffer As Variant, m As Integer, instring As String, str1 As String, str2 As String, str3 As String, str4 As String, str5 As String, str6 As String, str7 As String, str8 As String, str9 As String, str10 As String, str11 As String, str12 As String, int1 As Integer, int2 As Integer, int3 As Integer, int4 As Integer, int5 As Integer
Dim Arr() As Byte
Dim a As Single
Select Case MSComm1.CommEvent
Case comEvReceive
Buffer = MSComm1.Input
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
Arr = Buffer
For m = LBound(Arr) To UBound(Arr)
instring = instring + Hex(Arr(m)) + Chr(32)
Next m
Text4.Text = instring
If (flag = 1) Then
str1 = Mid(instring, 9, 1)
str2 = Mid(instring, 10, 1)
int1 = str1 * 16 + str2
str3 = Chr(int1)
If (str3 = "A") Then str3 = 10
If (str3 = "B") Then str3 = 11
If (str3 = "C") Then str3 = 12
If (str3 = "D") Then str3 = 13
If (str3 = "E") Then str3 = 14
If (str3 = "F") Then str3 = 15
str4 = Mid(instring, 12, 1)
str5 = Mid(instring, 13, 1)
int2 = str4 * 16 + str5
str6 = Chr(int2)
If (str6 = "A") Then str6 = 10
If (str6 = "B") Then str6 = 11
If (str6 = "C") Then str6 = 12
If (str6 = "D") Then str6 = 13
If (str6 = "E") Then str6 = 14
If (str6 = "F") Then str6 = 15
str7 = Mid(instring, 15, 1)
str8 = Mid(instring, 16, 1)
int3 = str7 * 16 + str8
str9 = Chr(int3)
If (str9 = "A") Then str9 = 10
If (str9 = "B") Then str9 = 11
If (str9 = "C") Then str9 = 12
If (str9 = "D") Then str9 = 13
If (str9 = "E") Then str9 = 14
If (str9 = "F") Then str9 = 15
str10 = Mid(instring, 18, 1)
str11 = Mid(instring, 19, 1)
int4 = str10 * 16 + str11
str12 = Chr(int4)
If (str12 = "A") Then str12 = 10
If (str12 = "B") Then str12 = 11
If (str12 = "C") Then str12 = 12
If (str12 = "D") Then str12 = 13
If (str12 = "E") Then str12 = 14
If (str12 = "F") Then str12 = 15
int5 = Val(str3) * 4096 + Val(str6) * 256 + Val(str9) * 16 + Val(str12)
a = int5 / 100
Text3.Text = Str(a)
End If
flag = 0
End Select
End Sub