Hi,
Today I checked the code of a collegue and I didn't agree with his code. So he wanted proof that his code was not okay and I tried to explain with a little test.
The thing I didn't like is that CheckLDWS_DONE and plaatsInArray are not initialized and in my opinion should have. These are now outputs that are written once when the looping is active.
But it is an FC, so the output area is just like the temp area not saved. In my opinion can have any value.
As a test I tried to influence the local memory by writing things to LB0, LB1, and so on in the FC where the problem FC is called. The output parameter didn't change.
When I added the line:
plaatsInArray:= k;
Then the output of the FC did change when changing local bytes:
But without the line plaatsInArray:= k; nothing on the output changes.
I tought the Output area in an FC is also like temp memory and uses the local memory, but now it looks like, if you don't write to the Output area inside the FC, the Output will not change ?
I still think this conclusion is incorrect and there should be an initialisation of outputs in an FC when nothing else is writing to it...
Anyone sees clear in this case?
Thanks in advance,
Kind regards,
C
Today I checked the code of a collegue and I didn't agree with his code. So he wanted proof that his code was not okay and I tried to explain with a little test.
The thing I didn't like is that CheckLDWS_DONE and plaatsInArray are not initialized and in my opinion should have. These are now outputs that are written once when the looping is active.
But it is an FC, so the output area is just like the temp area not saved. In my opinion can have any value.
Code:
FUNCTION FC621 : VOID
VAR_INPUT
REQ_checkLDWS:BOOL;
END_VAR
VAR_OUTPUT
plaatsInArray: INT;
CheckLDWS_DONE:BOOL;
END_VAR
VAR_TEMP
k: INT;
FOUND: BOOL;
i: INT;
j: INT;
compareString:BOOL;
END_VAR
BEGIN
compareString:=false;
IF req_checkLDWS THEN
i:=0;
FOR i:=-3 TO 5 DO
j:=0;
FOUND:= false;
REPEAT
compareString:= EQ_Strng(S1:="DB619: LDWS_LijnBuffer".positie[i].transportNR, S2:="LDWSgelezenOpslag".TRNUMMERS[j]);
IF compareString THEN
FOUND:=true;
plaatsInArray:=j;
"DB619: LDWS_LijnBuffer".positie[i].LDWS_DATA_Gelezen:=true;
END_IF;
j:=j+1;
UNTIL j >=11 OR FOUND
END_REPEAT;
END_FOR;
END_IF;
As a test I tried to influence the local memory by writing things to LB0, LB1, and so on in the FC where the problem FC is called. The output parameter didn't change.
When I added the line:
plaatsInArray:= k;
Then the output of the FC did change when changing local bytes:
But without the line plaatsInArray:= k; nothing on the output changes.
I tought the Output area in an FC is also like temp memory and uses the local memory, but now it looks like, if you don't write to the Output area inside the FC, the Output will not change ?
I still think this conclusion is incorrect and there should be an initialisation of outputs in an FC when nothing else is writing to it...
Anyone sees clear in this case?
Thanks in advance,
Kind regards,
C
Last edited: