Working with data writers.
More...
Working with data writers.
Setting up a data writer
- Set up publisher
- Set up a topic
- 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);
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);
}
- 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);
}
- Disposing of an instance of type
Foo
try {
writer.dispose(data, ref instance_handle);
}
Sending data
- Set up data writer
- Register instance
- Write instance of type
Foo
InstanceHandle_t instance_handle =
InstanceHandle_t.HANDLE_NIL;
try {
writer.write(data, ref instance_handle);
Console.WriteLine("***Error: failed to write data");
}
Tearing down a data writer
- Delete DataWriter:
try {
publisher.delete_datawriter(ref writer);
Console.WriteLine("***Error: failed to delete writer");
}