KRC4 Compact, KR6 Agilus, KSS 8.3.38
Well, this started as a "WTF am I doing wrong?" post, but I figured it out partway through.
What happened was the SPS code (below) was working, in that it stopped and cancelled the current program, and selected Abort() in the Level 1 interpreter. But once it did that, I couldn't run the Abort program, or even cancel it. I just kept getting Error 306, "Selection Active." I discovered the only way to Cancel the program was to de-select the SPS first. That should have been a big clue, but it took me a while to catch on.
Well, the problem turned out to be obvious, after I spent enough skull sweat on it. It was my boolean variables that controlled the IF statements. Because I wasn't resetting bAbortInProcess after performing the CWRITE-RUN, I had created a situation where, after the Abort() program had been selected, the SPS was constantly repeating the Stop/Cancel/Run loop. But it wasn't visible on the SmartPad -- the "Selection Active" error was the only real clue.
So, the cure was to reset my bAbortInProcess variable immediately following the CWRITE-RUN command, to keep the SPS pointer from re-entering the first IF statement.
IF bAbortInProcess THEN
IF NOT bAbortComplete THEN
IF ($PRO_STATE1 == #P_ACTIVE) THEN
$out [1030]=true
CWRITE ($CMD, STAT, MODE, "STOP 1")
ENDIF
IF ($PRO_STATE1 == #P_STOP) THEN
$out [1031]=true
CWRITE ($CMD, STAT, MODE, "CANCEL 1")
ENDIF
IF ($PRO_STATE1 == #P_FREE) THEN
$out [1032]=true
CWRITE($CMD,STAT,MODE,"RUN /R1/Abort()")
ENDIF
ENDIF
ENDIF
Display More