|
|
Topic: P338 |
User Defined Instructions (UDI) for Productivity Series |
|
Icon / Button =
UDIs function similarly to function blocks in other programming environments, allowing users to define custom instructions tailored to their specific automation needs. These instructions help streamline programming by encapsulating commonly used logic into reusable, self-contained modules.
Custom Instruction Creation: Users can develop new instructions that encapsulate frequently used logic, reducing programming redundancy and improving code maintainability.
Standardized Interface: Each UDI provides a consistent input/output structure, ensuring uniformity when applied in multiple contexts.
Integrated Documentation: Users can include detailed descriptions and usage guidelines within the UDI, enhancing clarity and easing future maintenance.
UDIs are designed for:
Encapsulating Repetitive Logic: Ideal for control sequences, mathematical operations, or communication protocols that are frequently used across different projects.
Device Control Functions: Can be employed to standardize control logic for specific hardware devices.
However, UDIs are not intended to be a high-level hierarchical design tool. For structuring application logic at an area or unit level, tasks within the Productivity Suite project should be used instead.
UDIs offer a modular programming approach, making them easily shareable:
Across Multiple Projects: Once created, a UDI can be exported and then imported to be reused in different applications without reimplementation.
Between Users: UDIs can be shared within teams or across organizations, promoting consistency and efficiency in PLC programming.
By leveraging UDIs, users can significantly improve code efficiency, reduce errors, and enhance project scalability.
|
Term |
Definition |
|
Assignment Required |
Assignment is the process of passing outside values to and from parameters, so different UDI instances may operate on different sets of values. When a UDI parameter is marked as "Assignment Required", it means that the parameter must be explicitly assigned an external tag or value before the UDI compiles. This helps to ensure that the UDI operates with valid data and to prevent unintended behavior due to uninitialized or default values. |
|
Local Parameter |
A Local parameter is a variable that is defined within the UDI definition and only accessed by the UDI function itself. When adding or defining parameters within the UDI, the Scope of the parameter defaults to Local, e.g. a local parameter does not have an In, Out, or InOut assignment. Local parameters are typically used for temporary calculations, internal state storage, or assisting in function execution. By default, Local Parameters are reset at each execution but can be assigned a Default Input Value to maintain some persistence across multiple executions of the UDI. |
|
InOut Parameter |
An InOut parameter is a variable that is defined within the UDI definition but can be accessed externally, meaning that modifications made to it inside the Function Block affect the original variable outside the Function Block. Data can serve as both input data and output data during the execution of the UDI. Because InOut parameters are passed by reference, they are typically used for bidirectional data exchange, updating values dynamically, or modifying large data structures such as arrays without duplicating memory. InOut parameters are passed by reference and can be changed by sources external to the function during the execution of the UDI. |
|
Input Parameter |
An Input Parameter is a variable that is defined within the UDI definition and passed into the UDI by value, meaning it passes a copy of data to the UDI however, modifications inside the UDI do not affect the original variable. Data is passed by value into the UDI for processing. During the execution of the UDI, the value cannot be changed by sources external to the function. Because Input parameters are passed by value, they are typically used for passing in configuration values, sensor readings, set points, or any data that should remain unchanged during execution. |
|
Output Parameter |
An Output parameter is a variable that is assigned a value inside the UDI and made available for use outside the UDI, upon Data resulting from its execution of the UDI. Because Output parameters are passed by value, they are typically used for returning calculated values, control signals, results, or status indicators for use in another task after the UDI executes. The data returned from the UDI is passed by value and cannot be changed by sources external to the function during the execution of the UDI. |
|
Passed by Reference |
When an argument is passed to a parameter by reference, the logic directly reads or writes the value that the tag uses in controller memory. Alternate: When parameters are passed by reference, the UDI receives a reference (or pointer) to the actual variable rather than a copy of its value. This means that any modifications made to the parameter inside the UDI will directly affect the original variable, allowing for efficient memory usage and real-time data updates |
|
Passed by Value |
When an argument is passed to a parameter by value, the value is copied in to or out of the parameter when the User Defined Instruction executes. Alternate: When parameters are passed by value, the UDI receives a copy of the variable's value. This means that any modifications made inside the function block do not affect the original variable, ensuring data integrity but potentially using more memory and processing time. |
|
Visible |
When a parameter is marked as "Visible", it means that the parameter can be seen on the UDI Instruction widget in a Task ladder editor. This visibility on the instruction widget allows users to monitor the parameters value in the programming environment making it useful for debugging and verification. |
|
Nesting |
Allows a user to build complex logic by breaking it down into smaller, manageable, and reusable UDI’s. However, it's important to avoid excessive nesting, which can make the code difficult to understand and maintain. |