Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Python TCP modules



Python TCP modules are Python socket modules where the associated Python script use TCP sockets to communicate with the framework.

Overview


These modules allow to execute Python code in a Python 3 environment:
  • A Python module creates a Python process using the Python executable path defined in the framework properties
  • services reception from the Python module will be deferred to the associated Python script using a TCP communication
  • services invocation from the Python script will be deferred as a Python module Service invocation using a TCP communication

pythonarchi
Two generic additional Python scripts are necessary to handle the communication between the Python module and the Python script:
  • The pythonModule.py script is responsible for the Services subscription in the Python environment
  • The pythonUtils.py script is an utility script usable by the user Python script


Note that these two modules are valid for a Python 3 environment for TCP communication.

Initialization and runtime sequence


Using lengthy methods for the Python scripts


Declaration

These modules are declared by the top-level pythonModule element. For example:
      <pythonModule name="FlightManagementSystem">

Types limitations


Python TCP modules only use Python 3. As there is a JSON library included in the Python implementation, so the exchange of Data is performed using the JSON format. There are no limitations on the types which can be exchanged with Python modules, including types complex types.

Python TCP module implementation


The pythonImplementation element declares the Python script file which implements the script, and specifies the associated properties.

There are no specific properties for TCP modules.

Examples

For example:
      <pythonModule name="FlightManagementSystem" >
         <pythonImplementation protocol="tcp" path="pythonAppli" 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 protocol="tcp" path="pythonAppli" />
      </pythonModule>

Python compatibility

Main Article: Python modules version

The pythonModule.py and pythonUtils.py scripts must change when the communication between Java and Python is upgraded.

The Python modules version is provided by the Framework as a launch argument when starting the Python process. The 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.

Python library


In order for the Python script to work properly, you must copy two additional Python scripts which will be used as a library in the same directory as the script itself:
  • The pythonModule.py script
  • The pythonUtils.py script

Python script


A Python script may have methods declared for:
  • The initialization of the module
  • The start of the module
  • The cyclic call for a cyclic service
  • The subscription of a service

Example

In the following example, the FlightManagementSystem module:
  • subscribe to the position publish service
  • subscribe to the directTo event service
  • provides the computeFlightPlan request-response service
      <pythonModule name="FlightManagementSystem" >
         <pythonImplementation protocol="tcp" 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 protocol="tcp" path="pythonAppli" inputPort="6000" outputPort="6005" inputSize="1024" outputSize="1024"/>
         <interfaces>
            <subscribe service="position" />
            <eventReceived service="directTo"/>
            <requestReceived service="computeFlightPlan"/>
         </interfaces>
      </pythonModule>


We could have the following code for the script:
      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
          ...

See also


Categories: concepts | python

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence