Jump to main content | Jump to Primary Navigation | Jump to Sub Navigation


 

Tutorial 2: The XML configuration file

Previous tutorial Next tutorial

This tutorial concerns creating a configuration file.

Contents

  1. Introduction
  2. Basic configuration files
  3. Specifying multiple devices
  4. Specifying multiple hosts
  5. Beyond configuration files

Introduction

Configuration files are a way of storing the initialization information for devices in DevBot. They are written in well-formed XML which conforms to the XML version 1.0 standard. They specify new devices with a unique name and the driver which creates the device. In addition, initial property values are given for mandatory (and perhaps other) properties of the device.

Alternatively it is possible to create applications without the need for an external file. This is covered in Tutorial 3: Creating devices programmatically

Basic configuration files

In the following basic.xml example from the previous tutorial, a device called DevBot is created using the simple driver and the initial values for the Countdown and PollPeriod properties are set.

<?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>

Another example is complex.xml which sets the values of the PollPeriod and DataLength properties for the "Complex" device.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <host id="Default">
        <device name="Complex" driver="benchmark">
            <property name="PollPeriod">100000</property>
            <property name="DataLength">1</property>
        </device>
    </host>
</configuration>

Specifying multiple devices

A single configuration file can specify multiple devices as in the following example for the EPuck driver.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <host id="Default">
        <device name="Epuck" driver="epuck">
            <property name="PollPeriod">250000</property>
            <property name="Camera">0</property>
            <property name="Device">/dev/rfcomm0</property>
        </device>
        <device name="Ifkit" driver="phidget_ifkit888">
            <property name="Serial">28971</property>
            <property name="PollPeriod">80000</property>
            <property name="Sensor0-Bind">ConvertReal</property>
            <property name="Sensor1-Bind">ConvertReal</property>
            <property name="Sensor2-Bind">Rotation</property>
        </device>
    </host>
</configuration>

Specifying multiple hosts

A single configuration file can specify multiple devices as in the following example.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <host id="Player1">
        <device name="Client" driver="pong_client">
            <property name="Dimension">6,25</property>
        </device>
        <device name="Ball" driver="pong_ball">
            <property name="PollPeriod">50000</property>
            <property name="Range">320,240</property>
            <property name="Dimension">8,8</property>
        </device>
    </host>
    <host id="Player2">
        <device name="Client" driver="pong_client">
            <property name="Dimension">6,25</property>
        </device>
    </host>
</configuration>

Beyond configuration files

An important advantage of using configuration files over creating devices programmatically is the ability to reconfigure the hosts, properties and devices without needing to recompile the controller program which uses them. However, configuration files are not suitable for applications which have a large number of properties, devices or hosts, as they grow proportionally with the information they hold. Creating devices programmatically is covered in the next tutorial.

Previous tutorial Next tutorial