Skip to content

Commit

Permalink
RS485_BUS_CONTROLLER: adding failsafe timer (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichielVanwelsenaere authored Oct 17, 2024
1 parent 070c721 commit 3156d94
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 13 deletions.
85 changes: 75 additions & 10 deletions src/Exports/CodesysV3.export
Original file line number Diff line number Diff line change
Expand Up @@ -10980,7 +10980,7 @@
<Single Type="System.Guid">a9ed5b7e-75c5-4651-af16-d2c27e98cb94</Single>
<Single Type="System.Guid">3b83b776-fb25-43b8-99f2-3c507c9143fc</Single>
</Array>
<Single Name="Timestamp" Type="long">638115485363855446</Single>
<Single Name="Timestamp" Type="long">638647811006771283</Single>
</Single>
<Single Name="Object" Type="{6f9dac99-8de1-4efc-8465-68ac443b7d08}" Method="IArchivable">
<Single Name="SpecialFunc" Type="{0db3d7bb-cde0-4416-9a7b-ce49a0124323}">None</Single>
Expand All @@ -11002,6 +11002,11 @@
<Null Name="Tag" />
<Single Name="Text" Type="string"> tonDelay.IN := TRUE;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">67</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string"> failSafeTimer.PT := T#10S;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">6</Single>
<Null Name="Tag" />
Expand Down Expand Up @@ -11032,6 +11037,11 @@
<Null Name="Tag" />
<Single Name="Text" Type="string">tonDelay();</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">68</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">failSafeTimer();</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">12</Single>
<Null Name="Tag" />
Expand Down Expand Up @@ -11127,6 +11137,36 @@
<Null Name="Tag" />
<Single Name="Text" Type="string">END_IF</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">70</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string"></Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">71</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">//if nothing is happening for to long, release the bus</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">72</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">IF BusOcupied AND failSafeTimer.Q THEN</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">73</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string"> devices[selectedDevice].ProcessDataArray(ADR(failSafeTimer.Q), BusData);</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">74</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string"> THIS^.ReleaseBus(); </Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">69</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">END_IF</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">31</Single>
<Null Name="Tag" />
Expand Down Expand Up @@ -11229,10 +11269,20 @@
<Single Name="Text" Type="string"> /// To manage silence time and startup delay</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">49</Single>
<Single Name="Id" Type="long">65</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string"> tonDelay: TON;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">66</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string"> /// in case the bus is occupied for an unusual long time, release it</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">49</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string"> failSafeTimer: TON;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">50</Single>
<Null Name="Tag" />
Expand Down Expand Up @@ -11316,7 +11366,7 @@
</Array>
</Single>
</Single>
<Single Name="UniqueIdGenerator" Type="string">64</Single>
<Single Name="UniqueIdGenerator" Type="string">74</Single>
<Single Name="POULevel" Type="{8e575c5b-1d37-49c6-941b-5c0ec7874787}">Standard</Single>
<List Name="ChildObjectGuids" Type="System.Collections.ArrayList" />
<Single Name="AddAttributeSubsequent" Type="bool">False</Single>
Expand Down Expand Up @@ -37508,32 +37558,42 @@
<Single Type="System.Guid">a9ed5b7e-75c5-4651-af16-d2c27e98cb94</Single>
<Single Type="System.Guid">3b83b776-fb25-43b8-99f2-3c507c9143fc</Single>
</Array>
<Single Name="Timestamp" Type="long">638115485363925025</Single>
<Single Name="Timestamp" Type="long">638647811426705746</Single>
</Single>
<Single Name="Object" Type="{f8a58466-d7f6-439f-bbb8-d4600e41d099}" Method="IArchivable">
<Single Name="Implementation" Type="{3b83b776-fb25-43b8-99f2-3c507c9143fc}" Method="IArchivable">
<Single Name="TextDocument" Type="{f3878285-8e4f-490b-bb1b-9acbb7eb04db}" Method="IArchivable">
<Array Name="TextLines" Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}">
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">3</Single>
<Single Name="Id" Type="long">7</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">// Start a timer to release the bus</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">4</Single>
<Single Name="Id" Type="long">8</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">THIS^.tonDelay.PT := THIS^.SilenceTime;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">5</Single>
<Single Name="Id" Type="long">9</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">THIS^.tonDelay.IN := TRUE;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">2</Single>
<Single Name="Id" Type="long">10</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">THIS^.failSafeTimer.IN := FALSE;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">11</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">THIS^.deviceActive := FALSE;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">2</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string"></Single>
</Single>
</Array>
</Single>
</Single>
Expand Down Expand Up @@ -37590,17 +37650,22 @@
<Single Type="System.Guid">a9ed5b7e-75c5-4651-af16-d2c27e98cb94</Single>
<Single Type="System.Guid">3b83b776-fb25-43b8-99f2-3c507c9143fc</Single>
</Array>
<Single Name="Timestamp" Type="long">638115485363965028</Single>
<Single Name="Timestamp" Type="long">638647811276812596</Single>
</Single>
<Single Name="Object" Type="{f8a58466-d7f6-439f-bbb8-d4600e41d099}" Method="IArchivable">
<Single Name="Implementation" Type="{3b83b776-fb25-43b8-99f2-3c507c9143fc}" Method="IArchivable">
<Single Name="TextDocument" Type="{f3878285-8e4f-490b-bb1b-9acbb7eb04db}" Method="IArchivable">
<Array Name="TextLines" Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}">
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">3</Single>
<Single Name="Id" Type="long">5</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">THIS^.tonDelay.IN := FALSE;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">6</Single>
<Null Name="Tag" />
<Single Name="Text" Type="string">THIS^.failSafeTimer.IN := TRUE;</Single>
</Single>
<Single Type="{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}" Method="IArchivable">
<Single Name="Id" Type="long">2</Single>
<Null Name="Tag" />
Expand Down
25 changes: 22 additions & 3 deletions src/Exports/PLCopen.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://www.plcopen.org/xml/tc6_0200">
<fileHeader companyName="WAGO" productName="e!COCKPIT" productVersion="e!COCKPIT" creationDateTime="2024-10-16T19:16:24.6920274" />
<contentHeader name="HomeAutomation.ecp" modificationDateTime="2024-10-16T19:14:29.3641422">
<fileHeader companyName="WAGO" productName="e!COCKPIT" productVersion="e!COCKPIT" creationDateTime="2024-10-17T17:00:07.9148148" />
<contentHeader name="HomeAutomation.ecp" modificationDateTime="2024-10-17T16:59:29.9903212">
<coordinateInfo>
<fbd>
<scaling x="1" y="1" />
Expand Down Expand Up @@ -9328,6 +9328,14 @@ END_WHILE</xhtml>
<xhtml xmlns="http://www.w3.org/1999/xhtml"> To manage silence time and startup delay</xhtml>
</documentation>
</variable>
<variable name="failSafeTimer">
<type>
<derived name="TON" />
</type>
<documentation>
<xhtml xmlns="http://www.w3.org/1999/xhtml"> in case the bus is occupied for an unusual long time, release it</xhtml>
</documentation>
</variable>
<variable name="devices">
<type>
<array>
Expand Down Expand Up @@ -9427,12 +9435,14 @@ END_WHILE</xhtml>
<xhtml xmlns="http://www.w3.org/1999/xhtml">IF Startup THEN
tonDelay.PT := StartupDelay;
tonDelay.IN := TRUE;
failSafeTimer.PT := T#10S;
Startup := FALSE;
END_IF

QueryReady(CLK := BusTrigger^);
BusOcupied := NOT(tonDelay.Q);
tonDelay();
failSafeTimer();

// check if there's a device that requires bus time and if so, launch the query
IF busOcupied = FALSE AND deviceActive = FALSE AND devicesCount &lt;&gt; 0 AND NOT QueryReady.Q THEN
Expand All @@ -9453,6 +9463,12 @@ IF QueryReady.Q THEN
THIS^.ReleaseBus();
END_IF

//if nothing is happening for to long, release the bus
IF BusOcupied AND failSafeTimer.Q THEN
devices[selectedDevice].ProcessDataArray(ADR(failSafeTimer.Q), BusData);
THIS^.ReleaseBus();
END_IF


//let the busdevices to their work
//FOR loopCounter := 0 TO devicesCount - 1 DO
Expand Down Expand Up @@ -9542,6 +9558,7 @@ THIS^.BusError := BusError;</xhtml>
<body>
<ST>
<xhtml xmlns="http://www.w3.org/1999/xhtml">THIS^.tonDelay.IN := FALSE;
THIS^.failSafeTimer.IN := TRUE;
THIS^.deviceActive := TRUE;</xhtml>
</ST>
</body>
Expand All @@ -9562,7 +9579,9 @@ THIS^.deviceActive := TRUE;</xhtml>
<xhtml xmlns="http://www.w3.org/1999/xhtml">// Start a timer to release the bus
THIS^.tonDelay.PT := THIS^.SilenceTime;
THIS^.tonDelay.IN := TRUE;
THIS^.deviceActive := FALSE;</xhtml>
THIS^.failSafeTimer.IN := FALSE;
THIS^.deviceActive := FALSE;
</xhtml>
</ST>
</body>
<addData />
Expand Down
Binary file modified src/HomeAutomation.ecp
Binary file not shown.

0 comments on commit 3156d94

Please sign in to comment.