Explicit propagation of network variables, 60 descr – Echelon Neuron C User Manual

Page 72

Advertising
background image

60

How Devices Communicate Using Network Variables

IO_4 input bit ioButton = BUTTON_UP;

/////////////////////////// Tasks //////////////////////
// I/O task -- handle pushbutton down event
// Just toggle the network variable (nvoSwitchState).
// In this case, no message is sent until a poll request
// is received from a reader device
when (io_changes(ioButton) to BUTTON_DOWN)
{
// button pressed, so toggle state

nvoSwitchState.state = !nvoSwitchState.state;

nvoSwitchState.value = nvoSwitchState.state ? 200 : 0;

}

when (reset) {
io_change_init(ioButton);

... // other reset processing

}

Explicit Propagation of Network Variables

As described earlier in this chapter, a network variable update is normally
initiated when a device assigns a value to an output network variable. In this

case, the network variable update is initiated implicitly by code that is generated

by the compiler to handle the variable’s modification.

An application can also explicitly request propagation for the output network

variable. Such explicit propagation is commonly used in the implementation of
“heartbeats,” regularly scheduled repeated propagation of the most recent value,

as supported by many interoperable devices. This technique could also be useful

in situations where the variable is not directly modifiable, or it might also result
from using pointers to network variables.
A device’s program can propagate any output network variables at any time,

including during initial power up and when transitioning from offline to online.
Network variable propagation on initial power-up can cause network congestion

if many devices are powered-up at the same time, and they all do power-up

propagation.

The application explicitly propagates an output network variable with the

propagate( ) function. The syntax is shown below:

propagate ([

network-var

]);

network-var

Specifies an output network variable identifier.

If no network variable is specified, all output network variables for the device are
propagated. The

network-var

identifier can also be a network variable array

identifier, or an element of a network variable array, as in

nv_array

[

index

]. If a

network variable array name is used without an array index, all elements of the
array are propagated.
The propagate( ) function can be used to send the value of an output network

variable that is declared const, and thus cannot be assigned to. Because a value
assignment triggers implicit network variable propagation, and because a const

variable cannot be assigned to, an explicit mechanism for propagation is

required. See the propagate( ) function in the

Neuron C Reference Guide

for

additional information.

Advertising