Runtime/win32: no sys.stdout with pythonw.exe
--- a/Beremiz_service.py Mon Aug 07 18:17:12 2023 +0200
+++ b/Beremiz_service.py Thu Sep 28 17:56:03 2023 +0200
@@ -558,8 +558,9 @@
# Beremiz IDE detects LOCAL:// runtime is ready by looking
# for self.workdir in the daemon's stdout.
- sys.stdout.write(_("Current working directory :") + WorkingDir + "\n")
+ sys.stdout.write(_("Current working directory :") + WorkingDir + "\n") runtime.GetPLCObjectSingleton().AutoLoad(autostart)
--- a/exemples/python/plc.xml Mon Aug 07 18:17:12 2023 +0200
+++ b/exemples/python/plc.xml Thu Sep 28 17:56:03 2023 +0200
@@ -1,1678 +1,1678 @@
-<?xml version='1.0' encoding='utf-8'?>
-<project xmlns="http://www.plcopen.org/xml/tc6_0201" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.plcopen.org/xml/tc6_0201">
- <fileHeader companyName="" productName="Beremiz" productVersion="0.0" creationDateTime="2008-12-14T16:21:19" contentDescription="This example shows many features in Beremiz: 1. How to implement python extensions. 2. How to implement basic C extension. 3. How to use C code in IEC POUs. 4. How to call C functions from python code. 5. How to avoid race conditions between IEC, C and python code. 6. How to convert betweet different IEC types. "/>
- <contentHeader name="Beremiz Python Support Tests" modificationDateTime="2022-07-03T16:04:31">
- <pageSize x="1024" y="1024"/>
- <dataType name="CPLX_TYPE">
- <variable name="FIRSTBYTE">
- <variable name="SECONDBYTE">
- <dataType name="StateMachine">
- <value name="STANDBY"/>
- <dataType name="datatype0">
- <dataType name="blups">
- <dimension lower="0" upper="31"/>
- <derived name="CPLX_TYPE"/>
- <pou name="main_pytest" pouType="program">
- <variable name="mux1_sel">
- <simpleValue value="3"/>
- <xhtml:p><![CDATA[blah]]></xhtml:p>
- <variable name="mux2_sel">
- <simpleValue value="3"/>
- <variable name="pytest_var1">
- <variable name="fefvsd">
- <derived name="datatype0"/>
- <variable name="pytest_var2">
- <derived name="python_eval"/>
- <variable name="Block1">
- <derived name="python_eval"/>
- <variable name="Block2">
- <derived name="python_eval"/>
- <variable name="Block3">
- <derived name="python_eval"/>
- <variable name="pytest_var3">
- <variable name="FromC">
- <variable name="C_Pragma0">
- <derived name="C_Pragma"/>
- <variable name="TestInput">
- <variable name="TestOutput">
- <variable name="FromInput">
- <variable name="Test_BCD">
- <simpleValue value="151"/>
- <variable name="Test_BCD_WRONG">
- <simpleValue value="154"/>
- <variable name="Test_BCD_CONVERTED">
- <variable name="Test_BCD_RESULT">
- <variable name="Test_BCD_WRONG_RESULT">
- <variable name="Test_DT">
- <simpleValue value="DT#2013-02-23-22:35:46"/>
- <variable name="Test_TOD">
- <variable name="Test_TOD_STRING">
- <variable name="Test_Date">
- <variable name="Test_String">
- <simpleValue value="test"/>
- <variable name="Test_Bool">
- <variable name="Global_RS">
- <variable name="Test_Python_Var">
- <variable name="Second_Python_Var">
- <variable name="Grumpf">
- <variable name="SomeVarName">
- <inVariable localId="4" height="30" width="315" executionOrderId="0" negated="false">
- <position x="200" y="390"/>
- <relPosition x="315" y="15"/>
- <expression>'sys.stdout.write("Hello world\n")'</expression>
- <block localId="5" width="125" height="80" typeName="python_eval" instanceName="py1" executionOrderId="0">
- <position x="686" y="400"/>
- <variable formalParameter="TRIG">
- <relPosition x="0" y="35"/>
- <connection refLocalId="7" formalParameter="OUT">
- <position x="686" y="435"/>
- <position x="285" y="435"/>
- <position x="285" y="480"/>
- <position x="250" y="480"/>
- <variable formalParameter="CODE">
- <relPosition x="0" y="65"/>
- <connection refLocalId="80" formalParameter="OUT">
- <position x="686" y="465"/>
- <position x="653" y="465"/>
- <position x="653" y="485"/>
- <position x="630" y="485"/>
- <variable formalParameter="ACK">
- <relPosition x="125" y="35"/>
- <variable formalParameter="RESULT">
- <relPosition x="125" y="65"/>
- <block localId="7" width="70" height="45" typeName="NOT" executionOrderId="0">
- <position x="180" y="450"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="30"/>
- <connection refLocalId="3">
- <position x="180" y="480"/>
- <position x="155" y="480"/>
- <variable formalParameter="OUT">
- <relPosition x="70" y="30"/>
- <inOutVariable localId="3" height="30" width="120" executionOrderId="0" negatedOut="false" negatedIn="false">
- <position x="35" y="465"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="7" formalParameter="OUT">
- <position x="35" y="480"/>
- <position x="25" y="480"/>
- <position x="25" y="440"/>
- <position x="270" y="440"/>
- <position x="270" y="480"/>
- <position x="250" y="480"/>
- <relPosition x="120" y="15"/>
- <expression>pytest_var2</expression>
- <block localId="8" width="125" height="80" typeName="python_eval" instanceName="Block1" executionOrderId="0">
- <position x="686" y="545"/>
- <variable formalParameter="TRIG">
- <relPosition x="0" y="35"/>
- <connection refLocalId="7" formalParameter="OUT">
- <position x="686" y="580"/>
- <position x="285" y="580"/>
- <position x="285" y="480"/>
- <position x="250" y="480"/>
- <variable formalParameter="CODE">
- <relPosition x="0" y="65"/>
- <connection refLocalId="9">
- <position x="686" y="610"/>
- <position x="665" y="610"/>
- <variable formalParameter="ACK">
- <relPosition x="125" y="35"/>
- <variable formalParameter="RESULT">
- <relPosition x="125" y="65"/>
- <inVariable localId="9" height="30" width="370" executionOrderId="0" negated="false">
- <position x="295" y="595"/>
- <relPosition x="370" y="15"/>
- <expression>'sys.stdout.write("FBID :"+str(FBID)+"\n")'</expression>
- <inVariable localId="11" height="30" width="290" executionOrderId="0" negated="false">
- <position x="295" y="735"/>
- <relPosition x="290" y="15"/>
- <expression>'PLCBinary.Simple_C_Call(5678)'</expression>
- <block localId="12" width="125" height="80" typeName="python_eval" instanceName="Block2" executionOrderId="0">
- <position x="686" y="687"/>
- <variable formalParameter="TRIG">
- <relPosition x="0" y="33"/>
- <connection refLocalId="7" formalParameter="OUT">
- <position x="686" y="720"/>
- <position x="285" y="720"/>
- <position x="285" y="480"/>
- <position x="250" y="480"/>
- <variable formalParameter="CODE">
- <relPosition x="0" y="63"/>
- <connection refLocalId="11">
- <position x="686" y="750"/>
- <position x="585" y="750"/>
- <variable formalParameter="ACK">
- <relPosition x="125" y="33"/>
- <variable formalParameter="RESULT">
- <relPosition x="125" y="63"/>
- <inVariable localId="14" height="30" width="290" executionOrderId="0" negated="false">
- <position x="290" y="885"/>
- <relPosition x="290" y="15"/>
- <expression>'MyPythonFunc(42)'</expression>
- <block localId="15" width="125" height="80" typeName="python_eval" instanceName="Block3" executionOrderId="0">
- <position x="686" y="837"/>
- <variable formalParameter="TRIG">
- <relPosition x="0" y="33"/>
- <connection refLocalId="7" formalParameter="OUT">
- <position x="686" y="870"/>
- <position x="285" y="870"/>
- <position x="285" y="480"/>
- <position x="250" y="480"/>
- <variable formalParameter="CODE">
- <relPosition x="0" y="63"/>
- <connection refLocalId="14">
- <position x="686" y="900"/>
- <position x="580" y="900"/>
- <variable formalParameter="ACK">
- <relPosition x="125" y="33"/>
- <variable formalParameter="RESULT">
- <relPosition x="125" y="63"/>
- <comment localId="16" height="90" width="680">
- <position x="35" y="275"/>
- <xhtml:p><![CDATA[This part of the example test that, despite of 2T period clock stimulating TRIG pin of pyth_eval blocks, blocks keep executing one after the other, in respect of execution order.]]></xhtml:p>
- <block localId="17" width="80" height="120" typeName="MUX" executionOrderId="0">
- <position x="1101" y="790"/>
- <variable formalParameter="K">
- <relPosition x="0" y="30"/>
- <connection refLocalId="18">
- <position x="1101" y="820"/>
- <position x="1076" y="820"/>
- <position x="1076" y="810"/>
- <position x="1060" y="810"/>
- <variable formalParameter="IN0">
- <relPosition x="0" y="50"/>
- <connection refLocalId="5" formalParameter="RESULT">
- <position x="1101" y="840"/>
- <position x="941" y="840"/>
- <position x="941" y="465"/>
- <position x="811" y="465"/>
- <variable formalParameter="IN1">
- <relPosition x="0" y="70"/>
- <connection refLocalId="8" formalParameter="RESULT">
- <position x="1101" y="860"/>
- <position x="926" y="860"/>
- <position x="926" y="610"/>
- <position x="811" y="610"/>
- <variable formalParameter="IN2">
- <relPosition x="0" y="90"/>
- <connection refLocalId="12" formalParameter="RESULT">
- <position x="1101" y="880"/>
- <position x="911" y="880"/>
- <position x="911" y="750"/>
- <position x="811" y="750"/>
- <variable formalParameter="IN3">
- <relPosition x="0" y="110"/>
- <connection refLocalId="15" formalParameter="RESULT">
- <position x="1101" y="900"/>
- <position x="811" y="900"/>
- <variable formalParameter="OUT">
- <relPosition x="80" y="30"/>
- <outVariable localId="19" height="35" width="125" executionOrderId="0" negated="false">
- <position x="1271" y="805"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="17" formalParameter="OUT">
- <position x="1271" y="820"/>
- <position x="1181" y="820"/>
- <expression>pytest_var1</expression>
- <block localId="21" width="80" height="120" typeName="MUX" executionOrderId="0">
- <position x="1106" y="385"/>
- <variable formalParameter="K">
- <relPosition x="0" y="30"/>
- <connection refLocalId="22">
- <position x="1106" y="415"/>
- <position x="1076" y="415"/>
- <position x="1076" y="405"/>
- <position x="1055" y="405"/>
- <variable formalParameter="IN0">
- <relPosition x="0" y="50"/>
- <connection refLocalId="5" formalParameter="ACK">
- <position x="1106" y="435"/>
- <position x="811" y="435"/>
- <variable formalParameter="IN1">
- <relPosition x="0" y="70"/>
- <connection refLocalId="8" formalParameter="ACK">
- <position x="1106" y="455"/>
- <position x="841" y="455"/>
- <position x="841" y="580"/>
- <position x="811" y="580"/>
- <variable formalParameter="IN2">
- <relPosition x="0" y="90"/>
- <connection refLocalId="12" formalParameter="ACK">
- <position x="1106" y="475"/>
- <position x="856" y="475"/>
- <position x="856" y="720"/>
- <position x="811" y="720"/>
- <variable formalParameter="IN3">
- <relPosition x="0" y="110"/>
- <connection refLocalId="15" formalParameter="ACK">
- <position x="1106" y="495"/>
- <position x="871" y="495"/>
- <position x="871" y="870"/>
- <position x="811" y="870"/>
- <variable formalParameter="OUT">
- <relPosition x="80" y="30"/>
- <inVariable localId="22" height="30" width="74" executionOrderId="0" negated="false">
- <position x="981" y="390"/>
- <relPosition x="74" y="15"/>
- <expression>mux1_sel</expression>
- <outVariable localId="23" height="35" width="125" executionOrderId="0" negated="false">
- <position x="1271" y="400"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="21" formalParameter="OUT">
- <position x="1271" y="415"/>
- <position x="1186" y="415"/>
- <expression>pytest_var3</expression>
- <outVariable localId="25" height="30" width="60" executionOrderId="0" negated="false">
- <position x="320" y="1075"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="26" formalParameter="OUT">
- <position x="320" y="1090"/>
- <position x="265" y="1090"/>
- <expression>FromC</expression>
- <inVariable localId="1" height="30" width="30" executionOrderId="0" negated="false">
- <position x="105" y="1075"/>
- <relPosition x="30" y="15"/>
- <expression>23</expression>
- <block localId="26" width="80" height="45" typeName="C_Pragma" instanceName="C_Pragma0" executionOrderId="0">
- <position x="185" y="1060"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="30"/>
- <connection refLocalId="1">
- <position x="185" y="1090"/>
- <position x="135" y="1090"/>
- <variable formalParameter="OUT">
- <relPosition x="80" y="30"/>
- <inVariable localId="27" height="30" width="90" executionOrderId="0" negated="false">
- <position x="100" y="1190"/>
- <relPosition x="90" y="15"/>
- <expression>TestInput</expression>
- <outVariable localId="28" height="30" width="105" executionOrderId="0" negated="false">
- <position x="195" y="1125"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="2">
- <position x="195" y="1140"/>
- <position x="140" y="1140"/>
- <expression>TestOutput</expression>
- <outVariable localId="29" height="30" width="85" executionOrderId="0" negated="false">
- <position x="215" y="1190"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="27">
- <position x="215" y="1205"/>
- <position x="190" y="1205"/>
- <expression>FromInput</expression>
- <inVariable localId="2" height="30" width="30" executionOrderId="0" negated="false">
- <position x="110" y="1125"/>
- <relPosition x="30" y="15"/>
- <expression>10</expression>
- <comment localId="30" height="105" width="465">
- <position x="50" y="925"/>
- <xhtml:p><![CDATA[You will be ready to use beremiz with C and Python when you will understand why "FromInput" is equal to 75.
-Happy hacking! ]]></xhtml:p>
- <comment localId="6" height="80" width="345">
- <position x="295" y="630"/>
- <xhtml:p><![CDATA[Prints FBID to stdout of PLC runtime. FBID is a unique reference to py_eval instance.]]></xhtml:p>
- <comment localId="10" height="85" width="345">
- <position x="295" y="770"/>
- <xhtml:p><![CDATA[Simple_C_Call is declared in C_File "1.x:c_code". See python ctypes manual for details on typing.]]></xhtml:p>
- <comment localId="32" height="145" width="235">
- <position x="25" y="505"/>
- <xhtml:p><![CDATA[Fast clock, at least faster that sleep(1). See what happens when python takes time to answer : PLC continues.]]></xhtml:p>
- <outVariable localId="33" height="30" width="133" executionOrderId="0" negated="false">
- <position x="580" y="1564"/>
- <relPosition x="0" y="16"/>
- <connection refLocalId="35" formalParameter="OUT">
- <position x="580" y="1580"/>
- <position x="371" y="1580"/>
- <expression>Test_BCD_RESULT</expression>
- <inVariable localId="34" height="30" width="75" executionOrderId="0" negated="false">
- <position x="60" y="1564"/>
- <relPosition x="75" y="16"/>
- <expression>Test_BCD</expression>
- <block localId="35" width="106" height="60" typeName="BCD_TO_UINT" executionOrderId="0">
- <position x="265" y="1539"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="41"/>
- <connection refLocalId="34">
- <position x="265" y="1580"/>
- <position x="135" y="1580"/>
- <variable formalParameter="OUT">
- <relPosition x="106" y="41"/>
- <inVariable localId="36" height="30" width="66" executionOrderId="0" negated="false">
- <position x="60" y="1774"/>
- <relPosition x="66" y="16"/>
- <expression>Test_DT</expression>
- <block localId="37" width="255" height="45" typeName="DATE_AND_TIME_TO_TIME_OF_DAY" executionOrderId="0">
- <position x="265" y="1759"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="31"/>
- <connection refLocalId="36">
- <position x="265" y="1790"/>
- <position x="125" y="1790"/>
- <variable formalParameter="OUT">
- <relPosition x="255" y="31"/>
- <block localId="38" width="195" height="45" typeName="DATE_AND_TIME_TO_DATE" executionOrderId="0">
- <position x="265" y="1834"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="31"/>
- <connection refLocalId="36">
- <position x="265" y="1865"/>
- <position x="242" y="1865"/>
- <position x="242" y="1790"/>
- <position x="125" y="1790"/>
- <variable formalParameter="OUT">
- <relPosition x="195" y="31"/>
- <outVariable localId="40" height="30" width="82" executionOrderId="0" negated="false">
- <position x="580" y="1849"/>
- <relPosition x="0" y="16"/>
- <connection refLocalId="38" formalParameter="OUT">
- <position x="580" y="1865"/>
- <position x="460" y="1865"/>
- <expression>Test_Date</expression>
- <outVariable localId="42" height="30" width="98" executionOrderId="0" negated="false">
- <position x="465" y="1944"/>
- <relPosition x="0" y="16"/>
- <connection refLocalId="46" formalParameter="OUT">
- <position x="465" y="1960"/>
- <position x="395" y="1960"/>
- <expression>Test_String</expression>
- <outVariable localId="43" height="30" width="82" executionOrderId="0" negated="false">
- <position x="465" y="2014"/>
- <relPosition x="0" y="16"/>
- <connection refLocalId="44" formalParameter="OUT">
- <position x="465" y="2030"/>
- <position x="400" y="2030"/>
- <expression>Test_Bool</expression>
- <block localId="44" width="135" height="45" typeName="STRING_TO_BOOL" executionOrderId="0">
- <position x="265" y="1999"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="31"/>
- <connection refLocalId="45">
- <position x="265" y="2030"/>
- <position x="115" y="2030"/>
- <variable formalParameter="OUT">
- <relPosition x="135" y="31"/>
- <inVariable localId="45" height="30" width="58" executionOrderId="0" negated="false">
- <position x="60" y="2014"/>
- <relPosition x="58" y="16"/>
- <expression>'True'</expression>
- <block localId="46" width="130" height="45" typeName="INT_TO_STRING" executionOrderId="0">
- <position x="265" y="1929"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="31"/>
- <connection refLocalId="58">
- <position x="265" y="1960"/>
- <position x="205" y="1960"/>
- <variable formalParameter="OUT">
- <relPosition x="130" y="31"/>
- <inVariable localId="50" height="30" width="106" executionOrderId="0" negated="false">
- <position x="75" y="2275"/>
- <relPosition x="106" y="15"/>
- <expression>Global_RS.Q1</expression>
- <block localId="51" width="70" height="85" typeName="AND" executionOrderId="0">
- <position x="240" y="2255"/>
- <variable formalParameter="IN1" negated="true">
- <relPosition x="0" y="35"/>
- <connection refLocalId="50">
- <position x="240" y="2290"/>
- <position x="180" y="2290"/>
- <variable formalParameter="IN2">
- <relPosition x="0" y="70"/>
- <connection refLocalId="52">
- <position x="240" y="2325"/>
- <position x="180" y="2325"/>
- <variable formalParameter="OUT">
- <relPosition x="70" y="35"/>
- <inVariable localId="52" height="30" width="105" executionOrderId="0" negated="false">
- <position x="75" y="2310"/>
- <relPosition x="105" y="15"/>
- <expression>BOOL#TRUE</expression>
- <outVariable localId="13" height="30" width="105" executionOrderId="0" negated="false">
- <position x="385" y="2275"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="51" formalParameter="OUT">
- <position x="385" y="2290"/>
- <position x="310" y="2290"/>
- <expression>Global_RS.S</expression>
- <outVariable localId="20" height="30" width="106" executionOrderId="0" negated="false">
- <position x="385" y="2390"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="41" formalParameter="OUT">
- <position x="385" y="2405"/>
- <position x="310" y="2405"/>
- <expression>Global_RS.R1</expression>
- <inVariable localId="24" height="30" width="106" executionOrderId="0" negated="false">
- <position x="75" y="2390"/>
- <relPosition x="106" y="15"/>
- <expression>Global_RS.Q1</expression>
- <block localId="41" width="70" height="85" typeName="OR" executionOrderId="0">
- <position x="240" y="2370"/>
- <variable formalParameter="IN1">
- <relPosition x="0" y="35"/>
- <connection refLocalId="24">
- <position x="240" y="2405"/>
- <position x="180" y="2405"/>
- <variable formalParameter="IN2">
- <relPosition x="0" y="70"/>
- <connection refLocalId="48">
- <position x="240" y="2440"/>
- <position x="180" y="2440"/>
- <variable formalParameter="OUT">
- <relPosition x="70" y="35"/>
- <inVariable localId="48" height="30" width="105" executionOrderId="0" negated="false">
- <position x="75" y="2425"/>
- <relPosition x="105" y="15"/>
- <expression>BOOL#FALSE</expression>
- <outVariable localId="54" height="30" width="135" executionOrderId="0" negated="false">
- <position x="930" y="1774"/>
- <relPosition x="0" y="16"/>
- <connection refLocalId="55" formalParameter="OUT">
- <position x="930" y="1790"/>
- <position x="855" y="1790"/>
- <expression>Test_TOD_STRING</expression>
- <block localId="55" width="125" height="45" typeName="TOD_TO_STRING" executionOrderId="0">
- <position x="730" y="1759"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="31"/>
- <connection refLocalId="39">
- <position x="730" y="1790"/>
- <position x="655" y="1790"/>
- <variable formalParameter="OUT">
- <relPosition x="125" y="31"/>
- <inOutVariable localId="39" height="30" width="75" executionOrderId="0" negatedOut="false" negatedIn="false">
- <position x="580" y="1774"/>
- <relPosition x="0" y="16"/>
- <connection refLocalId="37" formalParameter="OUT">
- <position x="580" y="1790"/>
- <position x="520" y="1790"/>
- <relPosition x="75" y="16"/>
- <expression>Test_TOD</expression>
- <inVariable localId="49" height="30" width="30" executionOrderId="0" negated="false">
- <position x="160" y="2510"/>
- <relPosition x="30" y="15"/>
- <expression>42</expression>
- <outVariable localId="57" height="30" width="50" executionOrderId="0" negated="false">
- <position x="240" y="2510"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="49">
- <position x="240" y="2525"/>
- <position x="190" y="2525"/>
- <expression>TOTO</expression>
- <outVariable localId="56" height="30" width="50" executionOrderId="0" negated="false">
- <position x="240" y="2550"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="49">
- <position x="240" y="2565"/>
- <position x="215" y="2565"/>
- <position x="215" y="2525"/>
- <position x="190" y="2525"/>
- <expression>TUTU</expression>
- <inVariable localId="58" height="30" width="146" executionOrderId="0" negated="false">
- <position x="60" y="1944"/>
- <relPosition x="146" y="16"/>
- <expression>Second_Python_Var</expression>
- <inVariable localId="59" height="30" width="30" executionOrderId="0" negated="false">
- <position x="100" y="1385"/>
- <relPosition x="30" y="15"/>
- <expression>1</expression>
- <block localId="61" typeName="function0" executionOrderId="0" height="45" width="111">
- <position x="760" y="1170"/>
- <variable formalParameter="LocalVar0">
- <relPosition x="0" y="30"/>
- <connection refLocalId="62">
- <position x="760" y="1200"/>
- <position x="723" y="1200"/>
- <variable formalParameter="OUT">
- <relPosition x="111" y="30"/>
- <inVariable localId="62" executionOrderId="0" height="30" width="58" negated="false">
- <position x="665" y="1185"/>
- <relPosition x="58" y="15"/>
- <expression>fefvsd</expression>
- <outVariable localId="63" executionOrderId="0" height="30" width="58" negated="false">
- <position x="905" y="1185"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="61" formalParameter="OUT">
- <position x="905" y="1200"/>
- <position x="871" y="1200"/>
- <expression>fefvsd</expression>
- <comment localId="53" height="80" width="420">
- <position x="75" y="2160"/>
- <xhtml:p><![CDATA[Shows global variables access from resource configuration (res_pytest) and from project's configuration.]]></xhtml:p>
- <inVariable localId="18" height="30" width="74" executionOrderId="0" negated="false">
- <position x="986" y="795"/>
- <relPosition x="74" y="15"/>
- <expression>mux2_sel</expression>
- <comment localId="60" height="45" width="930">
- <position x="60" y="1480"/>
- <xhtml:p><![CDATA[Here is shown how to convert values between different types (BCD, DT, TOD, STRING and others) using standard functions.]]></xhtml:p>
- <comment localId="64" height="55" width="300">
- <position x="665" y="1095"/>
- <xhtml:p><![CDATA[Example of usage of user-defined function.]]></xhtml:p>
- <comment localId="65" height="45" width="410">
- <position x="55" y="1315"/>
- <xhtml:p><![CDATA[Shows access variable defined in python extension. ]]></xhtml:p>
- <inVariable localId="66" height="30" width="137" executionOrderId="0" negated="false">
- <position x="60" y="1685"/>
- <relPosition x="137" y="15"/>
- <expression>Test_BCD_WRONG</expression>
- <block localId="67" width="106" height="100" typeName="BCD_TO_UINT" executionOrderId="0">
- <position x="265" y="1620"/>
- <variable formalParameter="EN">
- <relPosition x="0" y="40"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="80"/>
- <connection refLocalId="66">
- <position x="265" y="1700"/>
- <position x="255" y="1700"/>
- <position x="255" y="1700"/>
- <position x="345" y="1700"/>
- <position x="345" y="1700"/>
- <position x="197" y="1700"/>
- <variable formalParameter="ENO">
- <relPosition x="106" y="40"/>
- <variable formalParameter="OUT">
- <relPosition x="106" y="80"/>
- <outVariable localId="68" height="30" width="196" executionOrderId="0" negated="false">
- <position x="580" y="1685"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="67" formalParameter="OUT">
- <position x="580" y="1700"/>
- <position x="371" y="1700"/>
- <expression>Test_BCD_WRONG_RESULT</expression>
- <comment localId="69" height="165" width="375">
- <position x="795" y="1590"/>
- <xhtml:p><![CDATA[Incorrect BCD number is not converted to UINT.
-151 (16#97) is good BCD number , but
-Try this out and look at value of Test_BCD_CONVERTED variable.
- <outVariable localId="70" height="30" width="185" executionOrderId="0" negated="false">
- <position x="580" y="1645"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="67" formalParameter="ENO">
- <position x="580" y="1660"/>
- <position x="370" y="1660"/>
- <expression>Test_BCD_CONVERTED</expression>
- <comment localId="71" height="215" width="680">
- <position x="35" y="30"/>
- <xhtml:p><![CDATA[This example shows many features in Beremiz:
- 1. How to implement python extensions.
- 2. How to implement basic C extension.
- 3. How to use C code in IEC POUs.
- 4. How to call C functions from python code.
- 5. How to avoid race conditions between IEC, C and python code.
- 6. How to convert betweet different IEC types.
- <outVariable localId="72" executionOrderId="0" height="30" width="60" negated="false">
- <position x="1065" y="1970"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="76" formalParameter="OUT">
- <position x="1065" y="1985"/>
- <position x="1025" y="1985"/>
- <position x="1025" y="1995"/>
- <position x="985" y="1995"/>
- <expression>Grumpf</expression>
- <inVariable localId="73" executionOrderId="0" height="30" width="85" negated="false">
- <position x="625" y="1940"/>
- <relPosition x="85" y="15"/>
- <expression>BOOL#TRUE</expression>
- <inVariable localId="74" executionOrderId="0" height="30" width="70" negated="false">
- <position x="625" y="1975"/>
- <relPosition x="70" y="15"/>
- <expression>Test_DT</expression>
- <block localId="75" typeName="RTC" instanceName="RTC0" executionOrderId="0" height="90" width="65">
- <position x="760" y="1925"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="35"/>
- <connection refLocalId="73">
- <position x="760" y="1960"/>
- <position x="735" y="1960"/>
- <position x="735" y="1955"/>
- <position x="710" y="1955"/>
- <variable formalParameter="PDT">
- <relPosition x="0" y="70"/>
- <connection refLocalId="74">
- <position x="760" y="1995"/>
- <position x="727" y="1995"/>
- <position x="727" y="1990"/>
- <position x="695" y="1990"/>
- <variable formalParameter="Q">
- <relPosition x="65" y="35"/>
- <variable formalParameter="CDT">
- <relPosition x="65" y="70"/>
- <block localId="76" typeName="DT_TO_STRING" executionOrderId="0" height="40" width="110">
- <position x="875" y="1965"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="30"/>
- <connection refLocalId="75" formalParameter="CDT">
- <position x="875" y="1995"/>
- <position x="825" y="1995"/>
- <variable formalParameter="OUT">
- <relPosition x="110" y="30"/>
- <block localId="77" typeName="ADD" executionOrderId="0" height="60" width="65">
- <position x="170" y="1370"/>
- <variable formalParameter="IN1">
- <relPosition x="0" y="30"/>
- <connection refLocalId="59">
- <position x="170" y="1400"/>
- <position x="130" y="1400"/>
- <variable formalParameter="IN2">
- <relPosition x="0" y="50"/>
- <connection refLocalId="78">
- <position x="170" y="1420"/>
- <position x="160" y="1420"/>
- <position x="160" y="1450"/>
- <position x="390" y="1450"/>
- <position x="390" y="1400"/>
- <position x="380" y="1400"/>
- <variable formalParameter="OUT">
- <relPosition x="65" y="30"/>
- <outVariable localId="47" executionOrderId="0" height="30" width="130" negated="false">
- <position x="625" y="1335"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="79">
- <position x="625" y="1350"/>
- <position x="590" y="1350"/>
- <expression>Test_Python_Var</expression>
- <inVariable localId="79" executionOrderId="0" height="27" width="30" negated="false">
- <position x="560" y="1340"/>
- <relPosition x="30" y="15"/>
- <expression>23</expression>
- <inOutVariable localId="78" executionOrderId="0" height="30" width="100" negatedOut="false" negatedIn="false">
- <position x="280" y="1385"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="77" formalParameter="OUT">
- <position x="280" y="1400"/>
- <position x="235" y="1400"/>
- <relPosition x="100" y="15"/>
- <expression>SomeVarName</expression>
- <block localId="80" typeName="MOVE" executionOrderId="0" height="40" width="60">
- <position x="570" y="455"/>
- <variable formalParameter="IN">
- <relPosition x="0" y="30"/>
- <connection refLocalId="82">
- <position x="578" y="485"/>
- <position x="532" y="485"/>
- <variable formalParameter="OUT">
- <relPosition x="60" y="30"/>
- <connector name="Connection0" localId="81" height="30" width="130">
- <position x="545" y="390"/>
- <relPosition x="0" y="15"/>
- <connection refLocalId="4">
- <position x="545" y="405"/>
- <position x="515" y="405"/>
- <continuation name="Connection0" localId="82" height="30" width="130">
- <position x="410" y="470"/>
- <relPosition x="130" y="15"/>
- <pou name="C_Pragma" pouType="functionBlock">
- <variable name="COORDS">
- <dimension lower="0" upper="5"/>
- <simpleValue value="54"/>
- <simpleValue value="55"/>
- <simpleValue value="56"/>
- <simpleValue value="57"/>
- <simpleValue value="58"/>
- <simpleValue value="59"/>
- <variable name="SMURF">
- <derived name="CPLX_TYPE"/>
- <variable name="Global_RS">
- <variable name="Dudiduda">
- <derived name="blups"/>
- <xhtml:p><![CDATA[(* hereafter is a C pragma accessing FB interface in a clean way *)
- char fromPLC = GetFbVar(IN);
- extern int PLC_C_Call(char, char *);
- if(PLC_C_Call(fromPLC, &toPLC)){
- /* that code demonstrate C access to complex types */
- char somebyte = GetFbVar(COORDS, .table[3]);
- SetFbVar(SMURF, somebyte, .FIRSTBYTE);
- SetFbVar(COORDS, somebyte, .table[4]);
-(* If you do not use GetFbVar and SetFbVar macros, expect unexpected behaviour*)
-(* testing access to global struct array *)
-Dudiduda[2].FIRSTBYTE := 0;
- <pou name="norm" pouType="function">
- <xhtml:p><![CDATA[NORM := SQRT(IN1 * IN1 + IN2 * IN2);]]></xhtml:p>
- <pou name="function0" pouType="function">
- <derived name="datatype0"/>
- <variable name="LocalVar0">
- <derived name="datatype0"/>
- <xhtml:p><![CDATA[function0 := LocalVar0;
- <configuration name="config">
- <resource name="res_pytest">
- <task name="pytest_task" priority="0" interval="T#500ms"/>
- <pouInstance name="pytest_instance" typeName="main_pytest"/>
- <variable name="Global_RS">
- <variable name="Dudiduda">
- <derived name="blups"/>
+<?xml version='1.0' encoding='utf-8'?> +<project xmlns="http://www.plcopen.org/xml/tc6_0201" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.plcopen.org/xml/tc6_0201"> + <fileHeader companyName="" productName="Beremiz" productVersion="0.0" creationDateTime="2008-12-14T16:21:19" contentDescription="This example shows many features in Beremiz: 1. How to implement python extensions. 2. How to implement basic C extension. 3. How to use C code in IEC POUs. 4. How to call C functions from python code. 5. How to avoid race conditions between IEC, C and python code. 6. How to convert betweet different IEC types. "/> + <contentHeader name="Beremiz Python Support Tests" modificationDateTime="2023-09-28T17:24:49"> + <pageSize x="1024" y="1024"/> + <dataType name="CPLX_TYPE"> + <variable name="FIRSTBYTE"> + <variable name="SECONDBYTE"> + <dataType name="StateMachine"> + <value name="STANDBY"/> + <dataType name="datatype0"> + <dataType name="blups"> + <dimension lower="0" upper="31"/> + <derived name="CPLX_TYPE"/> + <pou name="main_pytest" pouType="program"> + <variable name="mux1_sel"> + <simpleValue value="3"/> + <xhtml:p><![CDATA[blah]]></xhtml:p> + <variable name="mux2_sel"> + <simpleValue value="3"/> + <variable name="pytest_var1"> + <variable name="fefvsd"> + <derived name="datatype0"/> + <variable name="pytest_var2"> + <derived name="python_eval"/> + <variable name="Block1"> + <derived name="python_eval"/> + <variable name="Block2"> + <derived name="python_eval"/> + <variable name="Block3"> + <derived name="python_eval"/> + <variable name="pytest_var3"> + <variable name="FromC"> + <variable name="C_Pragma0"> + <derived name="C_Pragma"/> + <variable name="TestInput"> + <variable name="TestOutput"> + <variable name="FromInput"> + <variable name="Test_BCD"> + <simpleValue value="151"/> + <variable name="Test_BCD_WRONG"> + <simpleValue value="154"/> + <variable name="Test_BCD_CONVERTED"> + <variable name="Test_BCD_RESULT"> + <variable name="Test_BCD_WRONG_RESULT"> + <variable name="Test_DT"> + <simpleValue value="DT#2013-02-23-22:35:46"/> + <variable name="Test_TOD"> + <variable name="Test_TOD_STRING"> + <variable name="Test_Date"> + <variable name="Test_String"> + <simpleValue value="test"/> + <variable name="Test_Bool"> + <variable name="Global_RS"> + <variable name="Test_Python_Var"> + <variable name="Second_Python_Var"> + <variable name="Grumpf"> + <variable name="SomeVarName"> + <inVariable localId="4" height="30" width="315" executionOrderId="0" negated="false"> + <position x="200" y="390"/> + <relPosition x="315" y="15"/> + <expression>'MyPrintFunction("Hello world\n")'</expression> + <block localId="5" width="125" height="80" typeName="python_eval" instanceName="py1" executionOrderId="0"> + <position x="686" y="400"/> + <variable formalParameter="TRIG"> + <relPosition x="0" y="35"/> + <connection refLocalId="7" formalParameter="OUT"> + <position x="686" y="435"/> + <position x="285" y="435"/> + <position x="285" y="480"/> + <position x="250" y="480"/> + <variable formalParameter="CODE"> + <relPosition x="0" y="65"/> + <connection refLocalId="80" formalParameter="OUT"> + <position x="686" y="465"/> + <position x="653" y="465"/> + <position x="653" y="485"/> + <position x="630" y="485"/> + <variable formalParameter="ACK"> + <relPosition x="125" y="35"/> + <variable formalParameter="RESULT"> + <relPosition x="125" y="65"/> + <block localId="7" width="70" height="45" typeName="NOT" executionOrderId="0"> + <position x="180" y="450"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="3"> + <position x="180" y="480"/> + <position x="155" y="480"/> + <variable formalParameter="OUT"> + <relPosition x="70" y="30"/> + <inOutVariable localId="3" height="30" width="120" executionOrderId="0" negatedOut="false" negatedIn="false"> + <position x="35" y="465"/> + <relPosition x="0" y="15"/> + <connection refLocalId="7" formalParameter="OUT"> + <position x="35" y="480"/> + <position x="25" y="480"/> + <position x="25" y="440"/> + <position x="270" y="440"/> + <position x="270" y="480"/> + <position x="250" y="480"/> + <relPosition x="120" y="15"/> + <expression>pytest_var2</expression> + <block localId="8" width="125" height="80" typeName="python_eval" instanceName="Block1" executionOrderId="0"> + <position x="686" y="545"/> + <variable formalParameter="TRIG"> + <relPosition x="0" y="35"/> + <connection refLocalId="7" formalParameter="OUT"> + <position x="686" y="580"/> + <position x="285" y="580"/> + <position x="285" y="480"/> + <position x="250" y="480"/> + <variable formalParameter="CODE"> + <relPosition x="0" y="65"/> + <connection refLocalId="9"> + <position x="686" y="610"/> + <position x="665" y="610"/> + <variable formalParameter="ACK"> + <relPosition x="125" y="35"/> + <variable formalParameter="RESULT"> + <relPosition x="125" y="65"/> + <inVariable localId="9" height="30" width="370" executionOrderId="0" negated="false"> + <position x="295" y="595"/> + <relPosition x="370" y="15"/> + <expression>'MyPrintFunction("FBID :"+str(FBID)+"\n")'</expression> + <inVariable localId="11" height="30" width="290" executionOrderId="0" negated="false"> + <position x="295" y="735"/> + <relPosition x="290" y="15"/> + <expression>'PLCBinary.Simple_C_Call(5678)'</expression> + <block localId="12" width="125" height="80" typeName="python_eval" instanceName="Block2" executionOrderId="0"> + <position x="686" y="687"/> + <variable formalParameter="TRIG"> + <relPosition x="0" y="33"/> + <connection refLocalId="7" formalParameter="OUT"> + <position x="686" y="720"/> + <position x="285" y="720"/> + <position x="285" y="480"/> + <position x="250" y="480"/> + <variable formalParameter="CODE"> + <relPosition x="0" y="63"/> + <connection refLocalId="11"> + <position x="686" y="750"/> + <position x="585" y="750"/> + <variable formalParameter="ACK"> + <relPosition x="125" y="33"/> + <variable formalParameter="RESULT"> + <relPosition x="125" y="63"/> + <inVariable localId="14" height="30" width="290" executionOrderId="0" negated="false"> + <position x="290" y="885"/> + <relPosition x="290" y="15"/> + <expression>'MyPythonFunc(42)'</expression> + <block localId="15" width="125" height="80" typeName="python_eval" instanceName="Block3" executionOrderId="0"> + <position x="686" y="837"/> + <variable formalParameter="TRIG"> + <relPosition x="0" y="33"/> + <connection refLocalId="7" formalParameter="OUT"> + <position x="686" y="870"/> + <position x="285" y="870"/> + <position x="285" y="480"/> + <position x="250" y="480"/> + <variable formalParameter="CODE"> + <relPosition x="0" y="63"/> + <connection refLocalId="14"> + <position x="686" y="900"/> + <position x="580" y="900"/> + <variable formalParameter="ACK"> + <relPosition x="125" y="33"/> + <variable formalParameter="RESULT"> + <relPosition x="125" y="63"/> + <comment localId="16" height="90" width="680"> + <position x="35" y="275"/> + <xhtml:p><![CDATA[This part of the example test that, despite of 2T period clock stimulating TRIG pin of pyth_eval blocks, blocks keep executing one after the other, in respect of execution order.]]></xhtml:p> + <block localId="17" width="80" height="120" typeName="MUX" executionOrderId="0"> + <position x="1101" y="790"/> + <variable formalParameter="K"> + <relPosition x="0" y="30"/> + <connection refLocalId="18"> + <position x="1101" y="820"/> + <position x="1076" y="820"/> + <position x="1076" y="810"/> + <position x="1060" y="810"/> + <variable formalParameter="IN0"> + <relPosition x="0" y="50"/> + <connection refLocalId="5" formalParameter="RESULT"> + <position x="1101" y="840"/> + <position x="941" y="840"/> + <position x="941" y="465"/> + <position x="811" y="465"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="70"/> + <connection refLocalId="8" formalParameter="RESULT"> + <position x="1101" y="860"/> + <position x="926" y="860"/> + <position x="926" y="610"/> + <position x="811" y="610"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="90"/> + <connection refLocalId="12" formalParameter="RESULT"> + <position x="1101" y="880"/> + <position x="911" y="880"/> + <position x="911" y="750"/> + <position x="811" y="750"/> + <variable formalParameter="IN3"> + <relPosition x="0" y="110"/> + <connection refLocalId="15" formalParameter="RESULT"> + <position x="1101" y="900"/> + <position x="811" y="900"/> + <variable formalParameter="OUT"> + <relPosition x="80" y="30"/> + <outVariable localId="19" height="35" width="125" executionOrderId="0" negated="false"> + <position x="1271" y="805"/> + <relPosition x="0" y="15"/> + <connection refLocalId="17" formalParameter="OUT"> + <position x="1271" y="820"/> + <position x="1181" y="820"/> + <expression>pytest_var1</expression> + <block localId="21" width="80" height="120" typeName="MUX" executionOrderId="0"> + <position x="1106" y="385"/> + <variable formalParameter="K"> + <relPosition x="0" y="30"/> + <connection refLocalId="22"> + <position x="1106" y="415"/> + <position x="1076" y="415"/> + <position x="1076" y="405"/> + <position x="1055" y="405"/> + <variable formalParameter="IN0"> + <relPosition x="0" y="50"/> + <connection refLocalId="5" formalParameter="ACK"> + <position x="1106" y="435"/> + <position x="811" y="435"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="70"/> + <connection refLocalId="8" formalParameter="ACK"> + <position x="1106" y="455"/> + <position x="841" y="455"/> + <position x="841" y="580"/> + <position x="811" y="580"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="90"/> + <connection refLocalId="12" formalParameter="ACK"> + <position x="1106" y="475"/> + <position x="856" y="475"/> + <position x="856" y="720"/> + <position x="811" y="720"/> + <variable formalParameter="IN3"> + <relPosition x="0" y="110"/> + <connection refLocalId="15" formalParameter="ACK"> + <position x="1106" y="495"/> + <position x="871" y="495"/> + <position x="871" y="870"/> + <position x="811" y="870"/> + <variable formalParameter="OUT"> + <relPosition x="80" y="30"/> + <inVariable localId="22" height="30" width="74" executionOrderId="0" negated="false"> + <position x="981" y="390"/> + <relPosition x="74" y="15"/> + <expression>mux1_sel</expression> + <outVariable localId="23" height="35" width="125" executionOrderId="0" negated="false"> + <position x="1271" y="400"/> + <relPosition x="0" y="15"/> + <connection refLocalId="21" formalParameter="OUT"> + <position x="1271" y="415"/> + <position x="1186" y="415"/> + <expression>pytest_var3</expression> + <outVariable localId="25" height="30" width="60" executionOrderId="0" negated="false"> + <position x="320" y="1075"/> + <relPosition x="0" y="15"/> + <connection refLocalId="26" formalParameter="OUT"> + <position x="320" y="1090"/> + <position x="265" y="1090"/> + <expression>FromC</expression> + <inVariable localId="1" height="30" width="30" executionOrderId="0" negated="false"> + <position x="105" y="1075"/> + <relPosition x="30" y="15"/> + <expression>23</expression> + <block localId="26" width="80" height="45" typeName="C_Pragma" instanceName="C_Pragma0" executionOrderId="0"> + <position x="185" y="1060"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="1"> + <position x="185" y="1090"/> + <position x="135" y="1090"/> + <variable formalParameter="OUT"> + <relPosition x="80" y="30"/> + <inVariable localId="27" height="30" width="90" executionOrderId="0" negated="false"> + <position x="100" y="1190"/> + <relPosition x="90" y="15"/> + <expression>TestInput</expression> + <outVariable localId="28" height="30" width="105" executionOrderId="0" negated="false"> + <position x="195" y="1125"/> + <relPosition x="0" y="15"/> + <connection refLocalId="2"> + <position x="195" y="1140"/> + <position x="140" y="1140"/> + <expression>TestOutput</expression> + <outVariable localId="29" height="30" width="85" executionOrderId="0" negated="false"> + <position x="215" y="1190"/> + <relPosition x="0" y="15"/> + <connection refLocalId="27"> + <position x="215" y="1205"/> + <position x="190" y="1205"/> + <expression>FromInput</expression> + <inVariable localId="2" height="30" width="30" executionOrderId="0" negated="false"> + <position x="110" y="1125"/> + <relPosition x="30" y="15"/> + <expression>10</expression> + <comment localId="30" height="105" width="465"> + <position x="50" y="925"/> + <xhtml:p><![CDATA[You will be ready to use beremiz with C and Python when you will understand why "FromInput" is equal to 75. +Happy hacking! ]]></xhtml:p> + <comment localId="6" height="80" width="345"> + <position x="295" y="630"/> + <xhtml:p><![CDATA[Prints FBID to stdout of PLC runtime. FBID is a unique reference to py_eval instance.]]></xhtml:p> + <comment localId="10" height="85" width="345"> + <position x="295" y="770"/> + <xhtml:p><![CDATA[Simple_C_Call is declared in C_File "1.x:c_code". See python ctypes manual for details on typing.]]></xhtml:p> + <comment localId="32" height="145" width="235"> + <position x="25" y="505"/> + <xhtml:p><![CDATA[Fast clock, at least faster that sleep(1). See what happens when python takes time to answer : PLC continues.]]></xhtml:p> + <outVariable localId="33" height="30" width="133" executionOrderId="0" negated="false"> + <position x="580" y="1564"/> + <relPosition x="0" y="16"/> + <connection refLocalId="35" formalParameter="OUT"> + <position x="580" y="1580"/> + <position x="371" y="1580"/> + <expression>Test_BCD_RESULT</expression> + <inVariable localId="34" height="30" width="75" executionOrderId="0" negated="false"> + <position x="60" y="1564"/> + <relPosition x="75" y="16"/> + <expression>Test_BCD</expression> + <block localId="35" width="106" height="60" typeName="BCD_TO_UINT" executionOrderId="0"> + <position x="265" y="1539"/> + <variable formalParameter="IN"> + <relPosition x="0" y="41"/> + <connection refLocalId="34"> + <position x="265" y="1580"/> + <position x="135" y="1580"/> + <variable formalParameter="OUT"> + <relPosition x="106" y="41"/> + <inVariable localId="36" height="30" width="66" executionOrderId="0" negated="false"> + <position x="60" y="1774"/> + <relPosition x="66" y="16"/> + <expression>Test_DT</expression> + <block localId="37" width="255" height="45" typeName="DATE_AND_TIME_TO_TIME_OF_DAY" executionOrderId="0"> + <position x="265" y="1759"/> + <variable formalParameter="IN"> + <relPosition x="0" y="31"/> + <connection refLocalId="36"> + <position x="265" y="1790"/> + <position x="125" y="1790"/> + <variable formalParameter="OUT"> + <relPosition x="255" y="31"/> + <block localId="38" width="195" height="45" typeName="DATE_AND_TIME_TO_DATE" executionOrderId="0"> + <position x="265" y="1834"/> + <variable formalParameter="IN"> + <relPosition x="0" y="31"/> + <connection refLocalId="36"> + <position x="265" y="1865"/> + <position x="242" y="1865"/> + <position x="242" y="1790"/> + <position x="125" y="1790"/> + <variable formalParameter="OUT"> + <relPosition x="195" y="31"/> + <outVariable localId="40" height="30" width="82" executionOrderId="0" negated="false"> + <position x="580" y="1849"/> + <relPosition x="0" y="16"/> + <connection refLocalId="38" formalParameter="OUT"> + <position x="580" y="1865"/> + <position x="460" y="1865"/> + <expression>Test_Date</expression> + <outVariable localId="42" height="30" width="98" executionOrderId="0" negated="false"> + <position x="465" y="1944"/> + <relPosition x="0" y="16"/> + <connection refLocalId="46" formalParameter="OUT"> + <position x="465" y="1960"/> + <position x="395" y="1960"/> + <expression>Test_String</expression> + <outVariable localId="43" height="30" width="82" executionOrderId="0" negated="false"> + <position x="465" y="2014"/> + <relPosition x="0" y="16"/> + <connection refLocalId="44" formalParameter="OUT"> + <position x="465" y="2030"/> + <position x="400" y="2030"/> + <expression>Test_Bool</expression> + <block localId="44" width="135" height="45" typeName="STRING_TO_BOOL" executionOrderId="0"> + <position x="265" y="1999"/> + <variable formalParameter="IN"> + <relPosition x="0" y="31"/> + <connection refLocalId="45"> + <position x="265" y="2030"/> + <position x="115" y="2030"/> + <variable formalParameter="OUT"> + <relPosition x="135" y="31"/> + <inVariable localId="45" height="30" width="58" executionOrderId="0" negated="false"> + <position x="60" y="2014"/> + <relPosition x="58" y="16"/> + <expression>'True'</expression> + <block localId="46" width="130" height="45" typeName="INT_TO_STRING" executionOrderId="0"> + <position x="265" y="1929"/> + <variable formalParameter="IN"> + <relPosition x="0" y="31"/> + <connection refLocalId="58"> + <position x="265" y="1960"/> + <position x="205" y="1960"/> + <variable formalParameter="OUT"> + <relPosition x="130" y="31"/> + <inVariable localId="50" height="30" width="106" executionOrderId="0" negated="false"> + <position x="75" y="2275"/> + <relPosition x="106" y="15"/> + <expression>Global_RS.Q1</expression> + <block localId="51" width="70" height="85" typeName="AND" executionOrderId="0"> + <position x="240" y="2255"/> + <variable formalParameter="IN1" negated="true"> + <relPosition x="0" y="35"/> + <connection refLocalId="50"> + <position x="240" y="2290"/> + <position x="180" y="2290"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="70"/> + <connection refLocalId="52"> + <position x="240" y="2325"/> + <position x="180" y="2325"/> + <variable formalParameter="OUT"> + <relPosition x="70" y="35"/> + <inVariable localId="52" height="30" width="105" executionOrderId="0" negated="false"> + <position x="75" y="2310"/> + <relPosition x="105" y="15"/> + <expression>BOOL#TRUE</expression> + <outVariable localId="13" height="30" width="105" executionOrderId="0" negated="false"> + <position x="385" y="2275"/> + <relPosition x="0" y="15"/> + <connection refLocalId="51" formalParameter="OUT"> + <position x="385" y="2290"/> + <position x="310" y="2290"/> + <expression>Global_RS.S</expression> + <outVariable localId="20" height="30" width="106" executionOrderId="0" negated="false"> + <position x="385" y="2390"/> + <relPosition x="0" y="15"/> + <connection refLocalId="41" formalParameter="OUT"> + <position x="385" y="2405"/> + <position x="310" y="2405"/> + <expression>Global_RS.R1</expression> + <inVariable localId="24" height="30" width="106" executionOrderId="0" negated="false"> + <position x="75" y="2390"/> + <relPosition x="106" y="15"/> + <expression>Global_RS.Q1</expression> + <block localId="41" width="70" height="85" typeName="OR" executionOrderId="0"> + <position x="240" y="2370"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="35"/> + <connection refLocalId="24"> + <position x="240" y="2405"/> + <position x="180" y="2405"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="70"/> + <connection refLocalId="48"> + <position x="240" y="2440"/> + <position x="180" y="2440"/> + <variable formalParameter="OUT"> + <relPosition x="70" y="35"/> + <inVariable localId="48" height="30" width="105" executionOrderId="0" negated="false"> + <position x="75" y="2425"/> + <relPosition x="105" y="15"/> + <expression>BOOL#FALSE</expression> + <outVariable localId="54" height="30" width="135" executionOrderId="0" negated="false"> + <position x="930" y="1774"/> + <relPosition x="0" y="16"/> + <connection refLocalId="55" formalParameter="OUT"> + <position x="930" y="1790"/> + <position x="855" y="1790"/> + <expression>Test_TOD_STRING</expression> + <block localId="55" width="125" height="45" typeName="TOD_TO_STRING" executionOrderId="0"> + <position x="730" y="1759"/> + <variable formalParameter="IN"> + <relPosition x="0" y="31"/> + <connection refLocalId="39"> + <position x="730" y="1790"/> + <position x="655" y="1790"/> + <variable formalParameter="OUT"> + <relPosition x="125" y="31"/> + <inOutVariable localId="39" height="30" width="75" executionOrderId="0" negatedOut="false" negatedIn="false"> + <position x="580" y="1774"/> + <relPosition x="0" y="16"/> + <connection refLocalId="37" formalParameter="OUT"> + <position x="580" y="1790"/> + <position x="520" y="1790"/> + <relPosition x="75" y="16"/> + <expression>Test_TOD</expression> + <inVariable localId="49" height="30" width="30" executionOrderId="0" negated="false"> + <position x="160" y="2510"/> + <relPosition x="30" y="15"/> + <expression>42</expression> + <outVariable localId="57" height="30" width="50" executionOrderId="0" negated="false"> + <position x="240" y="2510"/> + <relPosition x="0" y="15"/> + <connection refLocalId="49"> + <position x="240" y="2525"/> + <position x="190" y="2525"/> + <expression>TOTO</expression> + <outVariable localId="56" height="30" width="50" executionOrderId="0" negated="false"> + <position x="240" y="2550"/> + <relPosition x="0" y="15"/> + <connection refLocalId="49"> + <position x="240" y="2565"/> + <position x="215" y="2565"/> + <position x="215" y="2525"/> + <position x="190" y="2525"/> + <expression>TUTU</expression> + <inVariable localId="58" height="30" width="146" executionOrderId="0" negated="false"> + <position x="60" y="1944"/> + <relPosition x="146" y="16"/> + <expression>Second_Python_Var</expression> + <inVariable localId="59" height="30" width="30" executionOrderId="0" negated="false"> + <position x="100" y="1385"/> + <relPosition x="30" y="15"/> + <expression>1</expression> + <block localId="61" typeName="function0" executionOrderId="0" height="45" width="111"> + <position x="760" y="1170"/> + <variable formalParameter="LocalVar0"> + <relPosition x="0" y="30"/> + <connection refLocalId="62"> + <position x="760" y="1200"/> + <position x="723" y="1200"/> + <variable formalParameter="OUT"> + <relPosition x="111" y="30"/> + <inVariable localId="62" executionOrderId="0" height="30" width="58" negated="false"> + <position x="665" y="1185"/> + <relPosition x="58" y="15"/> + <expression>fefvsd</expression> + <outVariable localId="63" executionOrderId="0" height="30" width="58" negated="false"> + <position x="905" y="1185"/> + <relPosition x="0" y="15"/> + <connection refLocalId="61" formalParameter="OUT"> + <position x="905" y="1200"/> + <position x="871" y="1200"/> + <expression>fefvsd</expression> + <comment localId="53" height="80" width="420"> + <position x="75" y="2160"/> + <xhtml:p><![CDATA[Shows global variables access from resource configuration (res_pytest) and from project's configuration.]]></xhtml:p> + <inVariable localId="18" height="30" width="74" executionOrderId="0" negated="false"> + <position x="986" y="795"/> + <relPosition x="74" y="15"/> + <expression>mux2_sel</expression> + <comment localId="60" height="45" width="930"> + <position x="60" y="1480"/> + <xhtml:p><![CDATA[Here is shown how to convert values between different types (BCD, DT, TOD, STRING and others) using standard functions.]]></xhtml:p> + <comment localId="64" height="55" width="300"> + <position x="665" y="1095"/> + <xhtml:p><![CDATA[Example of usage of user-defined function.]]></xhtml:p> + <comment localId="65" height="45" width="410"> + <position x="55" y="1315"/> + <xhtml:p><![CDATA[Shows access variable defined in python extension. ]]></xhtml:p> + <inVariable localId="66" height="30" width="137" executionOrderId="0" negated="false"> + <position x="60" y="1685"/> + <relPosition x="137" y="15"/> + <expression>Test_BCD_WRONG</expression> + <block localId="67" width="106" height="100" typeName="BCD_TO_UINT" executionOrderId="0"> + <position x="265" y="1620"/> + <variable formalParameter="EN"> + <relPosition x="0" y="40"/> + <variable formalParameter="IN"> + <relPosition x="0" y="80"/> + <connection refLocalId="66"> + <position x="265" y="1700"/> + <position x="255" y="1700"/> + <position x="255" y="1700"/> + <position x="345" y="1700"/> + <position x="345" y="1700"/> + <position x="197" y="1700"/> + <variable formalParameter="ENO"> + <relPosition x="106" y="40"/> + <variable formalParameter="OUT"> + <relPosition x="106" y="80"/> + <outVariable localId="68" height="30" width="196" executionOrderId="0" negated="false"> + <position x="580" y="1685"/> + <relPosition x="0" y="15"/> + <connection refLocalId="67" formalParameter="OUT"> + <position x="580" y="1700"/> + <position x="371" y="1700"/> + <expression>Test_BCD_WRONG_RESULT</expression> + <comment localId="69" height="165" width="375"> + <position x="795" y="1590"/> + <xhtml:p><![CDATA[Incorrect BCD number is not converted to UINT. +151 (16#97) is good BCD number , but +Try this out and look at value of Test_BCD_CONVERTED variable. + <outVariable localId="70" height="30" width="185" executionOrderId="0" negated="false"> + <position x="580" y="1645"/> + <relPosition x="0" y="15"/> + <connection refLocalId="67" formalParameter="ENO"> + <position x="580" y="1660"/> + <position x="370" y="1660"/> + <expression>Test_BCD_CONVERTED</expression> + <comment localId="71" height="215" width="680"> + <position x="35" y="30"/> + <xhtml:p><![CDATA[This example shows many features in Beremiz: + 1. How to implement python extensions. + 2. How to implement basic C extension. + 3. How to use C code in IEC POUs. + 4. How to call C functions from python code. + 5. How to avoid race conditions between IEC, C and python code. + 6. How to convert betweet different IEC types. + <outVariable localId="72" executionOrderId="0" height="30" width="60" negated="false"> + <position x="1065" y="1970"/> + <relPosition x="0" y="15"/> + <connection refLocalId="76" formalParameter="OUT"> + <position x="1065" y="1985"/> + <position x="1025" y="1985"/> + <position x="1025" y="1995"/> + <position x="985" y="1995"/> + <expression>Grumpf</expression> + <inVariable localId="73" executionOrderId="0" height="30" width="85" negated="false"> + <position x="625" y="1940"/> + <relPosition x="85" y="15"/> + <expression>BOOL#TRUE</expression> + <inVariable localId="74" executionOrderId="0" height="30" width="70" negated="false"> + <position x="625" y="1975"/> + <relPosition x="70" y="15"/> + <expression>Test_DT</expression> + <block localId="75" typeName="RTC" instanceName="RTC0" executionOrderId="0" height="90" width="65"> + <position x="760" y="1925"/> + <variable formalParameter="IN"> + <relPosition x="0" y="35"/> + <connection refLocalId="73"> + <position x="760" y="1960"/> + <position x="735" y="1960"/> + <position x="735" y="1955"/> + <position x="710" y="1955"/> + <variable formalParameter="PDT"> + <relPosition x="0" y="70"/> + <connection refLocalId="74"> + <position x="760" y="1995"/> + <position x="727" y="1995"/> + <position x="727" y="1990"/> + <position x="695" y="1990"/> + <variable formalParameter="Q"> + <relPosition x="65" y="35"/> + <variable formalParameter="CDT"> + <relPosition x="65" y="70"/> + <block localId="76" typeName="DT_TO_STRING" executionOrderId="0" height="40" width="110"> + <position x="875" y="1965"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="75" formalParameter="CDT"> + <position x="875" y="1995"/> + <position x="825" y="1995"/> + <variable formalParameter="OUT"> + <relPosition x="110" y="30"/> + <block localId="77" typeName="ADD" executionOrderId="0" height="60" width="65"> + <position x="170" y="1370"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="30"/> + <connection refLocalId="59"> + <position x="170" y="1400"/> + <position x="130" y="1400"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="50"/> + <connection refLocalId="78"> + <position x="170" y="1420"/> + <position x="160" y="1420"/> + <position x="160" y="1450"/> + <position x="390" y="1450"/> + <position x="390" y="1400"/> + <position x="380" y="1400"/> + <variable formalParameter="OUT"> + <relPosition x="65" y="30"/> + <outVariable localId="47" executionOrderId="0" height="30" width="130" negated="false"> + <position x="625" y="1335"/> + <relPosition x="0" y="15"/> + <connection refLocalId="79"> + <position x="625" y="1350"/> + <position x="590" y="1350"/> + <expression>Test_Python_Var</expression> + <inVariable localId="79" executionOrderId="0" height="27" width="30" negated="false"> + <position x="560" y="1340"/> + <relPosition x="30" y="15"/> + <expression>23</expression> + <inOutVariable localId="78" executionOrderId="0" height="30" width="100" negatedOut="false" negatedIn="false"> + <position x="280" y="1385"/> + <relPosition x="0" y="15"/> + <connection refLocalId="77" formalParameter="OUT"> + <position x="280" y="1400"/> + <position x="235" y="1400"/> + <relPosition x="100" y="15"/> + <expression>SomeVarName</expression> + <block localId="80" typeName="MOVE" executionOrderId="0" height="40" width="60"> + <position x="570" y="455"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="82"> + <position x="578" y="485"/> + <position x="532" y="485"/> + <variable formalParameter="OUT"> + <relPosition x="60" y="30"/> + <connector name="Connection0" localId="81" height="30" width="130"> + <position x="545" y="390"/> + <relPosition x="0" y="15"/> + <connection refLocalId="4"> + <position x="545" y="405"/> + <position x="515" y="405"/> + <continuation name="Connection0" localId="82" height="30" width="130"> + <position x="410" y="470"/> + <relPosition x="130" y="15"/> + <pou name="C_Pragma" pouType="functionBlock"> + <variable name="COORDS"> + <dimension lower="0" upper="5"/> + <simpleValue value="54"/> + <simpleValue value="55"/> + <simpleValue value="56"/> + <simpleValue value="57"/> + <simpleValue value="58"/> + <simpleValue value="59"/> + <variable name="SMURF"> + <derived name="CPLX_TYPE"/> + <variable name="Global_RS"> + <variable name="Dudiduda"> + <derived name="blups"/> + <xhtml:p><![CDATA[(* hereafter is a C pragma accessing FB interface in a clean way *) + char fromPLC = GetFbVar(IN); + extern int PLC_C_Call(char, char *); + if(PLC_C_Call(fromPLC, &toPLC)){ + /* that code demonstrate C access to complex types */ + char somebyte = GetFbVar(COORDS, .table[3]); + SetFbVar(SMURF, somebyte, .FIRSTBYTE); + SetFbVar(COORDS, somebyte, .table[4]); +(* If you do not use GetFbVar and SetFbVar macros, expect unexpected behaviour*) +(* testing access to global struct array *) +Dudiduda[2].FIRSTBYTE := 0; + <pou name="norm" pouType="function"> + <xhtml:p><![CDATA[NORM := SQRT(IN1 * IN1 + IN2 * IN2);]]></xhtml:p> + <pou name="function0" pouType="function"> + <derived name="datatype0"/> + <variable name="LocalVar0"> + <derived name="datatype0"/> + <xhtml:p><![CDATA[function0 := LocalVar0; + <configuration name="config"> + <resource name="res_pytest"> + <task name="pytest_task" priority="0" interval="T#500ms"/> + <pouInstance name="pytest_instance" typeName="main_pytest"/> + <variable name="Global_RS"> + <variable name="Dudiduda"> + <derived name="blups"/> --- a/exemples/python/python@py_ext/pyfile.xml Mon Aug 07 18:17:12 2023 +0200
+++ b/exemples/python/python@py_ext/pyfile.xml Thu Sep 28 17:56:03 2023 +0200
@@ -1,69 +1,79 @@
-<?xml version='1.0' encoding='utf-8'?>
-<PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml">
- <variable name="Test_Python_Var" type="INT" initial="4"/>
- <variable name="Second_Python_Var" type="INT" initial="5"/>
-Python_to_C_Call = PLCBinary.Python_to_C_Call
-Python_to_C_Call.restype = ctypes.c_int
-Python_to_C_Call.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)]
- if(Python_to_C_Call(arg, i)):
- print("toC:", arg, "from C:", res, "FBID:", FBID)
- print("Failed Python_to_C_Call failed")
- print("Python read PLC global :",PLCGlobals.Test_Python_Var)
- print("Python read PLC global Grumpf :",PLCGlobals.Grumpf)
- PLCGlobals.Second_Python_Var = 789
-async_error_test_code = """
-from threading import Timer
-b = Timer(6, badaboomwx)
-print("py_runtime init:", x, ",", y)
-print("py_runtime cleanup")
-print("py_runtime start", x * x + y * y)
-print("py_runtime stop")
+<?xml version='1.0' encoding='utf-8'?> +<PyFile xmlns:xhtml="http://www.w3.org/1999/xhtml"> + <variable name="Test_Python_Var" type="INT" initial="4"/> + <variable name="Second_Python_Var" type="INT" initial="5"/> +Python_to_C_Call = PLCBinary.Python_to_C_Call +Python_to_C_Call.restype = ctypes.c_int +Python_to_C_Call.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_int)] +def MyPrintFunction(msg): + PLCObject.LogMessage(msg) + if(Python_to_C_Call(arg, i)): + print("toC:", arg, "from C:", res, "FBID:", FBID) + print("Failed Python_to_C_Call failed") + print("Python read PLC global :",PLCGlobals.Test_Python_Var) + print("Python read PLC global Grumpf :",PLCGlobals.Grumpf) + PLCGlobals.Second_Python_Var = 789 +async_error_test_code = """ +from threading import Timer +b = Timer(6, badaboomwx) +print("py_runtime init:", x, ",", y) +print("py_runtime cleanup") +print("py_runtime start", x * x + y * y) +print("py_runtime stop") --- a/runtime/PLCObject.py Mon Aug 07 18:17:12 2023 +0200
+++ b/runtime/PLCObject.py Thu Sep 28 17:56:03 2023 +0200
@@ -62,8 +62,9 @@
- sys.stdout.write("PLCobject : "+message+"\n")
+ sys.stdout.write("PLCobject : "+message+"\n") --- a/runtime/PyroServer.py Mon Aug 07 18:17:12 2023 +0200
+++ b/runtime/PyroServer.py Thu Sep 28 17:56:03 2023 +0200
@@ -73,7 +73,8 @@
if self._to_be_published():
print(_("Publishing service on local network"))
def PyroLoop(self, when_ready):
if self._to_be_published():