Echelon Neuron C User Manual

Page 88

Advertising
background image

76

How Devices Communicate Using Network Variables

of the framework provided by NodeBuilder Code Wizard. Your application might

not contain those functions, and you should consider providing equivalent
functionality in that case.
Parts of the example below are shown in boldface type. This indicates the most

important parts of the example. The rest of the code (non-boldface type) can be
considered more detail-oriented on first read-through.

#include <control.h>
#include <float.h>
#include <mem.h>
#include <snvt_nvt.h>

#pragma relaxed_casting_on
#define TYPE_ERROR 1
#define NV_LENGTH_MISMATCH 2



// Forward-declaration of the fblock’s director function:
void fbSensorDirector(unsigned uFbIndex, int iCommand);


// Declare the SCPTnvType family. Note the use of the
// cp_info modifier; the application must have some
// mechanism to become aware of a type change request
// so that it can validate and honor or reject that
// request. Other possibilities for such a notification
// include the object_disable or offline CP flags, or
// the implementation of this CP as a configuration
// network variable.
SCPTnvType cp_family cp_info(reset_required) nvType;

// SCPTmaxNVLength is optional, but allows for a
// network tool to filter out those types that will
// not be acceptable due to excessive length. The
// type change routine, below, still must verify that
// the requested type is within supported limits.
const SCPTmaxNVLength cp_family nvMaxLength;

// Declare the changeable-type network variable.
// The network variable's initial type also determines
// its maximum length, hence the initialization of the
// nvMaxLength property using the sizeof() operator
// applies to the NV's inital type.
network output changeable_type SNVT_volt_f nvoVolt
nv_properties

{

nvType,
nvMaxLength=sizeof(SNVT_volt_f)
};

// A functional block that contains
// the changeable-type network variable:
fblock SFPTopenLoopSensor {

nvoVolt implements nvoValue;

director

fbSensorDirector;

} fbSensor external_name("Sensor");

// nvTypeLastGood memorizes the last known good type of the
// changeable-type network variable. This is not a
// configuration property, but a simple (EEPROM) variable
// using the same type.
// Note this variable must be initialized correctly, to
// allow the device to come out of the initial reset cycle
// without an accidental type change, and to allow the
// changeable-type NV to function correctly even without
// an explicit type change:
eeprom SCPTnvType nvTypeLastGood =

{{0, 0, 0, 0, 0, 0, 0, 0}, 0, 1, NVT_CAT_INITIAL, 1, 0, 0, 0};

// The following two compiler directives enable the system extension,

Advertising