|
-
Jan 18th, 2007, 04:57 PM
#3
Thread Starter
Member
Re: [2005] How to use the Timer or Stopwatch Class to timeout in 30 seconds
I ended up using a timer inside a sub that fires on a SerialPort1.PinChanged event and looks for Carrier Detect to raise. Then the code starts a timer that fires in 15 seconds (more or less) which triggers the OnBadConnectionFound sub which resets the port.
Public Sub TimeOutBadConnection(ByVal sender As Object, _
ByVal e As System.IO.Ports.SerialPinChangedEventArgs) _
Handles SerialPort1.PinChanged
Dim portTimer As New System.Timers.Timer()
AddHandler portTimer.Elapsed, AddressOf OnBadConnectionFound
If SerialPort1.CDHolding = True And SerialPort1.BytesToRead = 0 Then
portTimer.Enabled = True
portTimer.Interval = 15000
portTimer.AutoReset = False
GC.KeepAlive(portTimer)
End If
End Sub
Public Sub OnBadConnectionFound(ByVal Source As Object, ByVal e As System.Timers.ElapsedEventArgs) ' Handles portTimer.Elapsed
resetPort()
End Sub
Regards,
Ike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|