VB串口接收 绘制曲线
本人编制VB串口接收,绘制曲线程序。 程序如下Dim arr1(190) As String
Private Sub MSComm1_OnComm()
Dim indata As Variant
Dim j As Single
Dim k As Single
Dim arr(0) As Byte
'--------------------------------------------------------------------------------------------
Select Case
Case comEvReceive
indata = MSComm1.Input
arr(0) = AscB(indata)
arr1(j) = arr(0) * 5 / 1024
j = j + 1
For k = 0 To 189
Text1.Text = arr1(k)
Call Waittime(1)
Next k
For k = 0 To 94
Picture2.Line (k, 20 * Val(arr1(k)))-((k + 1), 20 * Val(arr1(k + 1))), vbGreen
Next k
Shape2.FillColor = vbGreen
Shape1.FillColor = vbGreen
MSComm1.InBufferCount = 0
End Select
End Sub
在程序运行时,text能正确显示接收数据,但是绘制曲线时,arr1中数据变为0(头1~2个数据时正确),同时程序运行缓慢,CPU运行速度高。 换位command中,执行绘制曲线,仍然存在arr1数组中数据为零情况,希望大家给我些帮助,在此,先谢谢了。