beautypg.com

Input_value variable – Echelon I/O Model Reference for Smart Transceivers and Neuron Chips User Manual

Page 34

background image

24

Introduction

input_value Variable

You use the input_value variable to retrieve the input value for an I/O object
when either the io_update_occurs event or the io_changes event occurs. The

input_value built-in variable is a signed long, and it can be cast in the same

manner as any other C variable.

Example:

when (io_update_occurs(ioDevice)) {
if (input_value > 2) {
. . .
}
}

Example: A lamp device could set the value of its nvoSwitch network variable

based on the value of input_value (the switch value):

when (io_changes(ioSwitchInput)) {
nvoSwitch.state =
(input_value == SWITCH_ON) ? ST_ON : ST_OFF;
}

The value of the input_value variable depends on the context in which it is used.

The following combination of when clauses is valid. Because both events refer to
the same I/O object, there is no ambiguity about which object is providing the

input.

when (io_changes(ioDevice) to 4)
when (io_changes(ioDevice) to 3)
{
x = input_value;
}

However, the following combination of when clauses is not a valid context for use
of input_value, because there is no way to know which object is providing the

input value. If the first when clause evaluated to TRUE, input_value would refer
to ioDevice1, but if the second when clause evaluated to TRUE, input_value

would refer to ioDevice2.

when (io_update_occurs(ioDevice1))
when (io_update_occurs(ioDevice2))
{
x = input_value; // from ioDevice1 or ioDevice2?
}

In addition, input_value is valid only after an io_update_occurs or io_changes
event. In the following example, using multiple when clauses produces an

ambiguous value for input_value because the timer_expires event does not

perform I/O. In such cases, use the io_in( ) function to retrieve the value.

when (timer_expires(t))
when (io_update_occurs(ioDevice))
{
x = io_in(ioDevice); // don’t use input_value here
}