In order to locate the problem, I set up a datalogger on the comport to monitor the timing information. After 860 Hours and 14 minutes, the time stopped moving for a number of hours, then started again. The rest of the application, including this task, was still running (the com routine is embedded in it). I'm at a loss as to what the problem is, especially after running flawlessly for so long. The effect is as if the WaitForInterval never triggers, although, if that were the case, the console output routine wouldn't run either.
The code is shown below. Coding conventions aside, are there any hidden problems here that I'm not seeing?
Code: Select all
Public Sub HourTask() 'Hour Meter Task - Call this task in Sub Main() to start counting
Dim I As Byte
Dim Loc as Byte
Dim Temp as Single
Dim SECONDS_VALUE as Byte
Temp = 0.0
Loc = 0
SECONDS_VALUE = 0
For I = 0 to 199
If Hours(I) > Temp Then
Temp = Hours(I)
Loc = I
End If
Next
Call SetInterval(1.0) 'set the interval
Do
Call WaitForInterval(0) 'Wait for 1 Second
SECONDS_VALUE = SECONDS_VALUE + 1
If SECONDS_VALUE >= 60 Then
Hours(Loc) = Temp + 1.0 'increment the value
Temp = Hours(Loc)
'Circular Buffer
Loc = Loc + 1
If Loc >= 200 Then
Loc = 0
End If
SECONDS_VALUE = 0
End If
'*********Monitor Output******************************
If Monitor > 0 Then 'logger output (once per second)
Console.WriteLine(ConvertTime(HoursTotal()) & "," & C & "," _
& CStr(CBool(Register.PortC>=&hF0)) & "," & CStr(Alarm_Request))
End If
Loop
End Sub