Listener's take() operation

2 posts / 0 new
Last post
Offline
Last seen: 7 years 1 week ago
Joined: 03/27/2013
Posts: 28
Listener's take() operation

Hi there,

I'm in the process of developing an app using RTI 5.2.3 on windows. in subscriber application, I use a listener to retrieve the topic instance. I need to access the fields of the topic individually, in order to do some process. The listener recieves data with the take() operation. I wonder how I can obtain the fileds of the topic from "data_seq" and display each of them in a winform UI.

public override void on_data_available(DDS.DataReader reader)
{
ParametersDataReader Parameters_reader =
(ParametersDataReader)reader;

try
{
Parameters_reader.take(
data_seq,
info_seq,
DDS.ResourceLimitsQosPolicy.LENGTH_UNLIMITED,
DDS.SampleStateKind.ANY_SAMPLE_STATE,
DDS.ViewStateKind.ANY_VIEW_STATE,
DDS.InstanceStateKind.ANY_INSTANCE_STATE);
}
catch (DDS.Retcode_NoData)
{
return;
}
catch (DDS.Exception e)
{
Console.WriteLine("take error {0}", e);
return;
}

System.Int32 data_length = data_seq.length;
for (int i = 0; i < data_length; ++i)
{
if (info_seq.get_at(i).valid_data)
{
ParametersTypeSupport.print_data(data_seq.get_at(i)); //I need to access the topic's fields here

}
}

try
{
Parameters_reader.return_loan(data_seq, info_seq);
}
catch (DDS.Exception e)
{
Console.WriteLine("return loan error {0}", e);
}
}

 

Thanks in advance,

Randy

Juanjo Martin's picture
Offline
Last seen: 2 years 4 months ago
Joined: 07/23/2012
Posts: 48

Hi Randy,

Try accessing the i-th element in the data_seq list. The data should be there.

For example, if your type contains a "long x", you will have to do:

if (info_seq.get_at(i).valid_data)
{
doSomethingWithTheMember(data_seq.get_at(i).x)

}

Always remember to check if it's valid data.

Thanks,

Juanjo Martin