Issues with Getting Started Intro to Publish/Subscribe

7 posts / 0 new
Last post
Offline
Last seen: 1 day 20 hours ago
Joined: 09/08/2020
Posts: 16
Issues with Getting Started Intro to Publish/Subscribe

I'm trying to follow along with the publish/subscribe example on the RTI Connext DDS Getting Started page.  I downloaded the GitHub example code, ran rtiddsgen, and built the example code.

 

I can't figure out how to edit the HelloWorld topic that gets published.  The tutorial suggests modifying the HelloWorld msg contents (2.2.4 Open/Modify Publishing Application Step 3) like this:

 

sample.msg("Hello world!" + std::to_string(count)).

 

However, I don't see any "sample" HelloWorld instance in the example code.  There are other differences too between the GitHub sample code and Getting Started page.

 

The available objects are the HelloWorld topic (from participant->create_topic()) and HelloWorldTypeSupport.  I can't figure out how to edit the HelloWorld msg contents via these objects.  How do I do this?

 

Getting Started page:

// Create data sample for writing
HelloWorld sample;
for (int count = 0; running && (count < sample_count || sample_count == 0);
     count++) {
    // Modify the data to be written here
    sample.msg("Hello world! " + std::to_string(count));

Example Code (GitHub):

    /* Create data sample for writing */
    instance = HelloWorldTypeSupport::create_data();
    if (instance == NULL) {
        fprintf(stderr, "HelloWorldTypeSupport::create_data error\n");
        publisher_shutdown(participant);
        return -1;
    }
/* Main loop */
    for (count=0; (sample_count == 0) || (count < sample_count); ++count) {
        printf("Writing HelloWorld, count %d\n", count);

        /* Modify the data to be sent here */

        retcode = HelloWorld_writer->write(*instance, instance_handle);
        if (retcode != DDS_RETCODE_OK) {
            fprintf(stderr, "write error %d\n", retcode);
        }

        NDDSUtility::sleep(send_period);
    }
Offline
Last seen: 1 day 18 hours ago
Joined: 09/23/2018
Posts: 41

The code does not look like the code for the new Getting Started Guide,  it looks like the Traditional C++ HelloWorld example code that comes with the Connext installation:  e.g.  C:\Users\gary\Documents\rti_workspace\6.0.1\examples\connext_dds\c++\hello_idl

Did you do a  "git clone https://github.com/rticommunity/rticonnextdds-getting-started.git"   to retrieve the code?

In our installation examples, you can modify the sample like this (Traditional C++):

/* Modify the data to be sent here */
instance->prefix = "H";
instance->sampleId = count;
instance->payload = "1234";

If you use something like Visual Studio to edit the code,  it will give hover-help as you type:

 

I would redownload the code from git and make sure you are in the correct area for the new Getting Started Guide.

 

r
Offline
Last seen: 1 week 12 hours ago
Joined: 06/17/2019
Posts: 17

Hi Sharro, here is a direct reference to the 'sample' variable used in the c++11 getting started guide code on github:

https://github.com/rticommunity/rticonnextdds-getting-started/blob/376b4e7586bc725cd38da1776a77d224435ca851/1_hello_world/c%2B%2B11/hello_world_publisher.cxx#L45

I do notice that the for loop conditions are broken up on different lines and are slightly different. I'm checking with our getting started guide author about that. Let me know if you see other inconsistencies. 

Offline
Last seen: 1 day 20 hours ago
Joined: 09/08/2020
Posts: 16

I tried editing the instance msg like this:

        instance->msg("Hello world! " + std::to_string(count));

And get a build error:

g++ -c -pipe -std=c++11 -O2 -std=gnu++0x -Wall -W -D_REENTRANT -fPIC -DRTI_UNIX -DRTI_LINUX -DRTI_64BIT -DQT_NO_DEBUG -DQT_CORE_LIB -I. -I. -I../../rti_connext_dds-6.0.1/include -I../../rti_connext_dds-6.0.1/include/ndds -I../../rti_connext_dds-6.0.1/include/ndds/hpp -I/opt/Qt5/5.6/gcc_64/include -I/opt/Qt5/5.6/gcc_64/include/QtCore -I. -I/opt/Qt5/5.6/gcc_64/mkspecs/linux-g++ -o hello_world_publisher.o hello_world_publisher.cxx
hello_world_publisher.cxx: In function 'int publisher_main(int, int)':
hello_world_publisher.cxx:177:62: error: 'instance->HelloWorld::msg' cannot be used as a function

 

How do I fix this?

r
Offline
Last seen: 1 week 12 hours ago
Joined: 06/17/2019
Posts: 17

Hi Sharro, 

I think you're still trying to combine two different source code files / examples. Like Gary said, you may be trying to use the "hello_idl" code that comes with the Connext installation: e.g. C:\Users\gary\Documents\rti_workspace\6.0.1\examples\connext_dds\c++\hello_idl

And then trying to follow the getting started guide that uses different "1_hello_world" code from the github example

 

I would suggest cloning the github repo described in section 2.2.1 of the getting started guide: "git clone https://github.com/rticommunity/rticonnextdds-getting-started.git"

Or if you want to use the hello_idl example shipped with connext you can change the variables of the instance by using the equals sign (see gary's screen shot he provided)

Offline
Last seen: 1 day 20 hours ago
Joined: 09/08/2020
Posts: 16

Ross,

Thanks for the feedback.  I've been downloading from github via a zip but it looks like my local directory got out of sync from the master branch.  Not sure how that happened.  I can see the "HelloWorld sample" usage now.  Also got it compiling with the equals sign.

Looks like Gary's screenshot does match the hello_world example installed by Connext.  I'll reference that too if needed.

Thanks for the help sorting this out.

Offline
Last seen: 6 days 17 hours ago
Joined: 04/02/2013
Posts: 145

You're modifying the wrong example. Use the C++11 example in GitHub.