Digital Output
A simple Digital Output component can be created using the SOLID principles outlined in the SOLID Overview document. This example will demonstrate how to create a reusable Digital Output component that can be easily integrated into various projects.
Step 1: Define the Interface
Create an interface I_DigitalOutput that defines the properties for the Digital Output component.
1 2 3 | |
Step 2: Create the Digital Output Component
Create a function block DigitalOutput that implements the I_DigitalOutput interface.
1 2 3 4 5 6 7 8 9 10 11 | |
Step 3: Add the FB_Init Method to Initialize the Output Reference
The FB_Init method initializes the reference to the actual digital output variable. This allows the dependency output hardware variable to be injected, adhering to the Dependency Inversion Principle (DIP).
1 2 3 4 5 6 7 8 9 10 | |
Step 4: Using the Digital Output Component
To use the DigitalOutput component, create an instance of it in your main program or another function block. Initialize it with the actual digital output variable and control it through the On property.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
Conclusion
This example demonstrates how to create a simple Digital Output component using the SOLID principles. The component is reusable, maintainable, and adheres to best practices in software design. You can easily integrate this component into various projects by injecting the appropriate digital output variable.