Example Code - Status Print to .csv File

Note: Applies to RTI Connext 4.3 and above, although the same methodology can be applied to 4.0, 4.1, and 4.2.

The following example has been written in C++.

Purpose 

This example illustrates how to extract and print Datawriter and Datareader statuses to a Comma-Separated Values (csv) file. This example uses statuses that were added in version 4.3:

  • DATA_READER_CACHE_STATUS
  • DATA_READER_PROTOCOL_STATUS
  • DATA_WRITER_CACHE_STATUS
  • DATA_WRITER_PROTOCOL_STATUS

This example contains the following files:

  • Status_PrettyPrint_API files: a simple API for extracting and printing statuses
  • msg files: a single writer and single reliable reader with added API calls to print the statuses
  • csv files: output files from a sample run of this example. The writer file contains additional comments.
  • Readme: same content as this description

Extracting the statuses is just a matter of accessing the attributes of the status structures. The real value of the statuses is the ability to display them over time as a debugging aid. This idea applies to any pre-4.3 statuses as well.

Building

Make sure you are using one of the relevant RTI Connext versions, as specified at the top of the Solution.

Before compiling or running the example, make sure the environment variable NDDSHOME is set to the directory where your version of RTI Connext is installed.

Run rtiddsgen with the -example option and the target architecture of your choice (for example, i86Win32VS2005). The RTI Connext Core Libraries and Utilities Getting Started Guide describes this process in detail. Follow the same procedure to generate the code and build the examples. Do not use the -replace option.

After running rtiddsgen like this...

C:\local\StatusPrint\c++> rtiddsgen -language C++ -example i86Win32VS2005 msg.idl

...you will see messages that look like this:

File C:\local\StatusPrint\c++\msg_subscriber.cxx already exists and will not be replaced with updated content. If you would like to get a new file with the new content, either remove this file or supply -replace option.
File C:\local\StatusPrint\c++\msg_publisher.cxx already exists and will not be replaced with updated content. If you would like to get a new file with the new content, either remove this file or supply -replace option.

This is normal and is only informing you that the subscriber/publisher code has not been replaced, which is fine since all the source files for the example are already provided.

Running

In two separate command prompt windows for the publisher and subscriber, navigate to the objs/<arch>directory and run these commands:

Windows systems:

msg_publisher.exe <domain#> 13
msg_subscriber.exe <domain#> 15

UNIX systems:

./msg_publisher <domain#> 13
./msg_subscriber <domain#> 15

The applications accept two arguments:

  1. The <domain #>. Both applications must use the same domain # in order to communicate. The default is 0.
  2. How long the examples should run, measured in samples for the publisher and sleep periods for the subscriber. A value of '0' instructs the application to run forever; this is the default.

While generating the output below, we used values that would capture the most interesting behavior.

Publisher Output

Writing msg, count 0
Writing msg, count 1
Writing msg, count 2
Writing msg, count 3
Writing msg, count 4
Writing msg, count 5
Writing msg, count 6
Writing msg, count 7
Writing msg, count 8
Writing msg, count 9
Writing msg, count 10
Writing msg, count 11
Writing msg, count 12

Subscriber Output

msg subscriber sleeping for 1 sec...

   id: 1
msg subscriber sleeping for 1 sec...

   id: 2
msg subscriber sleeping for 1 sec...

   id: 3
msg subscriber sleeping for 1 sec...

   id: 4
msg subscriber sleeping for 1 sec...

   id: 5
msg subscriber sleeping for 1 sec...

   id: 6
msg subscriber sleeping for 1 sec...

   id: 7
msg subscriber sleeping for 1 sec...

   id: 8
msg subscriber sleeping for 1 sec...

   id: 9
msg subscriber sleeping for 1 sec...

   id: 10
msg subscriber sleeping for 1 sec...

   id: 11
msg subscriber sleeping for 1 sec...
msg subscriber sleeping for 1 sec...

   id: 12
msg subscriber sleeping for 1 sec...
Programming Language:
Attachments: