How can i access the data from subscriber

2 posts / 0 new
Last post
Offline
Last seen: 5 years 2 weeks ago
Joined: 11/20/2019
Posts: 1
How can i access the data from subscriber

Hello, my name is Derni, I am a beginner in this field. I have successfully published several data to the subscriber. My question is how can I access each data? for example like this screenshot that I attached in this question. I want to get "UploadTime" data etc and i want to put them into the right columns like on the table. I tried to access the instance variable but it can't work. 

Keywords:
Offline
Last seen: 1 month 3 weeks ago
Joined: 10/22/2018
Posts: 91

Hi Derni,

I would suggest looking at the examples on our community github page.
There you will find examples of what you are trying to achieve.
Specifically, the following part of the keyed_data example in C may be of help:

retcode = keysDataReader_take(
            keys_reader,
            &data_seq,
            &info_seq,
            DDS_LENGTH_UNLIMITED,
            DDS_ANY_SAMPLE_STATE,
            DDS_ANY_VIEW_STATE,
            DDS_ANY_INSTANCE_STATE);
    if (retcode == DDS_RETCODE_NO_DATA) {
        return;
    } else if (retcode != DDS_RETCODE_OK) {
        printf("take error %d\n", retcode);
        return;
    }

    for (i = 0; i < keysSeq_get_length(&data_seq); ++i) {
        /* Start changes for Keyed_Data */
        struct DDS_SampleInfo *info = NULL;
        keys *data = NULL;

        info = DDS_SampleInfoSeq_get_reference(&info_seq, i);
        data = keysSeq_get_reference(&data_seq, i);
        /* We first check if the sample includes valid data */
        if (info->valid_data) {
            if (info->view_state == DDS_NEW_VIEW_STATE) {
                printf("Found new instance; code = %d\n", data->code);
            }

            printf("Instance %d: x: %d, y: %d\n", data->code, data->x, data->y);

        }

That is lines 120:150 of the keys_subscriber.c file.

I would also like to mention, that the code generated by rtiddsgen when used with -example flag also generates this code for you.