5
« on: July 15, 2015, 12:00:47 PM »
This is completely F-ed up! The code compiles without error, it seems to run correctly, except....
If I load the g-code file (which today loads correctly - Why? I don't know....), and Single-step through it, here's what happens:
The first line, M806 P0, executes correctly, and initalizes the ATC.
The second line, M806 P20, also appears to execute correctly, and lowers the ATC "lift".
The third line, M806, P21, also appears to execute correctly, and raises the ATC "lift".
Here's where it gets strange - If I just wait a bit, after 10-20 seconds, I start getting error dialogs, coming from the code that actually performs the above operations. These dialogs report both Lift Down and Lift Up errors, and come from the LowerLift() and RasieLift() functions. Note the timeouts in these functions are 2 seconds, yet the errors don't pop up for at least 10-20 seconds AFTER the code is executed. Also, since I am single-stepping the G-code, should it not be impossible to single step one line until the macro for the previous line has completed execution? That being the case, how is it possible I am stepping several lines of code, and only getting error dialogs tens of seconds later? The more lines I execute, the more errors I get, and the longer they are delayed before popping up.
When I manually execute the Lift Down and Lift Up operations using MDI, they work perfectly every time.
This makes no sense at all to me, and is CLEARLY different behavior from what I've seen in the past. WTF is going on here?
Here is the LowerLift code. The RaiseLift code is essentially identical except it flips the control but the other way:
Function LowerLift (ByVal verify As Integer) As Integer
If IsOutputActive(ATC_LIFT) = ATC_LIFT_DOWN And IsActive(ATC_LIFT_SENSE) = 0 Then
LowerLift = ATC_ERR_NOERROR
GoTo EXIT4
End If
If verify = 0 Then
ActivateSignal(ATC_LIFT)
Sleep(1000)
LowerLift = ATC_ERR_NOERROR
GoTo EXIT4
End If
LowerLift = ConfirmAction(ATC_LIFT, ATC_LIFT_LOWER, ATC_LIFT_SENSE, ATC_LIFT_TIMEOUT, ATC_ERR_LIFT_DOWN_FAIL)
EXIT4:
CurrentLiftPos = 1
End Function
Function ConfirmAction (ByVal bit As Integer, _
ByVal bitval As Integer, _
ByVal sense As Integer, _
ByVal timeout As Integer, _
ByVal err As Integer) _
As Integer
'' Must not be mid-travel at start
If IsActive(sense) Then
ConfirmAction = err
GoTo Exit7
End If
'' Set/Clear the control bit
If bitval = 1 Then
ActivateSignal(bit)
Else
DeactivateSignal(bit)
End If
'' Ensure it moves - first wait for sensor high
ElapsedTime = 0
i = 0
While i < 10
If IsActive(sense) = 1 Then
i = i + 1
Else
i = 0
End If
Sleep(1)
ElapsedTime = ElapsedTime + 1
If ElapsedTime >= timeout Then
ConfirmAction = err
GoTo EXIT7
End If
Wend
'' Now wait for sensor low
i = 0
While i < 10
If IsActive(sense) = 0 Then
i = i + 1
Else
i = 0
End If
Sleep(1)
ElapsedTime = ElapsedTime + 1
If (ElapsedTime >= timeout) Then
ConfirmAction = err
GoTo EXIT7
End If
Wend
ConfirmAction = ATC_ERR_NOERROR
EXIT7:
End Function
Regards,
Ray L.