Hi everyone and thanks in advance for the replies. I need to rewrite an entire program in Codesys that was written in another program (let's just say that I have to migrate some Data Blocks).
So I began to copy the program by the variables so I would have everything in place when I would later copy the code itself.
I wrote down the variables that were in Data Blocks as variables in GVLs, and there was one thing I had to change. In the other program you can nest structures in data block/other structures, and in Codesys you can't do it. So i created an auxiliary folder and declared the STRUCTs I was going to use in the GVLs.
Everything worked fine, the problem rose when I had to initialize some variables in the GVLs. In the GVL declaration I just wrote down the initial values of the STRUCT following the online helper format, compiled it and nothing went wrong.
Now if I call a variable in a FB/PRG POU that has been initializated in the GVL it gives me this error: "No Matching "FB_Init" method found for instantiation of STRUCT..."
I didn't found a useful solution for this problem and I don't really know what to do with the METHOD call. I hope that you can comprehend my explanation and if that's not the case let me know, I will be more than happy to try to explain it better.
"In the other program you can nest structures in data block/other structures, and in Codesys you can't do it."
Codesys does support nested STRUCTs as shown in the example below. Not sure where you went wrong but there is one quirk to be aware of. Codesys (sometimes or always?) doesn't compile and include entities in the build. Consequently, at least one variable defined in your GVL needs to be accessed in an executing program in order to view the GVL while Online.
"In the other program you can nest structures in data block/other structures, and in Codesys you can't do it."
To nuance, the IEC61131-3 norm (which CODESYS follows really well) does not allow type definition and instancing of DUT data types in a single go. If you wish to read up on this I can recommend this book: https://link.springer.com/chapter/10.1007%2F978-3-642-12015-2_8
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone and thanks in advance for the replies. I need to rewrite an entire program in Codesys that was written in another program (let's just say that I have to migrate some Data Blocks).
So I began to copy the program by the variables so I would have everything in place when I would later copy the code itself.
I wrote down the variables that were in Data Blocks as variables in GVLs, and there was one thing I had to change. In the other program you can nest structures in data block/other structures, and in Codesys you can't do it. So i created an auxiliary folder and declared the STRUCTs I was going to use in the GVLs.
Everything worked fine, the problem rose when I had to initialize some variables in the GVLs. In the GVL declaration I just wrote down the initial values of the STRUCT following the online helper format, compiled it and nothing went wrong.
Now if I call a variable in a FB/PRG POU that has been initializated in the GVL it gives me this error: "No Matching "FB_Init" method found for instantiation of STRUCT..."
I didn't found a useful solution for this problem and I don't really know what to do with the METHOD call. I hope that you can comprehend my explanation and if that's not the case let me know, I will be more than happy to try to explain it better.
Line 4 of your GVL, where you have
~~~ CL501 : STRUCT_CL501_HMI ( ~~~
I think should read
~~~ CL501 : STRUCT_CL501_HMI := ( ~~~
Thanks! Yep, that solved the first problem!
Now I got another one, if you could solve it it would be great.
In the DUT declaration I got some Arrays, and in the GVL I don't know how to initiate it, it gives me an error.
Found the solution! I'll post it.
Thanks again.
Ryan
"In the other program you can nest structures in data block/other structures, and in Codesys you can't do it."
Codesys does support nested STRUCTs as shown in the example below. Not sure where you went wrong but there is one quirk to be aware of. Codesys (sometimes or always?) doesn't compile and include entities in the build. Consequently, at least one variable defined in your GVL needs to be accessed in an executing program in order to view the GVL while Online.
Create sub STRUCT
Create main STRUCT
Declare and Initialize in GVLVAR_GLOBAL
Access any variable declared in GVL from a program attached to a task, otherwise compiler doesn't bother to compile it.
Compile and go Online to see GVL data
Last edit: rickj 2021-03-27
"In the other program you can nest structures in data block/other structures, and in Codesys you can't do it."
To nuance, the IEC61131-3 norm (which CODESYS follows really well) does not allow type definition and instancing of DUT data types in a single go. If you wish to read up on this I can recommend this book: https://link.springer.com/chapter/10.1007%2F978-3-642-12015-2_8