m.prestel hat geschrieben:
Hello Sir,
ST checks for all the conditions and does not stop early.
AND_THEN does what you describe with nested ifs.
Best regards,
Marcel
Sorry Marcel,
I didn't understood your idea.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unfortunately it doesn't help. Only nested IFs works fine.
For those who want to reproduce it:
FUNCTIONwrite_value_bool : BOOLVAR_INPUT
  PLC      : POINTERTOModbusSlaveComPort;END_VARIFPLC^.xInitDoneANDNOTPLC^.xErrorTHEN
    write_value_bool:=TRUE;ELSE
    write_value_bool:=FALSE;END_IF
And yes, you have to wait for xInitDone to become FALSE or xError TRUE. For this purpose you can do xReset:= TRUE (at ModbusSlaveComPort) for one cycle.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
FUNCTIONwrite_value_bool : BOOLVAR_INPUT
  PLC     : POINTERTOModbusSlaveComPort;END_VARIFPLC^.xInitDoneANDNOTPLC^.xErrorTHEN
    write_value_bool:=TRUE;ELSE
    write_value_bool:=FALSE;END_IF
One should avoid the above IF THEN statements. A better solution could be;
Could you please explain why the following statement is always FALSE:
It runs on RaspberryPi with the latest Codesys Runtime.
PLC is a pointer to ModbusSlaveComPort.
The xInitDone is TRUE, xError is FALSE.
If I rewrite the code in such way it works as expected:
What is the result if you replace dereferenced pointers by only boolean variables ?
Hello Sir,
ST checks for all the conditions and does not stop early.
AND_THEN does what you describe with nested ifs.
Best regards,
Marcel
Sorry Marcel,
I didn't understood your idea.
It works as expected.
and if you try :
Sorry I misunderstood you...
Can you provide a small example application to easyly reproduce?
Best regards,
Marcel
Unfortunately it doesn't help. Only nested IFs works fine.
For those who want to reproduce it:
And yes, you have to wait for xInitDone to become FALSE or xError TRUE. For this purpose you can do xReset:= TRUE (at ModbusSlaveComPort) for one cycle.
This does not match written code. Written code says you have to wait xInitDone to TRUE AND xError to FALSE.
One should avoid the above IF THEN statements. A better solution could be;
Which (better) readable is something like;
Now your code is more atomic in nature and "what's in a name". Also, this function can very easily be transformed to a method of some FB.