Hi
I recently modified a project, but I found that when I changed the trig array value and the for loop did not change, it caused an error in the data:
exp:
PROGRAMPLC_PRGVAR
  ft_Ctrl: ARRAY [0..2] OFF_TRIG;
  rt_Ctrl: R_TRIG;
 Â
  index: INT;
  iState: INT;
  xCmd: BOOL;
  xAutoMode: BOOL;
  xDone: BOOL;END_VAR--------------------------------------------FORindex :=0TO3DO
  IFft_Ctrl[index].QTHEN
    iState:=90;
  END_IFEND_FORrt_ctrl(CLK:=xCmd);xAutoModeS=rt_Ctrl.Q;CASEiStateOF
  0:
    IFxAutoModeTHEN
      iState:=10;
    END_IF
  10:
    iState:=90;
    xAutoMode:=FALSE;
    xDone:=TRUE;
  90:
    iState:=0;
    xAutoMode:=FALSE;END_CASE
Notice that in the definition I give f_trig [0..2] and call f_trig [3] in the for loop without error。
In this program, I hope that when xCmd is the rising edge, iState followed by 10,90 and then back to 0.
But in fact, I use a single loop to monitor, the first loop iState set to 10. in the second loop, ft_Ctrl [3]. Q actually call the value of rt_Ctrl.Q and iState set to 90,and then back to 0.
This is very hard to find, because the actual project is large, I forgot to change the for statement after changing the definition of the variable, resulting in the emergence of this problem. I tested this on both somachine and twincat. So if this is the case, can the alarm be exceeded?
sorry for google translate..and thanks for attention
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
PROGRAMPLC_PRGVAR
  ft_Ctrl: ARRAY[0..1] OFF_TRIG;
  rt_Ctrl: R_TRIG;
 Â
  index: INT;
  xCmd: BOOL;
  xDone:BOOL;END_VAR--------------------------FORindex :=0TO3DO
  IFft_Ctrl[index].QTHEN
    xDone:=TRUE;
  END_IFEND_FORrt_ctrl(CLK:=xCmd);
At this program,when xCmd R_TRIG,xDone will be true.
I think it may be coherent after compilation so the address is continuously pointed, but it is somewhat counterproductive..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
So your question is basically : How to find in huge projects these kind of application errors?
You need to add the implcit check function: check bounds.
Then set brakepoints for upper and lower - then you will find the code in your application where you write below the array...
Note: later you need to remove this implicit functions again... ( just for the application development they should be in the application due Performance issues)
BR
Edwin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think for some time, if you write the program should be able to avoid this problem:
PROGRAMPLC_PRGVAR
  ft_Ctrl: ARRAY[0..iMax_ft_Number] OFF_TRIG;
  rt_Ctrl: R_TRIG;
  index: INT;
  xCmd: BOOL;
  xDone:BOOL;END_VARVARCONSTANT
  iMax_ft_Number:INT:=2;END_VAR---------------FORindex :=0TO5DO
  IFft_Ctrl[LIMIT(0,index,iMax_ft_Number)].QTHEN
    xDone:=TRUE;
  END_IFEND_FORrt_ctrl(CLK:=xCmd);
Uh, but writing like this adds to the complexity of the program. . I think I need to be cautious when I change the definition of an array.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-02-01
Originally created by: rickj
Or you could just do this ...
FORindex :=0TOiMax_ft_NumberDO
  IFft_Ctrl[index].QTHEN
   xDone:=TRUE;
  END_IFEND_FOR
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For me is not a bad solution to wrapp an array with an FB with get, add, set ... Methods
Enviat des del meu Aquaris M5.5 usant Tapatalk
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2018-02-05
Originally created by: rickj
Josep M. Rams hat geschrieben:
Hi.
For me is not a bad solution to wrapp an array with an FB with get, add, set ... Methods
Enviat des del meu Aquaris M5.5 usant Tapatalk
Agree Joseph.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I recently modified a project, but I found that when I changed the trig array value and the for loop did not change, it caused an error in the data:
exp:
Notice that in the definition I give f_trig [0..2] and call f_trig [3] in the for loop without error。
In this program, I hope that when xCmd is the rising edge, iState followed by 10,90 and then back to 0.
But in fact, I use a single loop to monitor, the first loop iState set to 10. in the second loop, ft_Ctrl [3]. Q actually call the value of rt_Ctrl.Q and iState set to 90,and then back to 0.
This is very hard to find, because the actual project is large, I forgot to change the for statement after changing the definition of the variable, resulting in the emergence of this problem. I tested this on both somachine and twincat. So if this is the case, can the alarm be exceeded?
sorry for google translate..and thanks for attention
Make it simpler:
At this program,when xCmd R_TRIG,xDone will be true.
I think it may be coherent after compilation so the address is continuously pointed, but it is somewhat counterproductive..
Hi,
So your question is basically :
How to find in huge projects these kind of application errors?
You need to add the implcit check function: check bounds.
Then set brakepoints for upper and lower - then you will find the code in your application where you write below the array...
Note: later you need to remove this implicit functions again... ( just for the application development they should be in the application due Performance issues)
BR
Edwin
Yes, this is perfect
Thank you very much
Hi,
every CODESYS Version has this checkfunctions build in!
BR
Edwin
I think for some time, if you write the program should be able to avoid this problem:
Uh, but writing like this adds to the complexity of the program. . I think I need to be cautious when I change the definition of an array.
Originally created by: rickj
Or you could just do this ...
Hi.
For me is not a bad solution to wrapp an array with an FB with get, add, set ... Methods
Enviat des del meu Aquaris M5.5 usant Tapatalk
Originally created by: rickj
Agree Joseph.