Jump to main content | Jump to Primary Navigation | Jump to Sub Navigation
| Previous tutorial | Next tutorial |
This tutorial teaches you how to create devices programmatically i.e. without using an external configuration file. We will produce a program that behaves identically to that described in Tutorial 1: First steps, but without the need for an external configuration file.
Creating devices programmatically is useful for physically reconfigurable systems, or (more realistically) cases where the configuration file mechanism might be too cumbersome i.e. dealing with 60 range finders positioned regularly around a vehicle.
Such configuration involves the initialization of the property values using accessor methods defined in property.h. If bot_host_start() is called and at least one mandatory property remains uninitialized a warning is printed and FALSE returned. When bot_host_stop() is called, all devices associated with the specified host are destroyed.
bot_host_create_device(host, "DevBot", "simple_driver");
period = bot_host_register_property(host, "DevBot/PollPeriod"); bot_property_set_uint(period, 100000); countdown = bot_host_register_property(host, "DevBot/Countdown"); bot_property_set_uint(countdown, 1);
/* Simple DevBot application example * demonstrating a simple text-output driver. * Device created programmatically. */ #include <devbot/property.h> #include <devbot/host.h> #include <devbot/type.h> int main(void) { BotProperty *message, *period, *countdown; BotHost *host; /* create empty BotHost */ host = bot_host_create(); /* create new device programmatically */ bot_host_create_device(host, "DevBot", "simple_driver"); /* acquire and set mandatory properties */ period = bot_host_register_property(host, "DevBot/PollPeriod"); bot_property_set_uint(period, 100000); countdown = bot_host_register_property(host, "DevBot/Countdown"); bot_property_set_uint(countdown, 1); /* perform local initialization of the host */ bot_host_start(host); /* acquire message property */ message = bot_host_register_property(host, "DevBot/Message"); /* change message property */ bot_property_set_string(message, "Hello World"); /* free BotHost data structures */ bot_host_stop(host); /* exit cleanly */ return 0; }
| Previous tutorial | Next tutorial |