How can I get the subscribed data value into parameter in C?

3 posts / 0 new
Last post
Offline
Last seen: 4 years 6 months ago
Joined: 08/11/2019
Posts: 28
How can I get the subscribed data value into parameter in C?

I want to put the subscribe data in to parameters in C,

and I already publish data and subscribe it which generate by idl.

For the publisher I can put value by " instance -> uploadtime(myparameter) = 20191106(value)"

```    
instance = WaterDispenserTypeSupport_create_data_ex(DDS_BOOLEAN_TRUE);
    if (instance == NULL) {
        fprintf(stderr, "WaterDispenserTypeSupport_create_data error\n");
        publisher_shutdown(participant);
        return -1;
    }

    /* For a data type that has a key, if the same instance is going to be
    written multiple times, initialize the key here
    and register the keyed instance prior to writing */
    
    instance_handle = WaterDispenserDataWriter_register_instance(
        WaterDispenser_writer, instance);
   ...

 ```

How can I put the value which I subscribe into other field and do other process like the picture?

 

 

Offline
Last seen: 2 weeks 6 days ago
Joined: 10/22/2018
Posts: 91

Hi Kay Wu,

I would like to confirm what you are trying to do.

Looking at the image you have attached, I think you want to know how you can access the data which is written on the publishing application, on your subscribing application?
There are two APIs to do this read and take. Before calling these APIs you will need to either use a listener, or a waitset, to be notified when there is new data available in your application.

If you haven't already I would suggest looking at a HelloWorld example. You can generate one using the  -example  flag to rtiddsgen (e.g., rtiddsgen -example -language C ./WaterDispenser.idl) - after running that command, check the WaterDispenser_subscriber.c file.

Sam

Offline
Last seen: 4 years 6 months ago
Joined: 08/11/2019
Posts: 28

Hi Sam,

Thank you very much for answering the question!

I read FooDataReader_take, but I have no idea how to use it, 

For  


DDS_ReturnCode_t FooDataReader_take ( FooDataReader * self,
struct FooSeq * received_data,
struct DDS_SampleInfoSeq * info_seq,
DDS_Long max_samples,
DDS_SampleStateMask sample_states,
DDS_ViewStateMask view_states,
DDS_InstanceStateMask instance_states
)

Can I ask a question,

where should I put in HelloWorld example and how to get the parameter which I set in .idl file.

I only find example for example : news

Once again, I apologize for the inconvenience. 

--Kay