我这有一段VB程序是为了画实时采集曲线的。
软件编程我不行,如果大家有看得懂得,请帮我看看。
程序不多
Private Sub MSComm1_OnComm() Dim Inbyte() As Byte Dim buffer As String Dim datatemp(1000) As Single If num > 199 Then Call renew '刷新绘图区 '读取仪表返回数据串 Select Case MSComm1.CommEvent Case comEvReceive Inbyte = MSComm1.Input'这地方看不懂,数组可以这样赋值吗? For i = LBound(Inbyte) To UBound(Inbyte) buffer = buffer + Hex(Inbyte(i)) + Chr(32) 'for语句也没看懂,尤其是buffer这赋的是什么值? Next i Case comEvSend End Select '获取十进制测量数据 ’这下面的又是没看懂,应该是将十六进制转换为十进制,怎么转换的呢? If Len(Trim(Mid(buffer, 1, 2))) = 1 Then datatemp(num) = Val("&H" & Mid(buffer, 3, 2) & Str("0") & Mid(buffer, 1, 2)) * 0.01 Else datatemp(num) = Val("&H" & Mid(buffer, 3, 2) & Mid(buffer, 1, 2)) * 0.01 End If
‘绘制曲线 Private Sub draw() Picture1.Cls Picture1.DrawWidth = 2 Picture1.BackColor = QBColor(7) ’下面的程序我看不懂,用的是什么原理画的曲线呢? Picture1.Scale (0, 50)-(200, 0) For i = 1 To num - 1 X1 = (i - 1): Y1 = datatemp(i - 1) X2 = i: Y2 = datatemp(i) Picture1.Line (X1, Y1)-(X2, Y2), QBColor(1) Next i End Sub |