This Page
Introduction | Usage | Download | Requirements | Acknowledgements
Linked lists are suitable as a flexible and modular way to implement simple and powerful code with ease.
This library will allow you to leverage the simplicity, power and flexibility of linked lists.
A linked list is a data structure that represents a sequence of nodes (Elements). This library implements a so called "double linked list", which simply means that the list gives each Element pointers to both the next Element and the previous Element. Unlike an array, a linked list does not provide constant time access to a particular “index” within the list. This means that if you’d like to find the K-th element in the list, you will need to iterate through K elements. The benefit of a linked list is that you can add and remove Elements from the list during runtime so this means you can very easily extend your code with new FB's without extra coding since interaction with lists is always done in FOR loops. This means that by design your code doesn't need to be rewritten as demonstrated in the example below 👇
TIP
Any new FB that will be a part of the List should preferably use encapsulation and composition to implement "FB_ExtendedElement".
This way FB_ExtendElement will act as a baseclass for your Element without beings explicitly itself of type "FB_ELEMENT".
If you use encapsulation and composition it will provide you with much more flexibility but as a penalty it will cost you also more programming since you have to
encapsulate/composite all methods and properties. In this demonstration we use EXTENSION
FUNCTION_BLOCK FB_Extendedlement EXTENDS LinkedList.FB_Element
VAR
_uiCount : UINT := 0;
END_VAR
// Body
Super^();
METHOD ReturnInstance : POINTER TO FB_ExtendedElement
// Body
ReturnInstance := THIS;
METHOD Count : UINT;
// Body
_uiCount := uiCount + 1;
VAR
Init : Bool := TRUE;
List : LinkedList.List;
ExtendedEl1: FB_ExtendedElement;
ExtendedEl2: FB_ExtendedElement;
pEl : POINTER TO FB_ExtendedElement;
ElementCount : UINT;
END_VAR
// Body
IF Init THEN
List.AddElement( ExtendedEl1 );
List.AddElement( ExtendedEl2 );
END_IF
// FOR LOOP TO DEMONSTRATE PROPER USAGE
You should never interact with list elements directly! Always interact with Elements through the central List!
By downloading and using our software you abide by the MIT License
Download cođź”—e - Linked List v1.0.0.0 library
System requirements and restrictions | Info |
---|---|
Programming System | CODESYS Development System Version 3.5.9.0 or higher |
Runtime System | CODESYS Control Version 3.5.9.0 or higher |
Licensing | - |
Required Accessories | - |
https://www.linkedin.com/in/hahermsen