Echelon Neuron C User Manual

Page 89

Advertising
background image

Neuron C Programmer’s Guide

77

// and allow for its use even if the target device doesn't support
// system extensions. See text for details, and see the Neuron C
// Reference Guide, Compiler Directives, for details about these
// directives.
#pragma system_image_extensions nv_length_override
#pragma unknown_system_image_extension_isa_warning

// see text!


// changeLength() performs or rejects the type change request.
// It is called from the director function in response to a
// device reset because the SCPTnvType has been declared with
// "cp_info(reset_required)." Other CP flags, such as
// object_disabled, require a different invocation. SCPTnvType
// may also be implemented as a configuration network variable,
// allowing for invocation of the changeLength() function from
// a "when(nv_update_occurs(...))" task.

void changeLength(void) {

// First, check to see if there is anything to do at all:

// is there a real type change request pending? The

// changeLength() function could have been invoked as a

// result of a regular device reset (or whichever other

// update notification event is associated with the nvType CP).


if ((nvoVolt::nvType.type_category != NVT_CAT_NUL)

&& (memcmp((void*)&nvTypeLastGood,(void*)&nvoVolt::nvType,

sizeof(SCPTnvType)) != 0)) {


// In case multiple network variables share the same

// SCPTnvType configuration property, make sure all

// affected network variables are unbound. Use is_bound()

// for all these network variables and reject the type change

// if any reports being bound.

// Check if requested type is within acceptable size

// limits. The sizeof(nvoVolt) function always returns the

// initial size of the network variable, which equals

// its maximum size.


if (nvoVolt::nvType.type_length > sizeof(nvoVolt)) {


// Reject: set the nvType CP back to the last known

// good value, log the error, and notify the

// network tool. In addition to the minimum

// requirements, this example implementation

// also automatically disables the fblock


nvoVolt::nvType

=

nvTypeLastGood;

error_log(TYPE_ERROR);
getObjStatus(fbSensor::global_index)->invalid_request

=

TRUE;

updateNode_Status();
setFblockDisable(fbSensor::global_index,

TRUE);


} else switch (nvoVolt::nvType.type_category) {

case

NVT_CAT_SIGNED_LONG:

case

NVT_CAT_UNSIGNED_LONG:

case

NVT_CAT_FLOAT:


// Accept long and float.

// Store the current type information and, for

// debugging purpose only, also change the length of

// the network variable via its nv_len property. See

// further below for an example implementation of the

//

recommended

get_nv_length_override

technique

for

//

this

network

variable.


nvTypeLastGood

=

nvoVolt::nvType;


#ifdef _DEBUG // see text!
nvoVolt::nv_len

=

nvoVolt::nvType.type_length;

Advertising