Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RS485_BUS_CONTROLLER: adding failsafe timer #162

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/FAQ/RS485_tips_and_tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,16 @@ The led will light up everytime data passes over the bus providing more informat
<!-- markdown-link-check-disable -->
Consider [this article on electrical-engineering](https://electrical-engineering-portal.com/correct-cabling-modbus-rs485) a must read.
<!-- markdown-link-check-enable -->

### **Using a dedicated Wago RS485 module**
Depending on requirements a dedicated RS485 module might be required instead of using the onboard serial port of the device (if available).

Based on user experience in this field, pay attention to:
- reset the module to factory settings before using.
- last confirmed working version of required libraries:
- WagoSysModule_75x_65x: Version 1.9.5.2
- WagoTypesCom: Version 1.6.1.3
- change the 'comport' in the RS485 master function block you intend to use.
- make sure the wiring of the module is correct:

<img src="../_img/WagoRS485ExternalWiring.gif" width="550">
Binary file added docs/_img/WagoRS485ExternalWiring.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.