How to get the data from publisher by programming in subscriber

3 posts / 0 new
Last post
Offline
Last seen: 3 years 7 months ago
Joined: 08/20/2020
Posts: 6
How to get the data from publisher by programming in subscriber

Hi, I am using C# to publish some of my customized data as a string with idl generated hello_world example, and I am able to recieve the string in subscriber in the form of showing them in subscriber's console.

However, I have no idea of where can I get the string via programming in subscriber. What is the precise function or method I should use to get the recieved string and use them as a variable(ex.as an int or string) so I can further process them in /*Main loop*/?

Howard's picture
Offline
Last seen: 19 hours 32 min ago
Joined: 11/29/2012
Posts: 565

In the example code, you should find a function,

public override void on_data_available(DDS.DataReader reader) {

After calling take(), that function prints the sample:

System.Int32 data_length = data_seq.length;
for (int i = 0; i < data_length; ++i) {
     if (info_seq.get_at(i).valid_data) {
          HelloWorldTypeSupport.print_data(data_seq.get_at(i));
     }
}

change it to

System.Int32 data_length = data_seq.length;
for (int i = 0; i < data_length; ++i) {
     if (info_seq.get_at(i).valid_data) {
          string mystring = data_seq.get_at(i).message);
     }
}

 

Offline
Last seen: 3 years 7 months ago
Joined: 08/20/2020
Posts: 6

It worked! Thank you for the help!