16,555
社区成员
发帖
与我相关
我的任务
分享
'放在线程里计算的
For iCount = 0 To UBound(volArr)
Drawpoints(iCount).X = iCount / k * 58 * 10 + Org_x
Drawpoints(iCount).Y = Org_Y - volArr(iCount) * 31
Next
lbl_Xyplot.Text = CStr(Environment.TickCount - starttime) '绘制坐标轴耗时 显示43ms
If Not volArr Is Nothing Then
linepen.Width = 2
linepen.Color = Color.Green
xyplot.DrawLines(linepen, Drawpoints) '绘制波形
lbl_WAVE.Text = CStr(Environment.TickCount - starttime) '显示波形耗时 显示5183ms
volArr = Nothing
RecDataArr = Nothing
End If
'PictureBox重绘过程
Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
xyplot = e.Graphics '生成XYplot
DrawXYPlotCanvas()
End Sub
'电压转换过程
Public Sub Threadcal()
Dim i As Integer
Dim j As Integer
Dim Volint As Integer
Dim ax, bx As Integer
ThreadStart = Environment.TickCount
For i = 0 To UBound(RecDataArr)
If ((i + 23) < UBound(RecDataArr)) Then
ax = 0
bx = 0
ax = CInt(RecDataArr(i)) + CInt(RecDataArr(i + 1))
bx = CInt(RecDataArr(i + 22)) + CInt(RecDataArr(i + 23))
If ((bx - ax) = 10) Then
For j = i + 2 To i + 19
If volArr Is Nothing Then
ReDim volArr(0)
Volint = RecDataArr(j) * 256 + RecDataArr(j + 1)
If Volint > 32768 Then '负数判断
Volint = DEC_to_Neg(Volint)
End If
volArr(0) = Volint / 32768 * 5
Else
ReDim Preserve volArr(UBound(volArr) + 1)
Volint = RecDataArr(j) * 256 + RecDataArr(j + 1)
If Volint > 32768 Then '负数判断
Volint = DEC_to_Neg(Volint)
End If
volArr(UBound(volArr)) = Volint / 32768 * 5
End If
j = j + 1
Next
i = i + 21
End If
End If
Next
'如果采样的数据量小于500 则直接退出程序
If UBound(volArr) < 500 Then Exit Sub
'电压转换为坐标像素点
Dim iCount As Integer
Dim k As Integer
k = UBound(volArr)
ReDim Drawpoints(k)
For iCount = 0 To UBound(volArr)
Drawpoints(iCount).X = iCount / k * 58 * 10 + Org_x
Drawpoints(iCount).Y = Org_Y - volArr(iCount) * 31
Next
Threadend = Environment.TickCount - ThreadStart
ThreadStart = 0
AccessControl()
b_Recived = False '接收完成标志复位
End Sub
这是我把串口接收到的数据转换为电压值的过程和转换为像素点的过程,我统计了,大概耗时是3456毫秒,我用断点设置也是差不多这个时间,我把这个线程的优先级设置到最高了,然后绘图,绘图过程经常要消耗10秒左右,而且我也是先用bitmap绘制,然后把设置picturebox1,image=bitmap来绘制,速度没有多少提高,在线程里面转换的字节一共有13K的字节,转换成6.5K字左右,然后把这个字转换坐标像素
难道真的是配置不行?