Defining Function Blocks

This section details the following topics:

Function Blocks

Creating a New Function Block

Editing a Function Block

Function Blocks

A function block provides an abstract view on a device to applications that want to employ the devices’ functionality. Thus, it is a consistent, self-contained set of (potentially re-usable) properties and capabilities.

For more detailed concept of function block please refer to section Function Block Specification in the Vorto Developer Guide.

A function block definition is typically structured as follows:

  • Properties
    • Status
    • Configuration
    • Fault
    • Events
  • Services - they represent the functional operations offered by the device.

Creating a New Function Block

Prerequisites

  • You have started your IDE.
  • You have selected the the Vorto perspective.
  • You have created a project (refer to Defining Projects)

Proceed as follows

  1. In the Vorto Model Project Browser, select the project in the Select Vorto Project drop-down list.
    Select a Project
  2. Right-click in the Functionblocks area and choose New Functionblock from the context menu.
    The Create Function Block Model dialog opens.
    Creating function block designer dialog
  3. Enter a name as Function Block Name, for example, ColorLight.
  4. Adjust the entries for the input fields Namespace and Version, if necessary.
  5. Optionally, enter a description in the Description entry field.
  6. Click Finish.
    The new function block (ColorLight) is created. Furthermore, the function block DSL source file (.fbmodel) is generated and displayed in the model editor. The file contains a complete structure according to the DSL syntax with the values given in the preceding steps.
    Generated source

Editing a Function Block

Prerequisites

You have created a function block project (refer to Creating a New Function Block).

Proceed as follows

Edit the function block project by extending the generated source file in the function block DSL editor.

Example

namespace com.mycompany.fb
version 1.0.0
displayname "ColorLight"
description "A light makes the environment bright and colorful"
category hue
using com.mycompany.type.Color ; 1.0.0

functionblock ColorLight {
    configuration {
        optional brightnessLevel as int
        optional defaultColor as Color
    }

    fault {
        mandatory bulbDefect as boolean "true if the light bulb of the lamp is defect"
    }

    operations {
        setR(r as int)
        setG(g as int)
        setB(b as int)
    }

}