Jump to main content | Jump to Primary Navigation | Jump to Sub Navigation
| Back to main tutorial page | Next tutorial |
This tutorial concerns reading a configuration file and accessing devices through the hardware abstraction layer.
#include <devbot/host.h> int main(void) { BotHost *host; /* create empty BotHost */ host = bot_host_create(); /* perform local initialization of the host */ bot_host_start(host); /* free BotHost data structures */ bot_host_stop(host); /* exit cleanly */ return 0; }
gcc -o basic `pkg-config --cflags --libs devbot` basic.c
<?xml version="1.0" encoding="utf-8"?> <configuration> <host id="Default"> <device name="DevBot" driver="simple_driver"> <property name="Countdown">10</property> <property name="PollPeriod">100000</property> </device> </host> </configuration>
This example defines a single device called DevBot using the simple_driver has a polling period of 100,000 microseconds and a countdown property with value 10. Devbot can be initialized with a configuration file using the bot_configure_file() command, defined in configuration.h. The first argument of bot_configure_file() specifies the BotHost to configure, the second argument indicates the configuration file to use, and the third argument points to the relevant section of the configuration file. After configuration, the command bot_host_start() performs local startup of a BotHost.
#include <devbot/host.h>
Initializing from a file automatically locates and loads any referenced drivers before creating and configuring each device.
BotProperty *message; message = bot_host_register_property(host, "DevBot/Message");
bot_property_set_string(message, "Hello World");
/* Simple DevBot application example * demonstrating a simple text-output driver. * Device created using registration function. */ #include <devbot/configuration.h> #include <devbot/property.h> #include <devbot/host.h> #include <devbot/type.h> int main(void) { BotProperty *message; BotHost *host; /* create empty BotHost */ host = bot_host_create(); /* load configuration file */ bot_configure_file(host, "basic.xml", "Default"); /* 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; }
| Back to main tutorial page | Next tutorial |