4. Examples

Several examples are provided to demonstrate the Python DCPS features.

The examples can be found in the following directory:

  • $OSPL_HOME/tools/python/examples

4.1. Example Files

4.1.1. File Types

The examples directory contains files of different types. The runnable python script files reference the xml and idl files.

File Type

Description

py

A program file or script written in Python

xml

An XML file that contains one or more Quality of Service (QoS) profiles for DDS entities.

idl

An interface description language file used to define topic(s).

4.1.2. Examples

Example

Description

qos_example.py

An example that demonstrates how to specify QoS settings using Python DCPS APIs. Also shows usage of a waitset.

example1.py

Dynamic generation of Python Topic classes using IDL file and name. Uses a topic with a sequence.

example2.py

Dynamic generation of Python Topic classes using Enumeration and nested modules.

example3.py

Static generation of Python Topic classes as in example1 using the same topics.

example4.py

Demonstrate finding DDS topics over-the-wire. Find topics registered by other processes, and read and write samples to those topics.

4.2. Running Examples

To run an example python script:

  1. Setup OSPL environment variables.

    Linux
    • source release.com

    Windows
    • release.bat

  2. Ensure you are in the tools/python/examples folder

  3. Run example scripts 1,2 and 4

    • > python3 example1.py

  4. Run example script 3

    • > idlpp -l python example3.idl

    • > python3 example3.py