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 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 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 value 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 value 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 value 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 value 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 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 putValue is not used. Please note that the value 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.)
Inputs
VAR_INPUT
putValue : PVOID := 0;
putPosPtr : POINTER TO T_LinkedListEntry := 0;
END_VAR
Name | Type | Description |
---|---|---|
putValue | PVOID | Value/data element (input parameter, 32/64 bit, unsigned number or pointer). |
putPosPtr | Address of the node element (input parameter). |
Inputs/outputs
VAR_IN_OUT
hList : T_HLINKEDLIST;
END_VAR
Name | Type | Description |
---|---|---|
hList | Linked List Handle. The handle must be initialized once with the function: F_CreateLinkedListHnd before being used. An associated instance of the handle variable must be created and initialized for each linked list. |
Outputs
VAR_OUTPUT
bOk : BOOL := FALSE;
getValue : PVOID := 0;
getPosPtr : POINTER TO T_LinkedListEntry := 0;
END_VAR
Name | Type | Description |
---|---|---|
bOk | BOOL | 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 searched node element could not be found, the list is empty, or has overflowed (no more free node elements). |
getValue | PVOID | Value/data element (output parameter, 32/64 bit, unsigned number or pointer). |
getPosPtr | The address of the node element (output parameter) |
Requirements
Development environment |
Target platform |
PLC libraries to be integrated (category group) |
---|---|---|
TwinCAT v3.1.0 |
PC or CX (x86, x64, ARM) |
Tc2_Utilities (System) |