help with timer - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

help with timer

felicityfelicity Posts: 1Member
Hello all,

I am a newbie and i am totally lost.Do help me.

I want to accurately find baud rate.

I have already programmed such that if i send character 'i' i get some value from my microcontroller.


But the problem is i dont know how to program this:


[b]In 10 sec, how many times I can transmit 'i' and receive data.[/b]

I thought all i have to do is set a timer that counts till ten and in the meanwhile transmit 'i' but i found that the timer does not seem to work parallely at all.


here is the code which dint work.


Code:
[code]
Public Class Form1
Dim i As Integer
Dim count As Integer
Dim txt As String


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Timer1.Enabled = True

End Sub

Private Sub calculate_transmit()
Do While i < 10
SerialPort1.WriteLine("i")
txt = SerialPort1.ReadChar
count = count + 1
Debug.Print(txt)
Loop

Debug.Print("total 'i' sent = ")
Debug.Print(count)

End Sub

Private Sub Form1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Click

calculate_transmit()

End Sub


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

i = i + 1

End Sub
[/code]

Comments

  • lionblionb Posts: 1,688Member ✭✭
    :
    Instead of timer you can try DateDiff() function
    [code]
    Private Sub Form1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Click

    Dim dteStart As Date = Now
    calculate_transmit(dteStart)

    End Sub

    Private Sub calculate_transmit(ByVal dteStart As Date)

    Dim i As Integer
    Dim count As Long
    Dim txt As String
    Dim dteEnd As Date
    Dim intDateDiff As Integer

    Do While intDateDiff <= 10
    Do While i < 10
    SerialPort1.WriteLine("i")
    txt = SerialPort1.ReadChar
    count = count + 1
    Debug.Print(txt)
    Loop
    dteEnd = Now
    intDateDiff = DateDiff(DateInterval.Second, dteStart, dteEnd)
    Loop

    Debug.Print("total 'i' sent = ")
    Debug.Print(count)

    End Sub
    [/code]

    I did not try this code but I think this idea will work
Sign In or Register to comment.