I understand Codesys forces you to use a constant to define the Array length and I cannot write to a constant. So I am hoping for a workaround. The idea is to make the FB use the correct amount of memory for the array on instantiation.
It would make sense that since the function block is instantiated with FB_Init I should be able to define the length of the array with the FB_Init.
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,is there a method to pass a number through FB_Init and use it to define the length of the array which is internal to the FB?
Example
Where ArrLen is used in the FB as shown, to define array length?
I understand Codesys forces you to use a constant to define the Array length and I cannot write to a constant. So I am hoping for a workaround. The idea is to make the FB use the correct amount of memory for the array on instantiation.
It would make sense that since the function block is instantiated with FB_Init I should be able to define the length of the array with the FB_Init.
Thanks.
FB_Init happens when you boot up the application.
ARRAY [0..ArrLen] OF INT; happens at compile time.
What you are looking at is allocating (and hopefully deallocating memory during runtime).
This is described in "B.)"here:
https://help.codesys.com/webapp/fb_factory;product=LibDevSummary;version=3.5.15.0
Thanks for clarifying. I did not realize they ran at different times.
I will look into the FB_Factory and see what I can do. Thank you.