1

I've been trying to use ADLINK's Vortex OpenSplice Community edition with the Python API (python version 3.6 within a PyEnv virtual environment) on Ubuntu 20.04.2 LTS. I've followed the PythonDCPSAPIGuide and got the python examples in ($OSPL_HOME/tools/python/examples) working. However I can't figure out how to create a topic associated for a domain participant for a statically generated topic class using idlpp. How would I be able to do this?

What I have done so far:

I have an IDL file that has include paths for quite a few other IDL files. I have converted these IDL files to a python topic classes using the following bash script:

#!/bin/bash

for FILE in *.idl; do
  $OSPL_HOME/bin/idlpp -I $OSPL_HOME/etc/idl -S -l python -d . $FILE
done

This creates a series of python packages (python topic classes) that I import into my python script which is in the same directory.

Using these packages I would like to create or register a topic with a domain participant in my python script. For example something like the following python code, (however the 'create_topic' function doesn't exist):

# myExampleDDSFile.py

from dds import *
from foo import foo_type # idlpp generated module/class
from foo2 import foo_type2 # idlpp generated module/class

dp = DomainParticipant()
topic = dp.create_topic('foo_topic',foo_type) # this function doesn't exist for a domain participant
pub = dp.create_publisher()

Would this be possible and if so how would I be able to register a topic that I have statically created with a domain participant in python?


I noticed in the provided python examples (e.g. $OSPL_HOME/tools/python/examples/example1.py) a topic is registered dynamically using the following code below, but I don't think this relates to statically generated python topic classes:

# example1.py snippet

dp = DomainParticipant()
gen_info = ddsutil.get_dds_classes_from_idl('example1.idl', 'basic::module_SequenceOfStruct::SequenceOfStruct_struct')
topic = gen_info.register_topic(dp, 'Example1')

I also couldn't see a relevant function in the source code.

I apologise if this is a simple question or if I have missed something - I am very new to Vortex OpenSplice DDS.

Any help would be appreciated.

gb261
  • 13
  • 4

1 Answers1

1

I can't speak to OpenSplice, but you can do this with CoreDX DDS. For example, given the IDL file "hello.idl":

struct StringMsg
{
   string msg;
};

run

coredx_ddl -l python -f hello.idl -d hello

And, then the following python is an example of how to use the generated 'StringMsg' type to construct a Topic and a DataReader:

import time
import dds.domain
from  hello import StringMsg

# Use default QoS, and no listener
dp    = dds.domain.DomainParticipant( 0 )
topic = dds.topic.Topic( StringMsg, "helloTopic", "StringMsg", dp )
sub   = dds.sub.Subscriber( dp )
dr    = dds.sub.DataReader( sub, topic )
rc    = dr.create_readcondition( dds.core.SampleState.ANY_SAMPLE_STATE,
                                 dds.core.ViewState.ANY_VIEW_STATE,
                                 dds.core.InstanceState.ANY_INSTANCE_STATE )
ws    = dds.cond.WaitSet()
ws.attach_condition(rc)

while True:
    t = dds.core.Duration.infinite()
    print('waiting for data...')
    ws.wait(t)
    while True:
        try:
            samples = dr.take( )
            for s in samples:
                if s.info.valid_data:
                    print("received: {}".format(s.data.msg))
        except dds.core.Error:
            break;
C Tucker
  • 301
  • 1
  • 8