pythonModule.py
script is responsible for the Services subscription in the Python environmentpythonUtils.py
script is an utility script usable by the user Python scriptpythonModule
element. For example:<pythonModule name="FlightManagementSystem">
pythonImplementation
element declares the Python script file which implements the script, and specifies the associated properties.separator
: the optional separator between values when sending or receiving services between Java and the Python script. The default value for the separator is "^"[2]
<pythonModule name="FlightManagementSystem" > <pythonImplementation path="pythonAppli" inputPort="6000" outputPort="6005" inputSize="1024" outputSize="5000"/> </pythonModule>Another example, where available free local ports are used for
inputPort
and outputPort
, and 1024 is used for both inputSize
and outputSize
:<pythonModule name="FlightManagementSystem" > <pythonImplementation path="pythonAppli" /> </pythonModule>
<services> <publish name="position" > <data name="latitude" type="float" /> <data name="longitude" type="float" /> <data name="altitude" type="float" /> </publish> </services>We may have the following content exchanged between Java and Python:
position=latitude:1.23^longitude:0.45^altitude:1200
It is possible to change the default value of the separator to be any character (or even a string having more than one character), including unicode character. This may be useful if string data sent or received by the Python script contain the default separator character.<pythonImplementation ... separator="!" >
<pythonImplementation ... separator="!!" >
<pythonImplementation ... separator="°" >
pythonModule.py
and pythonUtils.py
scripts must change when the communication between Java and Python is upgraded.pythonModule.py
script check if its own version is compatible with the version proviced by Java. This means that you normally should replace the pythonModule.py
and pythonUtils.py
scripts if the Python modules version changes.
pythonModule.py
scriptpythonUtils.py
scriptFlightManagementSystem
module:position
publish servicedirectTo
event servicecomputeFlightPlan
request-response service<pythonModule name="FlightManagementSystem" > <pythonImplementation path="pythonAppli"/> <interfaces> <subscribe service="position" /> <eventReceived service="directTo"/> <requestReceived service="computeFlightPlan"/> </interfaces> </pythonModule>Another way to specify the Python module is to explictly specify the ports and port sizes for the Java / Python communication:
<pythonModule name="FlightManagementSystem" > <pythonImplementation path="pythonAppli" inputPort="6000" outputPort="6005" inputSize="1024" outputSize="1024"/> <interfaces> <subscribe service="position" /> <eventReceived service="directTo"/> <requestReceived service="computeFlightPlan"/> </interfaces> </pythonModule>
from pythonUtils import PythonUtils class PythonAppli: def subscribe(self, pythonUtils, serviceName): service = pythonUtils.getService(serviceName) if serviceName == "position": // get position ... elif serviceName == "directTo": // compute directTo ... elif serviceName == "computeFlightPlan": // compute FlightPlan and sends the response ...
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence