Digital Input
A simple Digital Input component can be created using the SOLID principles outlined in the SOLID Overview document. This example will demonstrate how to create a reusable Digital Input component that can be easily integrated into various projects.
Step 1: Define the Interface
Create an interface I_DigitalInput that defines the properties for the Digital Input component.
1 2 3 | |
Step 2: Create the Digital Input Component
Create a function block DigitalInput that implements the I_DigitalInput interface.
1 2 3 4 5 6 7 8 9 10 | |
Step 3: Add the FB_Init Method to Initialize the Input Reference
The FB_Init method initializes the reference to the actual digital input variable. This allows the
dependency input 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 Input Component
To use the DigitalInput component, create an instance of it in your main program or another function block. Initialize it with the actual digital input variable and read its state through the IsActive property.
1 2 3 4 5 6 7 8 9 10 | |
Conclusion
The DigitalInput component can now be reused across different projects, adhering to the SOLID principles, particularly the Dependency Inversion Principle (DIP). By depending on the I_DigitalInput interface, the component remains flexible and easily testable.