Setting Initial Values in UDT Instances
Hello,
I'm programming an AC 800M controller with Compact Control Builder and have a number of function blocks for different components, as well as UDTs that are passed as parameters into those function blocks. For example, I may have a pump function block that I pass in a UDT containing the pump name and other data. Some variables in the UDTs need to be instantiated with different values. For example, pump name is different for each function block instance. I can set an initial value in the UDT definition for ALL UDT instances, but I have not found a way to set different initial values for UDT variables for each UDT instance in any variable table, other than adding them as code. Is there a simpler way to give UDT instance variables initial/constant values?
Thanks,
I'm programming an AC 800M controller with Compact Control Builder and have a number of function blocks for different components, as well as UDTs that are passed as parameters into those function blocks. For example, I may have a pump function block that I pass in a UDT containing the pump name and other data. Some variables in the UDTs need to be instantiated with different values. For example, pump name is different for each function block instance. I can set an initial value in the UDT definition for ALL UDT instances, but I have not found a way to set different initial values for UDT variables for each UDT instance in any variable table, other than adding them as code. Is there a simpler way to give UDT instance variables initial/constant values?
Thanks,
Answers
Hello,
To answer your question short, no you cannot set the initial values of instances. There are some options however, requiring some code.
You can for example create a base type like
MyPumpParametersType with some elements
Name
StartupTime
MaxTemperature
And then a specific type for each pump like for pump01 a Pump01Type with
Name Pump01
StartupTime T#30s
MaxTemperature 60
Create a function block accepting an anytype, put in an instance of Pump01Type and use GetStructComponent to get the 3 values out of your input and set them to the output of MyPumpParametersType. You then connect this type to your Pump function block.
Of course you have to make sure that each specific type has the same order and layout as the base type.
As mentioned before this is not the only or best way, just an example to get you thinking in the right direction.
To answer your question short, no you cannot set the initial values of instances. There are some options however, requiring some code.
You can for example create a base type like
MyPumpParametersType with some elements
Name
StartupTime
MaxTemperature
And then a specific type for each pump like for pump01 a Pump01Type with
Name Pump01
StartupTime T#30s
MaxTemperature 60
Create a function block accepting an anytype, put in an instance of Pump01Type and use GetStructComponent to get the 3 values out of your input and set them to the output of MyPumpParametersType. You then connect this type to your Pump function block.
Of course you have to make sure that each specific type has the same order and layout as the base type.
As mentioned before this is not the only or best way, just an example to get you thinking in the right direction.
Add new comment