Hi,
I using codesys to my app. Somethimes when I do update my project and try run my application the CPU load exceed 95% and program stop with exception code. What are my ways of getting out of this situation ? During operation, the CPU load is about 20%
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Looking at your code snippet, and assuming the arrays point to valid memory areas (not overlapping other variables), it seems off the top of my mind three things may be wrong :
the loop is infinite
MERGE_ARRAY is being passed arguments that cause a very long processing time or memory corruption.
Your code block is being called during every scan cycle, and the"firstScan" variable is local to the code block and being reinitialized to TRUE every time.
It should be possible to rule of some of these easily with a few tests.
Also, one quick note. You use this :
UINT_TO_BYTE(SIZEOF(dataImageLogoP1inv) -1)
If SIZEOF returns 0, then UINT_TO_BYTE will yield 255 (BYTE is unsigned), which is probably not what you want. It is hard to tell because we do not have all of the code, but I am not sure you should be using UINT_TO_BYTE, and iCount maybe should be a UINT (or something with a larger range).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not saying for sure that it is reinitialized to TRUE, but it could be if, say, the declaration of "firstScan" is located in a method rather than in the function block's body. I do not see the whole code, so it is hard to tell where your problem comes from.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I using codesys to my app. Somethimes when I do update my project and try run my application the CPU load exceed 95% and program stop with exception code. What are my ways of getting out of this situation ? During operation, the CPU load is about 20%
Hi,
You should check for an infinite / very long loop in your code that could be blocking the execution.
What kind of PLC are you using ?
This one:
https://comfiletech.com/linux-panel-pc-comfilepi/cpi-a102wr-10-2-industrial-raspberry-pi-touch-panel-pc/
Try to run the following command in a terminal :
Then you can monitor CPU usage and identify which process is eating all the CPU.
Codesys proces eating all the CPU during running my project. The problem is in the loop - please find in attachement . I do not what can be wrong...
what is the sizeof dataimagelogoP1inv equal to? if it is 255, your for loop will be an infinite loop..
Size like below :
dataImageLogoP1inv : ARRAY[0..203] OF BYTE;
SIZEOF return 204 in my example ?,so my loop should be :
it can be a problem ?
Last edit: damian177 2022-07-01
How is possible that my first solution worked time to time ?
Looking at your code snippet, and assuming the arrays point to valid memory areas (not overlapping other variables), it seems off the top of my mind three things may be wrong :
It should be possible to rule of some of these easily with a few tests.
Also, one quick note. You use this :
UINT_TO_BYTE(SIZEOF(dataImageLogoP1inv) -1)
If SIZEOF returns 0, then UINT_TO_BYTE will yield 255 (BYTE is unsigned), which is probably not what you want. It is hard to tell because we do not have all of the code, but I am not sure you should be using UINT_TO_BYTE, and iCount maybe should be a UINT (or something with a larger range).
In my project in one of program block it was declared this variable : VAR firstScan:BOOL:=TRUE; END_VAR Is not a global variable.
I don't understand why variable "fisrtScan" would be reinitialize to TRUE every time ?
I am not saying for sure that it is reinitialized to TRUE, but it could be if, say, the declaration of "firstScan" is located in a method rather than in the function block's body. I do not see the whole code, so it is hard to tell where your problem comes from.
Problem probably was in UINT_TO_BYTE(SIZEOF(dataImageLogoP1inv) -1) because oryginally I use :
UINT_TO_BYTE(SIZEOF(dataImageLogoP1inv)).
Thanks for help.