The nv_update_succeeds and nv_update_fails events – Echelon Neuron C User Manual

Page 64

Advertising
background image

52

How Devices Communicate Using Network Variables

io_out(ioLED,

nviLampState.state);

}

In the following example, when a thermostat device receives a new temperature

setpoint, it checks the current temperature and turns the heater on or off if

necessary:

network input SNVT_temp nviSetpoint;
network output SNVT_switch nvoHeater;
network output SNVT_temp nvoCurrentTemp;
when (nv_update_occurs(nviSetpoint)) {
nvoHeater.state = nvoCurrentTemp < nviSetpoint;
}

Most applications do not need to know the source of an input network variable
update, and can focus on implementing behavior in response to receiving the

updated network variable value.

However, the nv_in_addr built-in variable, described in the

Neuron C Reference

Guide

, provides addressing information about the device that originated the

update.

The nv_update_succeeds and nv_update_fails
Events

When a network variable update or poll fails, the nv_update_fails event

evaluates to TRUE. If no network variable is specified for the event, it evaluates

to TRUE for any network variable update or poll that failed on that device. If
multiple network variables are specified, the event can be TRUE once for each

network variable update or poll that failed.
Similarly, the nv_update_succeeds event evaluates to TRUE whenever an output
network variable update has been successfully sent or polled values have been

received from all the writers.
You can use the nv_update_fails event for any output network variables. The
following example illustrates using the nv_update_fails event with a single

output network variable:

network output SNVT_switch nvoSwitch;

when (nv_update_fails(nvoSwitch))
{
// take some corrective action
}

Here is an example of testing for network update failure and success:

boolean heater_failed;
network output SNVT_switch nvoHeater;
when (nv_update_fails(nvoHeater))
{
heater_failed = TRUE;
// remember update failure
}

when (nv_update_succeeds(nvoHeater))
{

Advertising