Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fisothemes committed May 18, 2022
1 parent c75b291 commit 2202cca
Show file tree
Hide file tree
Showing 44 changed files with 2,065 additions and 5 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Goodwill Mzumala

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# TwinCAT Dynamic Collections

A library for handling collections of data dynamically.
Create python like lists (a list containg multiple data type that can grow or shrink at runtime), true Queue and Stack data structures. Examples are in project.

# Function Blocks

* 👍 **FB_Collections** - Abstract class/Function Block that all collections inherit, handles the passing internal errors to the outside world. Implements I_Collections.
* 👍 **FB_List** - Python like List. Can store and operate lists of any size and type at runtime. Multi-type lists are supported. Implements I_List.
* 👍 **FB_Queue** - Standard Queue Data Struture. Can perform queue operations on any class/Function Block that implements I_List. Implements I_Queue.
* 👍 **FB_Stack** - Standard Stack Data Struture. Can perform stack operations on any class/Function Block that implements I_List. Implements I_Stack.

# Simple Example

This example demostrates how a STRING, DINT and STRUCT can be stored on the queue data structure.

**Declarations:**
```Pascal
(* implements I_List, used to store data. *)
fbList : FB_LIST;
(* implements I_Queue, will perform queue operations on any class that implements I_List *)
fbQueue : FB_QUEUE;
sData : STRING; // variable that holds string data
nData : DINT; // variable that holds 32-bit int data
stData : ST_DATA := (bMammals := TRUE, sDescription := 'Twin cats'); // variable that holds data in the form of a struct
(* variable to store returned data same as, "bVar := TRUE"*)
sRTNData : STRING;
nRTNData : DINT;
stRTNData : ST_DATA;
nCount1, nCount2 : DINT; // variable will hold the number of items in the queue
```
**Implimentation:**
```Pascal
fbQueue(ipList := fbList); // tell FB_Queue which list implementation you want to operate on. Can swap lists at runtime.
sData := 'Cats';
fbQueue.Enqueue(sData); // Enqueues a copy of string data to fbList
nData := 1234567;
fbQueue.Enqueue(nData) // Enqueues a copy of 32-bit int data
.Enqueue_At_Front(stData); // Enqueues stData at the front of the queue
nCount1 := fbQueue._Count; // should return 3
fbQueue.Dequeue(stRTNData) // removes data at the front of the queue and stores it's contents on stRTNData
.Reverse() // reverse the queue
.Peek(sRTNData, 1) // returns data at location at stores it on sRTNData without removing it.
.Peek(nRTNData, 0);
nCount2 := fbQueue._Count; // should return 2
```
- - -
**TcXaeShell Screencap:**

![Front Panel](./assets/images/Simple%20Example%20TcXaeShell%20Screencap.JPG)

![Front Panel](./assets/images/Simple%20Example%20TcXaeShell%20Screencap%202.JPG)
- - -




4 changes: 0 additions & 4 deletions TcCollections/TcCollections.tsproj

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added builds/0.1.0.0/TcDynCollections.library
Binary file not shown.
18 changes: 17 additions & 1 deletion TcCollections.sln → src/TwinCat Dynamic Collections.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# TcXaeShell Solution File, Format Version 11.00
VisualStudioVersion = 15.0.28010.2050
MinimumVisualStudioVersion = 10.0.40219.1
Project("{B1E792BE-AA5F-4E3C-8C82-674BF9C0715B}") = "TcCollections", "TcCollections\TcCollections.tsproj", "{AA44BF3E-9AE7-4A37-9C2A-219EE971CF2F}"
Project("{B1E792BE-AA5F-4E3C-8C82-674BF9C0715B}") = "TwinCat Dynamic Collections", "TwinCat Dynamic Collections\TwinCat Dynamic Collections.tsproj", "{AA44BF3E-9AE7-4A37-9C2A-219EE971CF2F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -33,6 +33,22 @@ Global
{AA44BF3E-9AE7-4A37-9C2A-219EE971CF2F}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64)
{AA44BF3E-9AE7-4A37-9C2A-219EE971CF2F}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86)
{AA44BF3E-9AE7-4A37-9C2A-219EE971CF2F}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86)
{1C1CF391-AD49-4301-B41D-3891FAA7DC78}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86)
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.4">
<Itf Name="I_Collections" Id="{b40166ad-f1ab-4d22-a4d0-84895557404c}">
<Declaration><![CDATA[INTERFACE I_Collections
]]></Declaration>
<Property Name="_Count" Id="{23a45eae-6557-42b2-bda5-f817dab9f3d2}">
<Declaration><![CDATA[(* Number of elements in collection*)
PROPERTY _Count : DINT]]></Declaration>
<Get Name="Get" Id="{d366bad5-7796-4b69-a3d6-af0e937b23f0}">
<Declaration><![CDATA[]]></Declaration>
</Get>
</Property>
<Property Name="_Error_Status" Id="{be04b552-3c2b-4c54-a9e7-651f0a9a158f}">
<Declaration><![CDATA[(* Gets collection's error status *)
PROPERTY _Error_Status : ST_ERROR]]></Declaration>
<Get Name="Get" Id="{eb2c4aed-dd87-4022-92be-3d474ee64a5e}">
<Declaration><![CDATA[]]></Declaration>
</Get>
</Property>
<Property Name="_Is_Empty" Id="{c45feb15-34b8-4188-816f-e2c0fc511e8c}">
<Declaration><![CDATA[(* Checks if collection is empty.*)
PROPERTY _Is_Empty : BOOL]]></Declaration>
<Get Name="Get" Id="{66385950-96ba-40cb-ae27-099814d052ba}">
<Declaration><![CDATA[]]></Declaration>
</Get>
</Property>
<Method Name="Clear" Id="{3f8ee2bf-80ec-4210-a30e-6f79f6fe68c0}">
<Declaration><![CDATA[(* Empties/Clears/Deletes every element on the collection*)
METHOD Clear
]]></Declaration>
</Method>
</Itf>
</TcPlcObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.4">
<Itf Name="I_List" Id="{aa13a36e-deb0-4cc7-ad47-2909bad43043}">
<Declaration><![CDATA[INTERFACE I_List EXTENDS I_Collections
]]></Declaration>
<Method Name="Add_Front" Id="{8b2ea375-a0ff-44b7-8f8c-c4f094b6f324}">
<Declaration><![CDATA[// Creates/Adds an node to the front of the list
METHOD Add_Front : I_List
VAR_INPUT
Value : ANY; // Value to store in node
END_VAR
]]></Declaration>
</Method>
<Method Name="Create" Id="{81c71698-0737-4ddf-8dda-7c86a5b4cf1a}">
<Declaration><![CDATA[// Creates/Adds an node to the end of the list
METHOD Create : I_List
VAR_INPUT
Value : ANY; // Value to store in node
END_VAR]]></Declaration>
</Method>
<Method Name="FB_exit" Id="{1c781fd8-c6fe-42d0-a211-a7e9afc18fb6}">
<Declaration><![CDATA[METHOD FB_exit : BOOL
VAR_INPUT
bInCopyCode : BOOL; // if TRUE, the exit method is called for exiting an instance that is copied afterwards (online change).
END_VAR
]]></Declaration>
</Method>
<Method Name="FB_init" Id="{14643ed7-fa83-4b95-bd84-9faef0650674}">
<Declaration><![CDATA[METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)
END_VAR
]]></Declaration>
</Method>
<Method Name="Get" Id="{3408fde9-c59e-4daa-b1d3-2d315fba1247}">
<Declaration><![CDATA[// Gets value from node at specified location;
METHOD Get : I_List
VAR_INPUT
Return_Value : ANY; // Variable to store requested node value
nIndex : DINT; // Location of node
END_VAR
]]></Declaration>
</Method>
<Method Name="Get_First" Id="{6b62c219-0110-480f-ac77-14ea333b936c}">
<Declaration><![CDATA[(* Gets value from first node. *)
METHOD Get_First : I_List
VAR_INPUT
Return_Value : ANY; // Variable to store returned value
END_VAR
]]></Declaration>
</Method>
<Method Name="Insert" Id="{c72aa948-3d8d-418d-a835-9c758c493d3b}">
<Declaration><![CDATA[// Adds new node to list at specified location
METHOD Insert : I_List
VAR_INPUT
Value : ANY; // Value to store in node
nIndex : DINT; // Location of node
END_VAR
]]></Declaration>
</Method>
<Method Name="Remove" Id="{2d468d08-7339-425f-acf1-368fbf9e2da3}">
<Declaration><![CDATA[(* Removes node at the front of the list and returns nothing. *)
METHOD Remove : I_List]]></Declaration>
</Method>
<Method Name="RemoveAt" Id="{49c185ed-edf9-4e4c-9697-d7cc0160f1c4}">
<Declaration><![CDATA[(* Remove node at specific loacation and return nothing *)
METHOD RemoveAt : I_List
VAR_INPUT
nIndex : DINT; // Location of node
END_VAR
]]></Declaration>
</Method>
<Method Name="Reverse" Id="{c8b588a0-6952-4667-82bf-7c4a6fefe80f}">
<Declaration><![CDATA[// Reverses list
METHOD Reverse : I_List
VAR_INPUT
END_VAR
]]></Declaration>
</Method>
<Method Name="Set" Id="{79c99d5b-b40c-4004-b332-3be0fe381fbb}">
<Declaration><![CDATA[// Sets value of node at specified location;
METHOD Set : I_List
VAR_INPUT
Value : ANY; // Value to store in node
nIndex : DINT; // Location of node
END_VAR
]]></Declaration>
</Method>
</Itf>
</TcPlcObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.4">
<Itf Name="I_Queue" Id="{4eed3d95-b896-4b64-bd88-ac8bba53121e}">
<Declaration><![CDATA[INTERFACE I_Queue EXTENDS I_Collections
]]></Declaration>
<Method Name="Dequeue" Id="{fb46ed3c-fa34-4930-b5f9-e6941295352c}">
<Declaration><![CDATA[(* Gets and remove item at the front of the queue *)
METHOD Dequeue : I_Queue
VAR_INPUT
Item : ANY; (* Variable to store returned item value *)
END_VAR
]]></Declaration>
</Method>
<Method Name="Dequeue_Void" Id="{c228b725-f3fc-4d64-8603-59b0dbe64ff5}">
<Declaration><![CDATA[(* Removes item at the front of the queue without returning anything *)
METHOD Dequeue_Void : I_Queue
VAR_INPUT
END_VAR
]]></Declaration>
</Method>
<Method Name="Enqueue" Id="{be9c9437-6d55-43f8-9c73-1f440f4d6bdb}">
<Declaration><![CDATA[(* Adds item at the back of the queue *)
METHOD Enqueue : I_Queue
VAR_INPUT
Item : ANY; (* Variable containg data to store on the queue *)
END_VAR
]]></Declaration>
</Method>
<Method Name="Enqueue_At_Front" Id="{64f76513-52e3-4f9f-8994-8006a245f9a9}">
<Declaration><![CDATA[(* Adds item at the front of the queue *)
METHOD Enqueue_At_Front : I_Queue
VAR_INPUT
Item : ANY; (* Variable containg data to store on the queue *)
END_VAR]]></Declaration>
</Method>
<Method Name="Peek" Id="{b611f957-687f-4533-a433-958b59ee48a2}">
<Declaration><![CDATA[(* Get item from the queue without removing it. *)
METHOD Peek : I_Queue
VAR_INPUT
Item : ANY; (* Variable to store returned item value *)
nIndex : DINT; (* Location of item*)
END_VAR]]></Declaration>
</Method>
<Method Name="Reverse" Id="{7f066baf-31b2-4ef5-9b2d-af3474545861}">
<Declaration><![CDATA[METHOD Reverse : I_Queue
VAR_INPUT
END_VAR
]]></Declaration>
</Method>
</Itf>
</TcPlcObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.4">
<Itf Name="I_Stack" Id="{2df439e0-81da-4e78-87bf-c4adedd54744}">
<Declaration><![CDATA[INTERFACE I_Stack EXTENDS I_Collections
]]></Declaration>
<Method Name="Peek" Id="{9a978ae2-f74e-4a80-a688-5ff02915b184}">
<Declaration><![CDATA[(* Get item from stack without removing it. *)
METHOD Peek : I_Stack
VAR_INPUT
Item : ANY; (* Variable to store returned item value *)
nIndex : DINT; (* Location of item*)
END_VAR
]]></Declaration>
</Method>
<Method Name="Pop" Id="{3bcc8ffd-0585-4d63-8b9b-010f602fe127}">
<Declaration><![CDATA[(* Gets and deletes item at the top of the stack *)
METHOD Pop : I_Stack
VAR_INPUT
Item : ANY; (* Variable to store returned item value *)
END_VAR
]]></Declaration>
</Method>
<Method Name="Pop_Void" Id="{48ea49e8-fe7d-43cc-92e3-4e500d8fe13c}">
<Declaration><![CDATA[(* Removes item at the top of the stack without returning anything *)
METHOD Pop_Void : I_Stack
VAR_INPUT
END_VAR
]]></Declaration>
</Method>
<Method Name="Push" Id="{80e4c8db-67e1-4c76-bcdb-e77d10437f1a}">
<Declaration><![CDATA[(* Add item to the top of the stack *)
METHOD Push : I_Stack
VAR_INPUT
Item : ANY; (* Variable containg data to store on the stack *)
END_VAR
]]></Declaration>
</Method>
<Method Name="Top" Id="{90510f03-ae76-443f-90c7-d276be0836b6}">
<Declaration><![CDATA[(* Get item at the top of the stack without removing it. *)
METHOD Top : I_Stack
VAR_INPUT
Item : ANY; (* Variable to store returned item value *)
END_VAR
]]></Declaration>
</Method>
</Itf>
</TcPlcObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.4">
<DUT Name="ST_ERROR" Id="{8f8f9496-fce9-4bb0-b8ee-f9ba713f7871}">
<Declaration><![CDATA[(* STRUCT used to contain error status information. *)
{attribute 'enable_dynamic_creation'}
TYPE ST_ERROR :
STRUCT
bSTATUS : BOOL; // Indicates if an error has occurred | TRUE = error, FALSE = no error
nCODE : DINT; // Error code specific to the particular error.
sSOURCE : T_MaxString; // Textual information describing the error.
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.4">
<DUT Name="ST_NODE" Id="{ae72523c-b4d2-4bc3-a909-213c887bca25}">
<Declaration><![CDATA[{attribute 'enable_dynamic_creation'}
TYPE ST_NODE:
STRUCT
Data : __SYSTEM.AnyType; // Stored data.
sData : T_MaxString; // Data converted to string.
pNext : POINTER TO ST_NODE := Tc3_Module.GVL.NULL; // Pointer to next node. (DEFAULT: NULL pointer)
END_STRUCT
END_TYPE
]]></Declaration>
</DUT>
</TcPlcObject>
Loading

0 comments on commit 2202cca

Please sign in to comment.