VB.NET实现windows应用程序开发串口调试并实时实时保存数据和画图

前端之家收集整理的这篇文章主要介绍了VB.NET实现windows应用程序开发串口调试并实时实时保存数据和画图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

自己最近做了一个关于VB.NET开发的串口调试程序,实现了和下位机DSP的通信,并且实现了实时画图功能,DSP把整形数据(占4个byte),左移后通过DMA方式先发高位,接收后用位段方式转化为整型。同时接受两路数据并以streamwrite的形式自动保存到.txt文件中。

Dim bvMaternal As BitVector32
Dim bvFetal As BitVector32
Dim sec1 As BitVector32.Section = BitVector32.CreateSection(255)
Dim sec2 As BitVector32.Section = BitVector32.CreateSection(255,sec1)
Dim sec3 As BitVector32.Section = BitVector32.CreateSection(255,sec2)
Dim sec4 As BitVector32.Section = BitVector32.CreateSection(255,sec3)

画图函数的实现:

Private Sub draw()


'Maternal signal coordinate
Dim mtlY2 As Single
Dim mtlX2 As Single
Dim mtlY1 As Single
Dim mtlX1 As Single
'Fetal signal coordinate
Dim ftlY2 As Single
Dim ftlX2 As Single
Dim ftlY1 As Single
Dim ftlX1 As Single


Dim mypenMaternal As New Pen(Color.Red,1)
Dim mypenFetal As New Pen(Color.Green,1)
Dim mygraphMaternal As Graphics
Dim mygraphFetal As Graphics
'Maternal signal drawing setup
mygraphMaternal = Me.picBoxMatenal.CreateGraphics

'X-axis and Y-axis Adjust parameter Get:

Dim XnumericUpDownVal As Integer = NumericUpDownX.Value
Dim YnumericUpDownVal As Integer = NumericUpDownY.Value


'Use FromImage method to creat an graphics object with bitmap
'mygraphMaternal = Graphics.FromImage(m_objDrawingMatSurface)


mygraphMaternal.PageUnit = GraphicsUnit.Point
mygraphMaternal.TranslateTransform(0,picBoxMatenal.Height / 2)
'Fetal signal drawing setup
mygraphFetal = Me.picBoxFetal.CreateGraphics

'Use FromImage method to creat an graphics object with bitmap
'mygraphFetal = Graphics.FromImage(m_objDrawingFetSurface)


mygraphFetal.PageUnit = GraphicsUnit.Point
mygraphFetal.TranslateTransform(0,picBoxFetal.Height)

mtlY2 = DataMaternal(Me.receiveDisplay_count) / YnumericUpDownVal
mtlX2 = Me.receiveDisplay_count / XnumericUpDownVal
mtlY1 = DataMaternal(Me.receiveDisplay_count - 1) / YnumericUpDownVal
mtlX1 = (Me.receiveDisplay_count - 1) / XnumericUpDownVal
'Fetal signal coordinate
ftlY2 = DataFetal(Me.receiveDisplay_count) / YnumericUpDownVal
ftlX2 = Me.receiveDisplay_count / XnumericUpDownVal
ftlY1 = DataFetal(Me.receiveDisplay_count - 1) / YnumericUpDownVal
ftlX1 = (Me.receiveDisplay_count - 1) / XnumericUpDownVal
'Dim MaternalPoints As Point() = {New Point(mtlX1,mtlY1),New Point(mtlX2,mtlY2)}
'Dim FetalPoints As Point() = {New Point(ftlX1,ftlY1),New Point(ftlX2,ftlY2)}
mygraphMaternal.DrawLine(mypenMaternal,mtlX1 + 16,-mtlY1 * 126,mtlX2 + 16,-mtlY2 * 126)
mygraphFetal.DrawLine(mypenFetal,ftlX1 + 16,-ftlY1 * 126,ftlX2 + 16,-ftlY2 * 126)
'mygraphMaternal.DrawCurve(mypenMaternal,MaternalPoints,1.0F)
'mygraphFetal.DrawCurve(mypenFetal,FetalPoints,1.0F)


'clean up
mygraphMaternal.Dispose()
mygraphFetal.Dispose()
'Force the form to paint itself,this triggers the Paint event
'Me.picBoxMatenal.Invalidate()
'Me.picBoxFetal.Invalidate()

End Sub



猜你在找的VB相关文章