FB_LinkedListCtrl
The function block FB_LinkedListCtrl can be used to implement a linked list in the PLC project. A double-linked list is created. A linked list allows values (known as nodes) to be stored. It is possible to iterate the list from the back to the front or the other way. Nodes can quickly be added or deleted.
It is not possible to change the maximum number of nodes at runtime; it must be specified before compiling. An array of type T_LinkedListEntry is used as a "node pool". Adding/removing/finding of nodes is controlled through action calls. The function block features the following tasks:
- A_AddHeadValue (adds a new node with the value putValue to the top of the list. The same value can be added more than once. If successful, getPosPtr returns the address while getValue returns the value of the new node.)
- A_AddTailValue (adds a new node with the value putValue to the end of the list. The same value can be added more than once. If successful, getPosPtr returns the address while getValue returns the value of the new node.)
- A_FindNext (searches for the next node (relative to putPosPtr) whose value is the same as putValue. If successful, getPosPtr returns the address while getValue returns the value of the node.)
- A_FindPrev (searches for the previous node (relative to putPosPtr) whose value is the same as putValue. If successful, getPosPtr returns the address while getValue returns the value of the node.)
- A_GetNext (navigates to the next node (relative to putPosPtr). The address putPosPtr must point the previous node! The value of putValue is not used.)
- A_GetPrev (navigates to the previous node (relative to putPosPtr) in the opposite direction to A_GetNext. The address putPosPtr must point the previous node! The value of putValue is not used.)
- A_GetHead (reads the starting node. If successful, getPosPtr returns the address of the node while getValue returns the associated value. The values of putValue and putPosPtr are not used.)
- A_GetTail (reads the final node. If successful, getPosPtr returns the address of the node while getValue returns the associated value. The values of putValue and putPosPtr are not used.)
- A_RemoveHeadValue (removes a node from the top of the list. If successful, getPosPtr returns the address while getValue returns the value of the node. The values of putValue and putPosPtr are not used.)
- A_RemoveTailValue (removes a node from the end of the list. If successful, getPosPtr returns the address while getValue returns the value of the node. The values of putValue and putPosPtr are not used.)
- A_RemoveValueAtPosPtr (searches for and removes a node with address putPosPtr. If successful, getPosPtr returns the address while getValue returns the value of the node. The value of putValue is not used.)
- A_GetIndexAtPosPtr (returns the array index (from the "node pool") of the node at address putPosPtr. When successful, getValue returns the null-based array index. The value of putValue is not used. Please note that the value of getValue is a node index, not the value of the node! )
- A_SetValueAtPosPtr (updates/sets the value of the node with putValue at the address putPosPtr. If successful, getPosPtr returns the address while getValue returns the value of the node.)
- A_Reset (deletes all list elements and resets the list.)
VAR_IN_OUT
VAR_IN_OUT
hList : T_HLINKEDLIST;
END_VAR
hList: Linked List Handle. The handle must be initialised once with the function F_CreateLinkedListHnd before being used. An associated instance of the handle variable must be created and initialised for each linked list
VAR_INPUT
VAR_INPUT
putValue : DWORD := 0;
putPosPtr : POINTER TO T_LinkedListEntry := 0;
END_VAR
putValue: Value/data element (output parameter, 32 bits; pointers are also possible).
putPosPtr: The address of the node element (input parameter).
VAR_OUTPUT
VAR_OUTPUT
bOk : BOOL := FALSE;
getValue : DWORD := 0;
getPosPtr : POINTER TO T_LinkedListEntry := 0;
END_VAR
bOk: Result of the last action called. Returns TRUE if a new node element could be added, removed, or found in the list. FALSE is returned if the node element that was searched for could not be found, the list is empty, or has overflowed (no more free node elements).
getValue: Value/data element (output parameter, 32 bits; pointers are also possible).
getPosPtr: The address of the node element (output parameter).
Requirements
Development environment | Target system type | PLC libraries to be linked |
---|---|---|
TwinCAT v2.10.0 Build >= 1339 | PC or CX (x86, ARM) | TcUtilities.Lib |