Error Recovery - Unhandled Error

JohnG
JohnG
edited July 8 in RAPID Programming
I'm having trouble creating an error and having the error handler work with that error. Below is one example of a section of code that basically models a WaitDI instruction but I need it to scan faster than the default .1 second polling. I want to be able to trigger an error if the MaxTime was hit. 

Every time I run the code below I get the error "40229, Unhandled error". Any help on what I'm doing wrong or missing here is appreciated!


VAR clock TimeClock;
VAR errnum ERR_FastWait_MaxTime:=-1;

PROC main ()
    BookErrNo ERR_FastWait_MaxTime;
    FastWaitDi diInspectAcqCmplt, 1, .01 \MaxTime:=.5;
ERROR
    IF ERRNO = ERR_FastWait_MaxTime THEN
        !do something
    ENDIF
ENDPROC

MODULE NewModule (NOSTEPIN)
PROC FastWaitDi (VAR signaldi SignalName, num TargetValue, num LoopDelay, \num MaxTime)
    IF Present(MaxTime) THEN
        ClkReset TimeClock;
        ClkStart TimeClock;
        WHILE SignalName <> TargetValue AND ClkRead(TimeClock) <= MaxTime DO
            WaitTime LoopDelay;
        ENDWHILE
        IF ClkRead(TimeClock) >= MaxTime THEN
            RAISE ERR_FastWait_MaxTime;
        ENDIF
    ELSE
        WHILE SignalName <> TargetValue DO
            WaitTime LoopDelay;
        ENDWHILE
    ENDIF
ENDPROC
ENDMODULE
Post edited by JohnG on

Comments

  • lemster68
    lemster68 United States ✭✭✭
    Change to:
    TEST ERRNO
      CASE ERR_FastWait_Maxtime:
    DEFAULT
       Stop;
    ENDTEST
     When the program stops look at the system variable ERRNO, it will have a value.  Match the value up with the predefined errors in the list.  This will tell you what the actual error was and you can accommodate for it or figure out what you have wrong.
    Lee Justice
  • Thanks for the quick reply. That did help me track it down a bit.

    Turns out it was fighting me by having the error handling in the procedure calling the one that raises the error. The code below seemed to have solved it by sending the error backwards in the call stack so to speak:
    VAR clock TimeClock;
    VAR errnum ERR_FastWait_MaxTime:=-1;
    
    PROC main ()
        BookErrNo ERR_FastWait_MaxTime;
        FastWaitDi diInspectAcqCmplt, 1, .01 \MaxTime:=.5;
    ERROR
        IF ERRNO = ERR_FastWait_MaxTime THEN
            !do something
        ENDIF
    ENDPROC
    
    MODULE NewModule (NOSTEPIN)
    PROC FastWaitDi (VAR signaldi SignalName, num TargetValue, num LoopDelay, \num MaxTime)
        IF Present(MaxTime) THEN
            ClkReset TimeClock;
            ClkStart TimeClock;
            WHILE SignalName <> TargetValue AND ClkRead(TimeClock) <= MaxTime DO
                WaitTime LoopDelay;
            ENDWHILE
            IF ClkRead(TimeClock) >= MaxTime THEN
                RAISE ERR_FastWait_MaxTime;
            ENDIF
        ELSE
            WHILE SignalName <> TargetValue DO
                WaitTime LoopDelay;
            ENDWHILE
        ENDIF
    ERROR
        IF ERRNO = ERR_FastWait_MaxTime THEN
            RaiseToUser \BreakOff \ErrorNumber:=ERR_FastWait_MaxTime;
        ENDIF
    ENDPROC
    ENDMODULE