strolch-website/docs/plc/example-set-up/index.html

46 lines
20 KiB
HTML

<!doctype html><html lang=en class="js csstransforms3d"><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=generator content="Hugo 0.80.0"><meta name=description content="Strolch is a parameterized framework for use on servers and IoT"><meta name=author content="Robert von Burg"><link rel=icon href=/favicon.ico type=image/ico><title>Example Set-Up - Strolch</title><link href=/css/nucleus.css?1678977092 rel=stylesheet><link href=/css/fontawesome-all.min.css?1678977092 rel=stylesheet><link href=/css/hybrid.css?1678977092 rel=stylesheet><link href=/css/featherlight.min.css?1678977092 rel=stylesheet><link href=/css/perfect-scrollbar.min.css?1678977092 rel=stylesheet><link href=/css/auto-complete.css?1678977092 rel=stylesheet><link href=/css/atom-one-dark-reasonable.css?1678977092 rel=stylesheet><link href=/css/theme.css?1678977092 rel=stylesheet><link href=/css/hugo-theme.css?1678977092 rel=stylesheet><link href=/css/theme-green.css?1678977092 rel=stylesheet><script src=/js/jquery-3.3.1.min.js?1678977092></script><style>:root #header+#content>#left>#rlblock_left{display:none!important}</style></head><body data-url=/plc/example-set-up/><nav id=sidebar><div id=header-wrapper><div id=header><a id=logo href=/><img src=/logo.png></a></div><div class=searchbox><label for=search-by><i class="fas fa-search"></i></label><input data-search-input id=search-by type=search placeholder=Search...>
<span data-search-clear><i class="fas fa-times"></i></span></div><script type=text/javascript src=/js/lunr.min.js?1678977092></script><script type=text/javascript src=/js/auto-complete.js?1678977092></script><script type=text/javascript>var baseurl="https:\/\/strolch.li\/";</script><script type=text/javascript src=/js/search.js?1678977092></script></div><section id=homelinks><ul><li><a class=padding href=/><i class="fas fa-home"></i>Home</a></li></ul></section><div class=highlightable><ul class=topics><li data-nav-id=/api/ title=API class=dd-item><a href=/api/>API</a></li><li data-nav-id=/documentation/ title=Documentation class=dd-item><a href=/documentation/>Documentation</a><ul><li data-nav-id=/documentation/architecture/ title=Architecture class=dd-item><a href=/documentation/architecture/>Architecture</a></li><li data-nav-id=/documentation/model/ title=Model class=dd-item><a href=/documentation/model/>Model</a></li><li data-nav-id=/documentation/do-and-donts/ title="Do and Don't" class=dd-item><a href=/documentation/do-and-donts/>Do and Don't</a></li><li data-nav-id=/documentation/runtime-configuration/ title="Runtime Configuration" class=dd-item><a href=/documentation/runtime-configuration/>Runtime Configuration</a></li><li data-nav-id=/documentation/realms/ title=Realms class=dd-item><a href=/documentation/realms/>Realms</a></li><li data-nav-id=/documentation/components/ title=Components class=dd-item><a href=/documentation/components/>Components</a></li><li data-nav-id=/documentation/services-and-commands/ title="Services and Commands" class=dd-item><a href=/documentation/services-and-commands/>Services and Commands</a></li><li data-nav-id=/documentation/searches/ title=Searches class=dd-item><a href=/documentation/searches/>Searches</a></li><li data-nav-id=/documentation/queries/ title=Queries class=dd-item><a href=/documentation/queries/>Queries</a></li><li data-nav-id=/documentation/transactions/ title=Transactions class=dd-item><a href=/documentation/transactions/>Transactions</a></li><li data-nav-id=/documentation/policies/ title=Policies class=dd-item><a href=/documentation/policies/>Policies</a></li><li data-nav-id=/documentation/observers/ title=Observers class=dd-item><a href=/documentation/observers/>Observers</a></li><li data-nav-id=/documentation/versioning/ title=Versioning class=dd-item><a href=/documentation/versioning/>Versioning</a></li><li data-nav-id=/documentation/reports/ title=Reports class=dd-item><a href=/documentation/reports/>Reports</a></li><li data-nav-id=/documentation/priviles/ title=Privileges class=dd-item><a href=/documentation/priviles/>Privileges</a></li></ul></li><li data-nav-id=/plc/ title=PLC class="dd-item
parent"><a href=/plc/>PLC</a><ul><li data-nav-id=/plc/architecture/ title=Architecture class=dd-item><a href=/plc/architecture/>Architecture</a></li><li data-nav-id=/plc/example-set-up/ title="Example Set-Up" class="dd-item active"><a href=/plc/example-set-up/>Example Set-Up</a></li></ul></li><li data-nav-id=/tutorial/ title=Tutorial class=dd-item><a href=/tutorial/>Tutorial</a><ul><li data-nav-id=/tutorial/configuration/ title=Configuration class=dd-item><a href=/tutorial/configuration/>Configuration</a></li><li data-nav-id=/tutorial/model/ title=Model class=dd-item><a href=/tutorial/model/>Model</a></li><li data-nav-id=/tutorial/crud-book/ title="CRUD Book" class=dd-item><a href=/tutorial/crud-book/>CRUD Book</a></li></ul></li><li data-nav-id=/download/ title=Download class=dd-item><a href=/download/>Download</a></li><li data-nav-id=/development/ title=Development class=dd-item><a href=/development/>Development</a><ul><li data-nav-id=/development/prerequisites/ title=Prerequisites class=dd-item><a href=/development/prerequisites/>Prerequisites</a></li><li data-nav-id=/development/building/ title="Building Strolch" class=dd-item><a href=/development/building/>Building Strolch</a></li><li data-nav-id=/development/maven-archetypes/ title="Maven Archetypes" class=dd-item><a href=/development/maven-archetypes/>Maven Archetypes</a></li><li data-nav-id=/development/web-app/ title="Web App" class=dd-item><a href=/development/web-app/>Web App</a></li><li data-nav-id=/development/main-class-app/ title="Main Class App" class=dd-item><a href=/development/main-class-app/>Main Class App</a></li><li data-nav-id=/development/converting-existing/ title="Converting Existing App" class=dd-item><a href=/development/converting-existing/>Converting Existing App</a></li></ul></li><li data-nav-id=/blog/ title=Blog class=dd-item><a href=/blog/>Blog</a><ul><li data-nav-id=/blog/post-00018/ title="Strolch PLC 1.2.3 released" class=dd-item><a href=/blog/post-00018/>Strolch PLC 1.2.3 released</a></li><li data-nav-id=/blog/post-00017/ title="Strolch 1.8.5 and PLC 1.2.2 are out" class=dd-item><a href=/blog/post-00017/>Strolch 1.8.5 and PLC 1.2.2 are out</a></li><li data-nav-id=/blog/post-00016/ title="Strolch PLC now also on Maven Central" class=dd-item><a href=/blog/post-00016/>Strolch PLC now also on Maven Central</a></li><li data-nav-id=/blog/post-00015/ title="Release of Strolch 1.6.100" class=dd-item><a href=/blog/post-00015/>Release of Strolch 1.6.100</a></li><li data-nav-id=/blog/post-00014/ title="Strolch Reports" class=dd-item><a href=/blog/post-00014/>Strolch Reports</a></li><li data-nav-id=/blog/post-00013/ title="Strolch Searches" class=dd-item><a href=/blog/post-00013/>Strolch Searches</a></li><li data-nav-id=/blog/post-00012/ title="Wow, the many changes!" class=dd-item><a href=/blog/post-00012/>Wow, the many changes!</a></li><li data-nav-id=/blog/post-00011/ title="Strolch now on Maven Central" class=dd-item><a href=/blog/post-00011/>Strolch now on Maven Central</a></li><li data-nav-id=/blog/post-00010/ title="Versioning of objects" class=dd-item><a href=/blog/post-00010/>Versioning of objects</a></li><li data-nav-id=/blog/post-00009/ title="Release 1.2.0" class=dd-item><a href=/blog/post-00009/>Release 1.2.0</a></li><li data-nav-id=/blog/post-00008/ title="Strolch Update" class=dd-item><a href=/blog/post-00008/>Strolch Update</a></li><li data-nav-id=/blog/post-00007/ title="Activities: Beginning of the planning engine" class=dd-item><a href=/blog/post-00007/>Activities: Beginning of the planning engine</a></li><li data-nav-id=/blog/post-00006/ title="Strolch Documentation" class=dd-item><a href=/blog/post-00006/>Strolch Documentation</a></li><li data-nav-id=/blog/post-00005/ title="Strolch Release 1.0.0" class=dd-item><a href=/blog/post-00005/>Strolch Release 1.0.0</a></li><li data-nav-id=/blog/post-00004/ title="DurationParameter and other minor changes: Release 1.0.0-RC4" class=dd-item><a href=/blog/post-00004/>DurationParameter and other minor changes: Release 1.0.0-RC4</a></li><li data-nav-id=/blog/post-00003/ title="DB Initialization: Release 1.0.0-RC3" class=dd-item><a href=/blog/post-00003/>DB Initialization: Release 1.0.0-RC3</a></li><li data-nav-id=/blog/post-00002/ title="Release 1.0.0-RC2" class=dd-item><a href=/blog/post-00002/>Release 1.0.0-RC2</a></li><li data-nav-id=/blog/post-00001/ title="Release 1.0.0-RC1" class=dd-item><a href=/blog/post-00001/>Release 1.0.0-RC1</a></li></ul></li></ul><section id=shortcuts><h3>More</h3><ul><li><a class=padding href=https://strolch.li/tags><i class="fas fa-tags"></i>Tags</a></li><li><a class=padding href=https://github.com/strolch-li><i class="fab fa-github"></i>GitHub project</a></li><li><a rel=me class=padding href=https://mstdn.gsi.li/@eitch target=_blank><i class="fab fa-mastodon"></i>Mastodon</a></li></ul></section><section id=footer><p>Built with <a href=https://github.com/matcornic/hugo-theme-learn target=_blank><i class="fas fa-heart"></i></a>from <a href=https://getgrav.org target=_blank>Grav</a> and <a href=https://gohugo.io/ target=_blank>Hugo</a></p></section></div></nav><section id=body><div id=overlay></div><div class="padding highlightable"><div><div id=top-bar><div id=top-github-link><a class=github-link title="Edit this page" href=https://github.com/strolch-li/strolch-website/tree/develop/content/plc/example-set-up.md target=blank><i class="fas fa-code-branch"></i><span id=top-github-link-text>Edit this page</span></a></div><div id=breadcrumbs itemscope itemtype=http://data-vocabulary.org/Breadcrumb><span id=sidebar-toggle-span><a href=# id=sidebar-toggle data-sidebar-toggle><i class="fas fa-bars"></i></a></span><span id=toc-menu><i class="fas fa-list-alt"></i></span><span class=links><a href=/>Strolch Overview</a> > <a href=/plc/>PLC</a> > Example Set-Up</span></div><div class=progress><div class=wrapper><nav id=TableOfContents><ul><li><a href=#example-set-up>Example Set-Up</a></li><li><a href=#new-project>New Project</a><ul><li><a href=#strolch-plc-example-connectionsxml>strolch-plc-example-connections.xml</a></li><li><a href=#strolch-plc-examplecsv>strolch-plc-example.csv</a></li><li><a href=#running-the-example>Running the example</a></li><li><a href=#customization>Customization</a></li></ul></li></ul></nav></div></div></div></div><div id=head-tags></div><div id=body-inner><h1>Example Set-Up</h1><h2 id=example-set-up>Example Set-Up</h2><p>This example setup describes the movement of containers over conveyors. The
conveyors have motors which can be started and stopped by a GPIO output pin
controlled on a Raspberry Pi and each conveyor has a light barrier to detect the
occupancy of a container and the Raspberry Pi detects this on GPIO input pins.</p><p>Further at each conveyor location is a barcode reader to read the ID of a
container.</p><p>The general idea is that the PLC notifies a Strolch agent of changes, and only
turns conveyors on, when the agent gives the command. Thus the agent handles
business logic and the PLC controls the I/Os.</p><p><img src=/assets/images/Strolch-Plc-Example.png alt="Strolch PLC Example"></p><h2 id=new-project>New Project</h2><p>Create a new project using the PLC Strolch Maven Archetype:</p><div class=highlight><pre style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-shell data-lang=shell>mvn archetype:generate <span style=color:#ae81ff>\
</span><span style=color:#ae81ff></span> -DarchetypeGroupId<span style=color:#f92672>=</span>li.strolch <span style=color:#ae81ff>\
</span><span style=color:#ae81ff></span> -DarchetypeArtifactId<span style=color:#f92672>=</span>strolch.mvn.archetype.plc <span style=color:#ae81ff>\
</span><span style=color:#ae81ff></span> -DarchetypeVersion<span style=color:#f92672>=</span>0.1.0-SNAPSHOT <span style=color:#ae81ff>\
</span><span style=color:#ae81ff></span> -DgroupId<span style=color:#f92672>=</span>&lt;my.groupid&gt; <span style=color:#ae81ff>\
</span><span style=color:#ae81ff></span> -DartifactId<span style=color:#f92672>=</span>&lt;my-artifactId&gt; <span style=color:#ae81ff>\
</span><span style=color:#ae81ff></span> -Dversion<span style=color:#f92672>=</span>&lt;my.version&gt; <span style=color:#ae81ff>\
</span><span style=color:#ae81ff></span> -Dpackage<span style=color:#f92672>=</span>&lt;my.package&gt; <span style=color:#ae81ff>\
</span><span style=color:#ae81ff></span> -DappName<span style=color:#f92672>=</span><span style=color:#e6db74>&#34;&lt;my app name&gt;&#34;</span>
</code></pre></div><p>This will create a multi-module project:</p><ul><li>The <code>&lt;my-artifactId>-web</code> module contains the server code, which handles notifications from the PLC, and can send
telegrams to the PLC.</li><li>The <code>&lt;my-artifactId>-plc-web</code> module contains the PLC code, which connects to the server and communicates with the
low-level hardware.</li><li>The <code>shared</code> modules contains classes shared by both projects (e.g. constants, etc.).</li></ul><p>This project already contains a default PLC model in <code>&lt;my-artifactId>-plc-web/runtime/data/</code>.</p><p>The following sections explains these files:</p><h3 id=strolch-plc-example-connectionsxml>strolch-plc-example-connections.xml</h3><p>This file defines the hardware connections. The following connections are implemented:</p><ul><li>li.strolch.plc.core.hw.i2c.RSL366OverHorterI2c</li><li>li.strolch.plc.core.hw.i2c.PCF8574InputConnection</li><li>li.strolch.plc.core.hw.gpio.RaspiBcmGpioInputConnection</li><li>li.strolch.plc.core.hw.gpio.RaspiBcmGpioOutputConnection</li><li>li.strolch.plc.core.hw.i2c.Multi8BitI2cOutputConnection</li><li>li.strolch.plc.core.hw.connections.DataLogicScannerConnection</li><li>li.strolch.plc.core.hw.connections.LoggerOutConnection</li><li>li.strolch.plc.core.hw.connections.RandomStringConnection</li></ul><p>See their respective classes for details.</p><h3 id=strolch-plc-examplecsv>strolch-plc-example.csv</h3><p>This file maps I/Os to Resources and Actions and is converted into Strolch <code>Resource</code> objects using
the <code>PlcAddressGenerator</code> class.</p><p>In this example we will use simple Raspberry Pi GPIOs. For convenience, and also when sharing I/O definitions with
external partners, it is easier to use a CSV file to define the I/Os and then use the <code>PlcAddressGenerator</code> to generate
and validate the model.</p><p>For easier handling, use the following Google Sheet as a starting
point: <a href="https://docs.google.com/spreadsheets/d/10fgTfR3FZCVbQ5bbh0xB1u8rLIaw2KEyO45VMv7y5ho/edit?usp=sharing">https://docs.google.com/spreadsheets/d/10fgTfR3FZCVbQ5bbh0xB1u8rLIaw2KEyO45VMv7y5ho/edit?usp=sharing</a></p><p>The CSV headers are as follows:</p><ul><li>Description → a simple description for this PlcAddress</li><li>Type →<ul><li>Group → Must be the first line and generates a PlcLogicalDevice, all
succeeding lines are grouped to this device. Add additional to group
further devices</li><li>Input → defines a boolean input</li><li>Output → defines a boolean output</li><li>Virtual → defines a virtual address which has no corresponding hardware
connection. Used for internal communication.</li><li>DataLogicScanner → defines an address to read barcodes from a DataLogic
Scanner. The actions must be left empty as the keys Barcode (address), On
and Off (telegrams) will be generated.</li></ul></li><li>SubType →<ul><li>For Input and Output types →<ul><li>DevPin, DevPin0 → Generates the address as <code>&lt;Connection>.&lt;Device>.&lt;Pin></code>.
DevPin0 decrements the Device and Pin values by one for zero-indexed addressing.</li><li>Pin → Generates the address as <code>&lt;Connection>.&lt;Pin></code>.</li></ul></li><li>For Virtual types →<ul><li>Boolean</li><li>String</li><li>Integer</li></ul></li></ul></li><li>Device → Device number</li><li>Pin → The pin number on the device</li><li>Resource → The resource ID with which to notify the agent</li><li>Action1 → The action ID</li><li>Action2 → The second action ID if required</li><li>Connection → The ID of the PlcConnection with which this I/O is attached</li><li>DeviceId → For type Group: Set the ID of this PlcLogicalDevice being generated</li><li>Interted → For boolean inputs or outputs, if true, inverts the value</li><li>Value → A default value, often used for virtual integer addresses</li><li>Remote → if true, then the server will be notified of changes to this address</li></ul><p>When you use this file as input for the <code>PlcAddressGenerator</code>, then it will
generate PlcLogicalDevice, PlcAddress and PlcTelegram elements. See the file <code>strolch-plc-example.xml</code> for an example.</p><p>The <code>PlcLogicalDevice</code> references the <code>PlcAddress</code> and <code>PlcTelegram</code> objects, and is
then used in the UI for grouping.</p><p>The <code>PlcAddress</code> is used to store the current value and defines the keys with
which the agent will be notified</p><p>The <code>PlcTelegram</code> is used to store default values to send, for specific keys. E.g.
The action <code>On</code> would send true, and <code>Off</code> would send false. This is semantics, and
is defined in each project depending on the hardware.</p><h3 id=running-the-example>Running the example</h3><p>Once you have both the server and PLC instances running, you can login. The default username and password are <code>admin</code>
/ <code>admin</code>.</p><p>After logging in to the PLC you should be greeted with the following
screen:
<img src=/assets/images/plc.png alt="PLC UI"></p><p>And after logging in to the server you should be greeted with the following
screen:
<img src=/assets/images/plc-server.png alt="Server UI"></p><p>If the PLC could connect to the server, then the <code>PLC Control</code> icon should be activated. The actions Enable, Disable and
Stop All send telegrams to the PLC, thus showing how the server would communicate with the PLC.</p><h3 id=customization>Customization</h3><h4 id=plc>PLC</h4><p>Now that the server and PLC are running, we can customize the code. On the PLC side you will want to create
new <code>li.strolch.plc.core.PlcService</code> services by extending the class and then registering the service
in <code>CustomPlcServiceInitializer</code>.</p><p>See the example <code>StartupPlcService</code>.</p><h4 id=server>Server</h4><p>On the server side, to register for notifications from the PLC, one would
implement <code>li.strolch.plc.gw.server.PlcGwService</code> services and register them on the <code>PlcHandler</code> in
the <code>PostInitializer</code> class.</p><p>See the example <code>ModePlcSrvService</code>.</p><footer class=footline></footer></div></div><div id=navigation><a class="nav nav-prev" href=/plc/architecture/ title=Architecture><i class="fa fa-chevron-left"></i></a><a class="nav nav-next" href=/tutorial/ title=Tutorial style=margin-right:0><i class="fa fa-chevron-right"></i></a></div></section><div style=left:-1000px;overflow:scroll;position:absolute;top:-1000px;border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px><div style=border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px></div></div><script src=/js/clipboard.min.js?1678977092></script><script src=/js/perfect-scrollbar.min.js?1678977092></script><script src=/js/perfect-scrollbar.jquery.min.js?1678977092></script><script src=/js/jquery.sticky.js?1678977092></script><script src=/js/featherlight.min.js?1678977092></script><script src=/js/highlight.pack.js?1678977092></script><script>hljs.initHighlightingOnLoad();</script><script src=/js/modernizr.custom-3.6.0.js?1678977092></script><script src=/js/learn.js?1678977092></script><script src=/js/hugo-learn.js?1678977092></script><script src=/mermaid/mermaid.js?1678977092></script><script>mermaid.initialize({startOnLoad:true});</script><script type=text/javascript>var _paq=window._paq=window._paq||[];_paq.push(["setDocumentTitle",document.domain+"/"+document.title]);_paq.push(["setCookieDomain","*.strolch.li"]);_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);(function(){var u="https://piwik.eitchnet.ch/";_paq.push(['setTrackerUrl',u+'matomo.php']);_paq.push(['setSiteId','2']);var d=document,g=d.createElement('script'),s=d.getElementsByTagName('script')[0];g.type='text/javascript';g.async=true;g.src=u+'matomo.js';s.parentNode.insertBefore(g,s);})();</script></body></html>