Working with data writers.
More...
Working with data writers.
Setting up a data writer
- Create a data writer, FooDataWriter, of user data type
Foo:
DataWriterQos writer_qos = new DataWriterQos();
DataWriterListener writer_listener = null;
try {
publisher.get_default_datawriter_qos(writer_qos);
} catch (DDS.Exception) {
Console.WriteLine(
"***Error: failed to get default datawriter qos");
}
DataWriter writer = publisher.create_datawriter(topic,
writer_qos,
writer_listener,
if (writer == null) {
Console.WriteLine("***Error: failed to create writer");
}
Managing instances
- Getting an instance "key" value of user data type
Foo
try {
writer.get_key_value(data, ref instance_handle);
} catch (DDS.Exception) {
}
- Registering an instance of type
Foo
InstanceHandle_t instance_handle = InstanceHandle_t.HANDLE_NIL;
instance_handle = writer.register_instance(data);
- Unregistering an instance of type
Foo
try {
writer.unregister_instance(data, ref instance_handle);
} catch (DDS.Exception) {
}
- Disposing of an instance of type
Foo
try {
writer.dispose(data, ref instance_handle);
} catch (DDS.Exception) {
}
Sending data
- Write instance of type
Foo
InstanceHandle_t instance_handle =
InstanceHandle_t.HANDLE_NIL;
try {
writer.write(data, ref instance_handle);
} catch (DDS.Exception) {
Console.WriteLine("***Error: failed to write data");
}
Tearing down a data writer
- Delete DataWriter:
try {
publisher.delete_datawriter(ref writer);
} catch (DDS.Exception) {
Console.WriteLine("***Error: failed to delete writer");
}