PublishModule
module increments or decrements a value cyclicallyEventModule
module allows to click on a toggle to set if the first module should increment or decrement the value, and shows the valuePublishModule
in the Python scripting language.
PublishModule
which:EventModule
which:PublishModule
in Python:applications.xml
XML file has to be modified to switch from a Java module implementation to a Python module implementation.
<files> <file url="applications.xml" /> <file url="services.xml" /> <file url="types.xml" /> <pythonRuntime path="<my_python_path>/python.exe" /> </files>If we want to simplify debugging if we encounter errors in the script execution, we can set the
debugScripts
property:<files> <file url="applications.xml" /> <file url="services.xml" /> <file url="types.xml" /> <property key="debugScripts" value="true" /> <pythonRuntime path="<my_python_path>/python.exe" /> </files>
<files> <file url="applications.xml" /> <file url="services.xml" /> <file url="types.xml" /> <property key="debugScripts" value="true" /> <pythonRuntime path="<my_Anaconda_path>/python.exe" anaconda="true" /> </files>
applications.xml
XML file, by modifying the PublishModule
configuration:<application name="publishAppli"> <modules> <pythonModule name="PublishModule" > <pythonImplementation path="pythonAppli"> <defaultSendEntryPoint method="publish" /> </pythonImplementation> <interfaces> <eventReceived service="event"/> <cyclic service="published" frequency="200ms" attach="attach"/> </interfaces> </pythonModule> </modules> </application>As you can see, we specified that the implementation of the
PublishModule
is in the pythonApply.py
file, in the same directory as the application.xml
file. We will also have a send
method in the Groovy script will be called each time the published
Service is cyclically invoked.
pythonModule.py
scriptpythonUtils.py
scriptpublished
service to be invoked cyclically every 200 milliseconds in the module XML specification:<cyclic service="published" frequency="200ms" attach="attach"/>The
pythonApply.py
script will implement the behavior of this Module:subscribe
method will be notified of the event
Service. Depending on the value of the event
data, a step
variable will have a 1 or -1 valuesend
method will be invoked cyclically for the published
Service. The current value will be incremented or decremented, and the Service will be notified with this current valuefrom pythonUtils import PythonUtils class PythonAppli: step = 1 count = 1 def subscribe(self, pythonUtils, serviceName): eventService = pythonUtils.getService("event"); eventValue = eventService["event"] if eventValue: self.step = -1 else: self.step = 1 def publish(self, pythonUtils, serviceName): publishService = pythonUtils.getService("published"); pythonUtils.setValue(publishService, "value", self.count) self.count = self.count + self.step pythonUtils.send("published")
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence