'-----------------------------------------------
' 接收触法事件
'-----------------------------------------------
'获取温度测量值并显示
'每发送一次指令,触发下面事件,返回数据串
Private Sub MSComm1_OnComm()
Dim Inbyte()As Byte ' 接收数据暂存
Dim bufferAs String ' 温度数据缓冲
Dimdatatemp2a, datatemp2b As String ' 两字节进制温度数据
Dimdatatemp2 As String ' 十六进制温度数据
Dim count AsInteger ' 接收个数计数
If num > Txttimes.Text - 1 Then ' 接收个数判断
Timer1.Enabled = False ' 接收完毕
Shpstate.FillColor = &H80FF&
Exit Sub
End If
'读取仪表返回数据串
Select CaseMSComm1.CommEvent
CasecomEvReceive
count= MSComm1.InBufferCount ' 接收温度数据个数,两字节,低位在前
Inbyte = MSComm1.Input ' 接收温度数据
If count <> 2 Then Exit Sub ' 不是两字节,表示接收错误,跳出程序
counter = counter + 1 ' 基数器加1
For i = LBound(Inbyte) To UBound(Inbyte) ' 把接收的数据安十六进制格式放入缓冲中
buffer= buffer + Hex(Inbyte(i)) + Chr(32)
Next i
End Select
'获取十进制测量数据
IfLen(Trim(Mid(buffer, 1, 2))) = 1 Then
datatemp(num) = Val("&H" & Mid(buffer, 3, 3) &Str("0") & Mid(buffer, 1, 2)) * 0.0625
Else
datatemp(num) = Val("&H" & Mid(buffer, 3, 3) &Mid(buffer, 1, 2)) * 0.0625
End If
'获取十六进制测量数据
IfLen(Trim(Mid(buffer, 1, 2))) = 1 Then
datatemp2a = Str("0") & Trim(Mid(buffer, 1, 2))
Else
datatemp2a = Mid(buffer, 1, 2)
End If
IfLen(Trim(Mid(buffer, 4, 2))) = 1 Then
datatemp2b = Str("0") & Trim(Mid(buffer, 3, 2))
Else
datatemp2b = Mid(buffer, 4, 2)
End If
datatemp2 =datatemp2a & " " & datatemp2b
'显示测量温度值
If counter =num + 1 Then ' If datatemp(num) <> 0 Then 不能显示零度,别的正常
Grid.Col= 1: Grid.Row = num + 1
Grid.Text = Format$(datatemp(num), "0.0")
Ifcounter > 13 Then Grid.TopRow = counter - 12 ' 控制滚动条的滚动
TempText= Format$(datatemp(num), "0.0") ' 10进制显示,保留一位小数
num =num + 1
Callcal ' 调用计算极值、平均值子程序
Calldraw ' 调用绘曲线过程
End If
End Sub
请问没注释的这些都是什么意思,最好具体解释一下,老师问的比较细,问每个字符的具体含义。比如Trim(Mid(buffer, 1, 2))中每一项都是什么意思之类的都会问
'获取十进制测量数据
IfLen(Trim(Mid(buffer, 1, 2))) = 1 Then
datatemp(num) = Val("&H" & Mid(buffer, 3, 3) &Str("0") & Mid(buffer, 1, 2)) * 0.0625
Else
datatemp(num) = Val("&H" & Mid(buffer, 3, 3) &Mid(buffer, 1, 2)) * 0.0625
End If
'获取十六进制测量数据
IfLen(Trim(Mid(buffer, 1, 2))) = 1 Then
datatemp2a = Str("0") & Trim(Mid(buffer, 1, 2))
Else
datatemp2a = Mid(buffer, 1, 2)
End If
IfLen(Trim(Mid(buffer, 4, 2))) = 1 Then
datatemp2b = Str("0") & Trim(Mid(buffer, 3, 2))
Else
datatemp2b = Mid(buffer, 4, 2)
End If
datatemp2 =datatemp2a & " " & datatemp2b
' 接收触法事件
'-----------------------------------------------
'获取温度测量值并显示
'每发送一次指令,触发下面事件,返回数据串
Private Sub MSComm1_OnComm()
Dim Inbyte()As Byte ' 接收数据暂存
Dim bufferAs String ' 温度数据缓冲
Dimdatatemp2a, datatemp2b As String ' 两字节进制温度数据
Dimdatatemp2 As String ' 十六进制温度数据
Dim count AsInteger ' 接收个数计数
If num > Txttimes.Text - 1 Then ' 接收个数判断
Timer1.Enabled = False ' 接收完毕
Shpstate.FillColor = &H80FF&
Exit Sub
End If
'读取仪表返回数据串
Select CaseMSComm1.CommEvent
CasecomEvReceive
count= MSComm1.InBufferCount ' 接收温度数据个数,两字节,低位在前
Inbyte = MSComm1.Input ' 接收温度数据
If count <> 2 Then Exit Sub ' 不是两字节,表示接收错误,跳出程序
counter = counter + 1 ' 基数器加1
For i = LBound(Inbyte) To UBound(Inbyte) ' 把接收的数据安十六进制格式放入缓冲中
buffer= buffer + Hex(Inbyte(i)) + Chr(32)
Next i
End Select
'获取十进制测量数据
IfLen(Trim(Mid(buffer, 1, 2))) = 1 Then
datatemp(num) = Val("&H" & Mid(buffer, 3, 3) &Str("0") & Mid(buffer, 1, 2)) * 0.0625
Else
datatemp(num) = Val("&H" & Mid(buffer, 3, 3) &Mid(buffer, 1, 2)) * 0.0625
End If
'获取十六进制测量数据
IfLen(Trim(Mid(buffer, 1, 2))) = 1 Then
datatemp2a = Str("0") & Trim(Mid(buffer, 1, 2))
Else
datatemp2a = Mid(buffer, 1, 2)
End If
IfLen(Trim(Mid(buffer, 4, 2))) = 1 Then
datatemp2b = Str("0") & Trim(Mid(buffer, 3, 2))
Else
datatemp2b = Mid(buffer, 4, 2)
End If
datatemp2 =datatemp2a & " " & datatemp2b
'显示测量温度值
If counter =num + 1 Then ' If datatemp(num) <> 0 Then 不能显示零度,别的正常
Grid.Col= 1: Grid.Row = num + 1
Grid.Text = Format$(datatemp(num), "0.0")
Ifcounter > 13 Then Grid.TopRow = counter - 12 ' 控制滚动条的滚动
TempText= Format$(datatemp(num), "0.0") ' 10进制显示,保留一位小数
num =num + 1
Callcal ' 调用计算极值、平均值子程序
Calldraw ' 调用绘曲线过程
End If
End Sub
请问没注释的这些都是什么意思,最好具体解释一下,老师问的比较细,问每个字符的具体含义。比如Trim(Mid(buffer, 1, 2))中每一项都是什么意思之类的都会问
'获取十进制测量数据
IfLen(Trim(Mid(buffer, 1, 2))) = 1 Then
datatemp(num) = Val("&H" & Mid(buffer, 3, 3) &Str("0") & Mid(buffer, 1, 2)) * 0.0625
Else
datatemp(num) = Val("&H" & Mid(buffer, 3, 3) &Mid(buffer, 1, 2)) * 0.0625
End If
'获取十六进制测量数据
IfLen(Trim(Mid(buffer, 1, 2))) = 1 Then
datatemp2a = Str("0") & Trim(Mid(buffer, 1, 2))
Else
datatemp2a = Mid(buffer, 1, 2)
End If
IfLen(Trim(Mid(buffer, 4, 2))) = 1 Then
datatemp2b = Str("0") & Trim(Mid(buffer, 3, 2))
Else
datatemp2b = Mid(buffer, 4, 2)
End If
datatemp2 =datatemp2a & " " & datatemp2b