User guide

64 How Devices Communicate Using Network Variables
poll(nviSetpoint);
}
when(nv_update_occurs(nviSetpoint))
when(nv_update_occurs(nviCurrent)) {
nvoValve = control_algorithm(nviCurrent, nviSetpoint);
}
While this straight-forward solution is adequate for many devices, it is not
without problems:
The multi-NV polling approach still needs to ensure that all input
network variables have been updated prior to computing a new output
value. The last example also needs to track arrival of all input network
variable updates, as demonstrated in the previous example.
Polling network variables immediately after reset (or power-up) can lead
to network congestion for a site-wide power-up, and can cause the
network stabilization to take some time after power has been applied.
While reset-time polling is not a problem if only a small number of devices issue
only a small number of poll requests, a single device (or its developer) does not
normally know the nature and application algorithm of the other devices in the
network.
When using power-up polls, combined with a suitable technique to monitor input
network variable updates, it is strongly recommended that you insert a random
delay of a few seconds between the reset and the initiation of these poll requests.
This delay helps to spread the power-up peak traffic demand in the network, and
improves overall startup performance.
Example:
network input SNVT_temp nviCurrent;
network input SNVT_temp nviSetpoint;
network output SNVT_volt nvoValve;
mtimer powerupDelay;
when(reset) {
powerupDelay = 16ul * random() + 500ul;
// 0.500 to 4.5s delay
}
when(timer_expires(powerupDelay)) {
poll(nviCurrent);
poll(nviSetpoint);
}
when(nv_update_occurs(nviSetpoint))
when(nv_update_occurs(nviCurrent)) {
nvoValve = control_algorithm(nviCurrent, nviSetpoint);
}
The best option, where appropriate, is to use poll-free techniques. Tracking of
incoming updates, keeping records of last known-good-values or use of
heartbeating sensors are all good tools to solve the problem of initial network
variable updates for many devices.