<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to How to run a python script with codesys GUI</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/371c692c9c/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/371c692c9c/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/371c692c9c/</id><updated>2022-02-09T14:56:04.220000Z</updated><subtitle>Recent posts to How to run a python script with codesys GUI</subtitle><entry><title>How to run a python script with codesys GUI</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/371c692c9c/?limit=25#f261" rel="alternate"/><published>2022-02-09T14:56:04.220000Z</published><updated>2022-02-09T14:56:04.220000Z</updated><author><name>snguyen</name><uri>https://forge.codesys.com/u/snguyen/</uri></author><id>https://forge.codesys.com7ff9d72de58206085129f555ce4f3e8c026773b7</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi, I do not know if there is a specific library for this, but you can run linux command line from CodeSys, meaning you can call your python script too.&lt;/p&gt;
&lt;p&gt;First, you need to edit a codesys file in the RPI to allow codesys to run command lines :&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;sudo mousepad /etc/CODESYSControl.cfg&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;in the file "CODESYSControl.cfg", add this :&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;[SysProcess]&lt;/span&gt;
&lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;AllowAll&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Then, in CodeSys, you need the have the SysProcess library in your project. You can then call your python script as follows :&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;commandString&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="s1"&gt;'python yourScript.py'&lt;/span&gt; &lt;span class="o"&gt;(*&lt;/span&gt;&lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt; &lt;span class="n"&gt;console&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt;&lt;span class="o"&gt;*)&lt;/span&gt;
&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;(*&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="o"&gt;*)&lt;/span&gt;
&lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="n"&gt;Sysprocess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;RTS_IEC_RESULT&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;(*&lt;/span&gt;&lt;span class="n"&gt;This&lt;/span&gt; &lt;span class="n"&gt;returns&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;something&lt;/span&gt; &lt;span class="n"&gt;was&lt;/span&gt; &lt;span class="n"&gt;wrong&lt;/span&gt;&lt;span class="o"&gt;*)&lt;/span&gt;
&lt;span class="o"&gt;---------------&lt;/span&gt;
&lt;span class="n"&gt;SysProcess&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;SysProcessExecuteCommand2&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pszCommand&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="n"&gt;commandString&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pszStdOut&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;udiStdOutLen&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;SIZEOF&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;&lt;span class="n"&gt;pResult&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Note that the CodeSys cycle will stop until the command has return. If your script takes time, you can either add '&amp;amp;' at the end of your command so the function returns immediately and the script runs in background (but you won't have your return string), or put your call in a separate core (codesys can use 4 core on the RPI, meaning 4 simultaneous code running)&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to run a python script with codesys GUI</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/371c692c9c/?limit=25#c2d1" rel="alternate"/><published>2022-02-09T13:26:03.390000Z</published><updated>2022-02-09T13:26:03.390000Z</updated><author><name>ramas</name><uri>https://forge.codesys.com/u/ramas/</uri></author><id>https://forge.codesys.com2089140a010b16928af770743cb3afe4c0e7e59a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Could someone share their knowledge in this topic please, Thank you&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>How to run a python script with codesys GUI</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/371c692c9c/?limit=25#16de" rel="alternate"/><published>2022-02-09T13:23:48.926000Z</published><updated>2022-02-09T13:23:48.926000Z</updated><author><name>ramas</name><uri>https://forge.codesys.com/u/ramas/</uri></author><id>https://forge.codesys.com9b2a54f17d96ded6e45e57a3fddbe31cccaead9e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hey Guys, &lt;br/&gt;
I am very new to Codesys i find it very useful for PLC applications.&lt;br/&gt;
I have designed the GUI for an appplication in Codesys how do I relate the GUI to a python script.&lt;br/&gt;
For example: I have a button or a bunch of buttons designed through codesys. These buttons when clicked should call python functions. This application will be run on a Raspberry pie as the PLC. &lt;br/&gt;
I really could not find any material online to do such a thing. COuld someone help me and point me in the right direction maybe show me an example or post a link maybe for reference.&lt;/p&gt;
&lt;p&gt;Thank you in advance.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>