I am sending data through a COM port and starting my timer with a 4000 interval to send my message back if I did not receive anything before the 4 seconds.
{Load}
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
[...]
SendCard(0)
[...]
End Sub
{SendCard Sub} I'm sending the require information through this Sub by setting the property "LastCommand" which sends the data through the port.
Private Sub SendCard(ByVal cardIndex As Integer)
If cardIndex < Setting.Machine.Cards.Length Then
'Calling LastCommand's Set()
LastCommand = "*" & Setting.Machine.Cards(cardIndex) & ": STRQ" & ControlChars.CrLf
Else
'Blah blah...
End If
End Sub
The property sends the data and start the Timer.
Public Property LastCommand() As String
Get
Return lastCommandString
End Get
Set(ByVal value As String)
lastCommandString = value
MainCOMSerialPort.Write(value)
ResponseTimer.Start()
End Set
End Property
When I receive an answer I stop the timer and then ask the information for the next card.
Private Sub MainCOMSerialPort_DataReceived(...)
[...]
ResponseTimer.Stop() 'After this stop it does not trigger the Tick event any longer.
SendCard(Array.IndexOf(Setting.Machine.Cards, CardString) + 1) 'Sending the next card
[...]
End Sub
The tick event works fine for the first card
Private Sub ResponseTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ResponseTimer.Tick
'MessageBox.Show("No Respone Yet")
LastCommand = LastCommand
End Sub
So it's asking my first command every 4 second until I get something in return, but when I start over with the second command the Timer does not tick.
I'm using .NET 4.0 and the {Windows.Forms.Timer}, I tried with Timers.Timer and did not work either I don't understand why it does not start again.