I made a FB which has as input several string variables. Inside the FB I declare a variable consisting of a struct array of said inputs (this struct is made just of strings). These are later formated in a specific way and saved in a .txt file.
My problem is when I go online, even I see the desired strings on the input variables, on the array theyΒ΄re all empty and my text file comes out as just comas and line breaks (which I write on my FB). It only works if I manually write the strings on the array.
The index shows properly on my test file, as I defined them there manually. Any suggestions? Is it not possible to define inputs and right away call them in a defined variable?
Last edit: epinikion 2020-04-21
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The Daten array gets initialized before your input variables are set. You need somewhere to update the Daten array "data" to match the input variables that are defined in your function block call or initialization. If you want to set them on intialization you might want to look into setting up a fb_init method for that function block.
More on fb_init can be found here: https://help.codesys.com/webapp/_cds_method_fb_init_fb_reinit;product=codesys;version=3.5.15.0#interface-of-method-fb-init
π
2
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for your answer, I will take a look. Is it possible to define the variable in the program instead of in the variable definitions in order to spare me the fb_init? I think not, right?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can try using VAR_TEMP as that will assign the values every time your function block is called. So as long as your input variables have been set, Daten will update on your next call to your FB. You won't be able to see those values during runtime as once the function block has finished it's call it will destroy the variable. Otherwise I'm not sure what your end goal is it is harder to make suggestions.
Hi,
I made a FB which has as input several string variables. Inside the FB I declare a variable consisting of a struct array of said inputs (this struct is made just of strings). These are later formated in a specific way and saved in a .txt file.
My problem is when I go online, even I see the desired strings on the input variables, on the array theyΒ΄re all empty and my text file comes out as just comas and line breaks (which I write on my FB). It only works if I manually write the strings on the array.
HereΒ΄s the DUT, just some strings:
And here a snippet of the variables on my FB:
The index shows properly on my test file, as I defined them there manually. Any suggestions? Is it not possible to define inputs and right away call them in a defined variable?
Last edit: epinikion 2020-04-21
The Daten array gets initialized before your input variables are set. You need somewhere to update the Daten array "data" to match the input variables that are defined in your function block call or initialization. If you want to set them on intialization you might want to look into setting up a fb_init method for that function block.
More on fb_init can be found here: https://help.codesys.com/webapp/_cds_method_fb_init_fb_reinit;product=codesys;version=3.5.15.0#interface-of-method-fb-init
Thank you for your answer, I will take a look. Is it possible to define the variable in the program instead of in the variable definitions in order to spare me the fb_init? I think not, right?
You can try using VAR_TEMP as that will assign the values every time your function block is called. So as long as your input variables have been set, Daten will update on your next call to your FB. You won't be able to see those values during runtime as once the function block has finished it's call it will destroy the variable. Otherwise I'm not sure what your end goal is it is harder to make suggestions.
Great, that works too! Many thanks.