What are Structs?
Eduardo Margulis
Nov-7th, 2017 13:06

A struct is a complex data type declaration that defines a physically grouped list of variables (of different data types) to be placed under one name in a block of memory, allowing the different variables to be accessed via a single declared name which returns the same address.
In Unilogic there are four types of Structs:

  • System Data Tag Structs: System Data Tags service the UniStream system. These tags are organized into Structs.
  • Automatically-created Structs: These are created by the software when you add elements to your application including:

– Hardware Structs that serve hardware elements such as I/O and COM modules and modems
– Communication structs such as MODBUS and CANopen.
– Function Structs, such as PID.


  • Timer Structs: These are created when you add a Timer data tag.


  • User-defined Struct: You define these and reuse them in your program. Each instance may contain different power up values.

To create a User-defined struct please follow the next steps:

  1. Click the Struct tab on the bottom of the Operand Window.

  2. Either click the Add Struct icon, or right-click and select Add Struct.

  3. Name the Struct and click Save.

4. Either click the Add icon or right-click the window to add members to the Struct. You can add single operands or arrays)


To use the struct on your project, you need to declare an instance.

You can declare an instance of a Struct either as a global tag, or a local tag.

  1. Right-click the Global Tag window, or the window of a function. Name the instance, then scroll down until you see the name of the desired Struct and select it.


  2. Now that the Struct is declared, you can assign Alias names to the members.


  3. You can also drill down and assign Alias names to individual members within arrays that you have included in the Struct.


Now that the Struct has been declared, it can be used in your program just like any other tag.


Was this article helpful?
2 out of 3 found this helpful
 
Eduardo Margulis Dec-20th, 2017 9:04

There is no specific limitation on number of members a struct may have. You may have several hundreds. You just need to take into account the overall memory for tags that is 2 MB.

YS
YTAutomation Singapore Support Dec-20th, 2017 6:15

Is there any limitation for a struct? May I know how many members can I have in one struct?