我想测量两个串行接收数据之间的时间 [英] I Want To Measure Time Between Two Serial Received Data

查看:53
本文介绍了我想测量两个串行接收数据之间的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,

Hello Everyone,

在我的项目中,我通过串行通信从我的vb程序上的微控制器接收数据,我正在获得有关我程序的准确数据......

In my project I am receiving data from a microcontroller on my vb programme through serial communication and I am getting accurate data on my programme...

现在接下来我想测量两个串行接收数据之间的时间......所以plz帮助我这样做,因为我自己无法做到这一点。我会非常感激

Now next I want to measure the time between two serially received data... So plz help me in doing this as I am unable to this on my own. I Shall be very thankful

我在下面附上我的代码 

I am attaching my code below  

 ''''''''''''''Variables for serial communication'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim i As Integer
    Dim WithEvents myPort As New SerialPort
    Dim inData As UInt32
    Dim n As UInt32
    Dim l As UInt32
    Public Delegate Sub myDelegate1(ByVal n As UInt32)
 
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        
        myPort.PortName = "COM2"
        myPort.BaudRate = 115200
        myPort.Parity = Parity.None
        myPort.DataBits = 8
        myPort.StopBits = StopBits.One
        myPort.Encoding = Encoding.ASCII

    End Sub
    Private Sub myPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles myPort.DataReceived
        
        While myPort.BytesToRead > 0
            inData = myPort.ReadLine
           
            Me.BeginInvoke((New myDelegate1(AddressOf Graph1Delegate)), n)
        End While
    
    End Sub
    Private Function Graph1Delegate()
        n = n + inData
      
        l = n * 5
        TextBox3.Text = n
        TextBox2.Text = l
             


    End Function

推荐答案


现在接下来我想测量两个串行接收数据之间的时间......所以plz帮助我这样做,因为我自己无法做到这一点。我会非常感激

Now next I want to measure the time between two serially received data... So plz help me in doing this as I am unable to this on my own. I Shall be very thankful

收到第一个时,请记录时间。 收到第二个时,再次记录时间。 从第二个中减去第一个以获得差异。

When the first one is received, record the time.  When the second one is received, record the time again.  Subtract the first from the second to get the difference.

最简单的实现是将当前时间添加到集合中(例如,List(Of))以用于每个事件,并且之后的差异计算。  

The simplest implementation would be to add the current time to a collection (eg, a List(Of)) for every event, and do the difference calculation later.  


这篇关于我想测量两个串行接收数据之间的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆