CILG0001 Internal Error
Hello,
When trying to use my C# function block using User Structs, PLCNext Engineer gave the error mentioned in the title.
I have declared the Structures as in the examples given in Github, how do i get rid of this error?
Kind Regards,
Coen van der Grinten
Comments
Hi Coen,
Does anything in this previous thread help?
https://www.plcnext-community.net/en/discussions-2-offcanvas/internal-error-cilg0001.html
Perhaps check the that the same variable is connected to both the IN and OUT part of the InOut FB parameter? (I can't see this detail in the screen shot)
~ Martin.
Hi Coen,
a .NET String is not usable as in or output, you have to use IecString80 or define your own IecString with a different size as in the example on GitHub.
https://github.com/PLCnext/CSharpExamples/blob/master/PLCnext_CSharpExamples/05_IECString/FBWithString.cs
Here is a list of datatypes supported directly as in-/outputs or where you have to add an attribute. IecString80 is a predefined System.Iec61131Lib.IecStringEx with a length of 80.
https://www.plcnext.help/te/Programming/Csharp/Csharp_Supported_data_types.htm
- Marcel
Hi Marcel and Martin,
Indeed the problem was the IecString80 not being used. It now works fine.
I just now have encountered another problem.
Whenever i assign an initial value to the variable (Of the data type defined in C#), it doesn't assign this value when i start the project.
I am watching the value from an OPC Client, since later this project will have the same functionality. When assigning an initial value to the string within my defined struct, the string will remain empty after starting the project.
Right now the variables are declared as Externals, since i want to be able to call to these variables from all over the project.
Hi Coen,
If you mean that you are initialising these values inside the C# FB: I would expect any initial values of OUT parameters to stick, but not for IN or IN/OUT parameters.
If you are talking about an IN/OUT parameter, then the initial value you set in your C# FB will be over-written by the value of the variable you pass on the IN side of the FB, before that variable has a chance to be written to the OUT side of the FB.
So in that case you would need to initialise the value of the IEC variable that you pass into the FB with the required initial value.
But perhaps I am misunderstanding your scenario.
Martin.
Hi Martin,
For now i am using the C# function block to fill up a Self Defined data type (AI). So in PLCNext Engineer i create a variable of the data type AI, which is recognized from the C# program and works fine.
But when trying to initialize the value from PLCNex Engineer there seems to be no result.
I have created these variables as External values, as i want to access these across different programs and want the variables visible over OPC UA.
For now i tried giving the External Variables initial values in the PLC variables, where all external values show. I have given certain parameters of my data type values, so for example two strings 'Name' and 'Unit' have a initial string value.(Screenshot 1)
When starting the project these values don't show and the strings remain empty. It does work for any other data type, for example the initial value for a Real does show.
For now im looking at the variables over OPC UA. I can edit and read the Real variable, but the strings remain empty even when writing into the variables from the client.
~Coen
Hi Coen,
Thanks for the additional information. Now I understand.
I have reproduced the problem you described. Not only does the
IecString80
field not take the initial value specified in PLCnext Engineer, I also cannot assign any value to this variable at runtime using the debug feature of PLCnext Engineer.I will pass this information to the PLCnext Engineer team and update this thread with their feedback.
~ Martin.
Hi Martin,
Do you have any news on the topic?
Kind regards,
Coen
Hi Coen,
Sorry for the delay. This issue is currently being investigated by the PLCnext Engineer team, but I don't have any feedback yet.
They will get another reminder today.
~ Martin.
Hi Martin,
I've run into a similar problem, which might help when trying to solve the problem.
I think the issue has to do with editing strings in PLCNext Engineer vs C#.
I have created an function block to illustrate this in PLCNext Engineer.
The first screenshot illustrates the issue we already talked about. For some reason, i can't edit a string i have declared in a Data Type written in C# (The AI data type). The screenshot shows the connected string to the string in the data type in debugging, but the string is not copied.
The second screenshot shows the function block which did work: Connecting the string to a C# function block, which copies the string into the data type.
The (temporary) solution with the C# function block is not ideal, since creating a different function block for each data type costs time and recourses.
I would prefer the first option to be working.
I hope this could help with figuring out the problem.
Kind regards,
Coen
Hi Coen,
I think this is the solution to the problem you described.
Here is an example of how to declare a Structure in C#:
Note that the
ctor
method must be called for everyIecString
field, in order to initialise the string to the correct size. Then, when you create an instance of this Struct in PLCnext Engineer, assignments to this field should work OK.Hope this helps.
~ Martin.
Hi Martin,
Indeed using the Initialization in the declaration of the struct works!
Thank you very much for your help! Assignments to the string now work in PLCNext Engineer.
Kind regards,
Coen