Robert Carlsson
Member
Hey all!
I've been developing a function block, and at the end of this function block I want to write error code to an output variable, #RET. If there were no error, I want to write the value w#16#0, if there were an error, I want the error code to be returned. Here is the code:
This only works halfway. If I have an error, the error code is written to #RET and there's nothing strange about that. But when there is no error, the execution jumps to done (and the code between err and done is never executed), but still the previous error code sticks. When getting another error code, the #RET is changed immediately, but as soon as I clear every error, nothing happens.
I managed to get the things working by changing the code to this:
Where the only change is after the done label.
Does anyone have an explination why it didn't work with the first code?
Thanks
I've been developing a function block, and at the end of this function block I want to write error code to an output variable, #RET. If there were no error, I want to write the value w#16#0, if there were an error, I want the error code to be returned. Here is the code:
Code:
err: NOP 0
L #iReturn
L W#16#8000 // Make sure the error bit is set
OW
T #RET // Write the error information to the RET variable
SET
SAVE
JU exit
done: NOP 0
L 0 // Make sure the RET variable indicates no error has occured
T #RET
SET
SAVE
exit: NOP 0
I managed to get the things working by changing the code to this:
Code:
err: NOP 0
L #iReturn
L W#16#8000 // Make sure the error bit is set
OW
T #RET // Write the error information to the RET variable
SET
SAVE
JU exit
done: NOP 0
L P##RET // Make sure the RET variable indicates no error has occured
LAR1
L 0
T W [AR1,P#0.0]
SET
SAVE
exit: NOP 0
Does anyone have an explination why it didn't work with the first code?
Thanks