Echelon LonTal Stack User Manual

Page 75

Advertising
background image

LonTalk Stack Developer’s Guide

63

Example:
This example defines a four-channel analog-to-digital converter (ADC), with the
following properties:

• Four channels (implemented as an array of functional blocks)
• One gain setting per channel (implemented as an array of configuration

properties)

• A single offset setting for the ADC (implemented as a shared

configuration property)

• A linearization setting for all channels (implemented as a configuration

property array)

#include <s32.h>
#define CHANNELS 4

network output SNVT_volt nvoAnalogValue[CHANNELS];

network input cp SCPTgain nciGain[CHANNELS];
network input cp SCPToffset nciOffset;
network input cp SCPTsetpoint nciLinearization[5];

fblock SFPTopenLoopSensor {
// the actual network variable that implements the
// mandatory 'nvoValue' member of this profile:
nvoAnalogValue[0] implements nvoValue;
} fbAdc[CHANNELS] external_name("Analog Input")
fb_properties {
// one gain factor per channel:
nciGain[0],
// one offset, common to all channels:
static nciOffset,
// one linearization array for all channels:
static nciLinearization = {
{0, 0}, {2, 0}, {4, 0}, {6, 0}, {8, 0}
};
};

This example implements a single output network variable, of type SNVT_volt,

per channel to represent the most recent ADC reading. This network variable

has a fixed type, defined at compile-time, but could be defined as a
changeable-type network variable if needed for the application.
There is one gain setting per channel, implemented as an array of configuration

network variables, of type SCPTgain, where the elements of the array are
distributed among the four functional blocks contained in the functional block

array. Because the SCPTgain configuration property has a default gain factor of
1.0, no explicit initialization is required for this configuration property network

variable.
There is a single offset setting, implemented as a configuration network variable,
of type SCPToffset. This configuration NV applies to all channels, and is shared

among the elements of the functional block array. The SCPToffset
configuration property has a default value of zero.
The SCPToffset configuration property is a type-inheriting configuration

property. The true data type of a type-inheriting property is the type of the

Advertising