Skip to main content

RTI Connector for Connext DDS

Project description

(return to rticonnextdds-connector)

RTI Connector for Connext DDS

RTI Connector for Connext DDS is a quick and easy way to access the power and functionality of RTI Connext DDS. It is based on XML-Based Application Creation and Dynamic Data.

Language Support

This repository is specific to Python. For other languages (lua, C, etc.), refer to the main Connector repository.

We use ctypes to call our native functions; these details are hidden in a Python wrapper. RTI tested its Python implementation with both Python 2.7.14 and Python 3.6.3.

Platform support

Python Connector builds its library for select architectures. If you need another architecture, please contact your RTI account manager or sales@rti.com.

### Testing We tested on: * For MacOS 64 bit : Darwin 18 clang 10 * For Windows 64 bit: Windows 10 64 bit VS2015 * For Windows 32 bit: Windows 7 32 bit VS2017 * For Linux 64 bit: CentOS 6.5 gcc 4.8.2 * For Linux 32 bit: Ubuntu 16.04 gcc 5.4.0 * For ARM: Yocto linux 2.0.3 gcc 5.2.0

Version of Connext

To check the version of the libraries, run the following command. For example:

strings librtiddsconnector.dylib | grep BUILD

Threading model

The Connector Native API does not yet implement any mechanism for thread safety. For now, the responsibility of protecting calls to the Connector is left to you. (In future, thread safety may be added in the native layer.) In Python, you will have to protect the calls to Connector if you are using different threads. For an example, see Protecting calls to the Connector library below.

Support

Connector is an experimental RTI product. If you have questions, use the RTI Community forum.

Getting started with Python

Be sure you have Python. Then use pip to install the Connector:

$ pip install rticonnextdds_connector

You can also clone the repository:

$ git clone --recursive https://github.com/rticommunity/rticonnextdds-connector-py.git

Available examples

You can find several sets of examples in the examples/python directory.

  • simple: shows how to write samples and how to read/take.

  • mixed: contains various examples.

Protecting calls to the Connector library

As explained above, you are responsible for protecting calls to Connector. There are many options in Python to do so; one is to use the threading package:

...
...
import threading
sem = threading.Semaphore();
...
...
#acquire the semaphore
sem.acquire(True);
#call to connector APissem.acquire(True);
input.take();
numOfSamples = input.samples.getLength();
...
...
#release the semaphore
sem.release();
...
...

For more information on the threading Python packages, see the Python documentation.

API overview

require the Connector library

To use rticonnextdds_connector, import it:

import rticonnextdds_connector as rti

instantiate a new Connector

To create a new Connector, pass an XML file and a configuration name.

connector = rti.Connector("MyParticipantLibrary::Zero","./ShapeExample.xml");

For more information on the XML format, see the XML-Based Application Creation guide or look at the ShapeExample.xml file included in this examples directory.

delete a Connector

To destroy all the DDS entities that belong to a Connector previously created, call the delete function.

connector = rti.Connector("MyParticipantLibrary::Zero","./ShapeExample.xml");
...
...
connector.delete();

write a sample

To write a sample, first get a reference to the output port:

output = connector.getOutput("MyPublisher::MySquareWriter")

Then set the instance’s fields:

output.instance.setNumber("x", 1);
output.instance.setNumber("y", 2);
output.instance.setNumber("shapesize", 30);
output.instance.setString("color", "BLUE");

Then write:

output.write();

set the instance’s fields:

The content of an instance can be set by using a dictionary that matches the original type, or field by field.

  • Using a dictionary:

#assuming that sample is a dictionary containing
#an object of the same type of the output.instance:

output.instance.setDictionary(sample);
  • Field by field:

output.instance.setNumber("y", 2);

The following APIs set an instance field by field: setNumber(fieldName, number); setBoolean(fieldName, boolean); and setString(fieldName, string);.

Nested fields can be accessed with the dot notation "x.y.z". Arrays or sequences can be accessed with square brakets: "x.y[1].z". For more information on how to access fields, see the “Data Access API” section of the RTI Prototyper Getting Started Guide.

read/take data

To read/take samples, first get a reference to the input port:

input = connector.getInput("MySubscriber::MySquareReader");

Then call the read() or take() API:

input.read();

or

input.take();

The read/take operation can return multiple samples. Therefore, you must iterate on an array:

    input.take();
    numOfSamples = input.samples.getLength();
    for j in range (1, numOfSamples+1):
        if input.infos.isValid(j):
            x = input.samples.getNumber(j, "x");
            y = input.samples.getNumber(j, "y");
            size = input.samples.getNumber(j, "shapesize");
            color = input.samples.getString(j, "color");
            toPrint = "Received x: " + repr(x) + " y: " + repr(y) + " size: " + repr(size) + " color: " + repr(color);
            print(toPrint);
}

access sample fields after a read/take

A read() or take() operation can return multiple samples. They are stored in an array. Every time you try to access a specific sample, you have to specify an index (j in the example below).

You can access the data by getting a copy in a dictionary object, or you can access each field individually:

  • Using a dictionary:

numOfSamples = input.samples.getLength();
for j in range (1, numOfSamples+1):
    if input.infos.isValid(j):
        sample = input.samples.getDictionary(j);
        #print the whole sample
        print(sample);
        #or print a single element
        print(sample['x']);
}
  • Field by field:

numOfSamples = input.samples.getLength();
for j in range (1, numOfSamples+1):
    if input.infos.isValid(j):
        x = input.samples.getNumber(j, "x");
        y = input.samples.getNumber(j, "y");
        size = input.samples.getNumber(j, "shapesize");
        color = input.samples.getString(j, "color");
        toPrint = "Received x: " + repr(x) + " y: " + repr(y) + " size: " + repr(size) + " color: " + repr(color);
        print(toPrint);
}

The following APIs access the samples field by field: getNumber(indexm fieldName); getBoolean(index, fieldName); and getString(index, fieldName);.

License

With the sole exception of the contents of the “examples” subdirectory, all use of this product is subject to the RTI Software License Agreement included at the top level of this repository. Files within the “examples” subdirectory are licensed as marked within the file.

This software is an experimental (“pre-production”) product. The Software is provided “as is,” with no warranty of any type, including any warranty for fitness for any purpose. RTI is under no obligation to maintain or support the software. RTI shall not be liable for any incidental or consequential damages arising out of the use or inability to use the software.

(return to rticonnextdds-connector)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rticonnextdds_connector-0.4.2.tar.gz (20.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rticonnextdds_connector-0.4.2-py3-none-any.whl (24.3 MB view details)

Uploaded Python 3

File details

Details for the file rticonnextdds_connector-0.4.2.tar.gz.

File metadata

  • Download URL: rticonnextdds_connector-0.4.2.tar.gz
  • Upload date:
  • Size: 20.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for rticonnextdds_connector-0.4.2.tar.gz
Algorithm Hash digest
SHA256 e1582ec4fe47e8d38bd5877e34b4be8f4bead850fa5778a36a04b0f04a900107
MD5 42095932aabeb0abd5566293ef74085f
BLAKE2b-256 eb448ebd1356bf96eb52f68a3dbcdf2acc2417b6a135cb3db4df4962befb4ddc

See more details on using hashes here.

File details

Details for the file rticonnextdds_connector-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: rticonnextdds_connector-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 24.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.4

File hashes

Hashes for rticonnextdds_connector-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 21733aaa432611ddf40fc8dfbd9d75efaab61fa6d5902b9e95336789b40fc3bf
MD5 1044ea297e3260014e20e975c7dbe213
BLAKE2b-256 e5933892643f82bada9182d04a9dc2a2527e99ca5755fa9dec0406f15300a28e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page