Brendan has provided a great service to those of us having to do Serial communications.... still.
I have however found a small bug when a time delay between writes and reads spans midnight. In this case, the application will hang indefinitely waiting for Timer to reach a value greater than 86400 seconds. Since Timer is seconds since midnight, it has values ranging only from 0 to 86400.
Here is a patch to the Delay subroutine I believe will resolve this issue. I welcome others to make suggestions on improving this workaround. This solution has a downside in that all events are paused up until midnight. At most, this should be a couple of seconds. More typically, this would be nearer 0.1 seconds.
Note that since the time delay value T is typically much less than one second any new solutions will need more precision in the wait than a single second.
- Private Sub Delay(T As Single)
- If T = 0 Then Exit Sub
- Dim TempSNG As Single
- TempSNG = Timer
- If TempSNG + T > 86400 Then 'Check for timed event spanning midnight 86400 = seconds in a day
- TempSNG = TempSNG - 86400
- Application.Wait "00:00:00" 'Need to wait until midnight or execution will be immediate
- End If
- Do While Timer < TempSNG + T
- DoEvents ' Yield to other processes.
- End Sub