Echelon NodeBuilder FX/PL Examples User Manual

Page 25

Advertising
background image

NodeBuilder FX/PL Examples Guide

17

same as the type of the primary input network variable of the functional block
(nviDigitalOutput).

11. Click Generate and Close.

12. Open the device template’s Source Files folder and open ncexample.h by double clicking it. Add

the following lines of code shown in bold:

#ifndef _NcExample_H_
#define _NcExample_H_

#define SWITCH_ON 0x01
#define SWITCH_OFF 0x00

This code defines enumerations to use for on and off values for the buttons and LEDs.

13. Open DigitalOutput.nc from the Source Files folder and add the following lines of code shown

in bold to the DigitalOutputProcessNV() method:

void DigitalOutputprocessNV(void)
{

// drive the LED as appropriate:

GizmoSetLed(deviceState.nvArrayIndex,
nviDigitalOutput[deviceState.nvArrayIndex].state);
}

This code causes the LED to be updated whenever the input network variable on the associated
DigitalOutput functional block receives an update.

14. Open the DigitalInput.nc file from the Source Files folder and add the following lines of code:

void setDOutValue(unsigned uIndex) {

// set the nvo to reflect the input line state.

if (fblockNormalNotLockedOut(DigitalInput[uIndex]::global_index)) {

nvoDigitalInput[uIndex].state

= input_value ? SWITCH_OFF : SWITCH_ON;

}
}

when (io_changes(ioButton1)) {
setDOutValue(0);
}
when (io_changes(ioButton2)) {
setDOutValue(1);
}

This code causes the output network variables on the DigitalInput functional blocks to be updated
whenever the value from the hardware (for example, the push-buttons) changes.

The fblockNormalNotLockedOut() function ensures that the functional block is enabled.
Alternatively, the following clause can also be used for the argument of the
fblockNormalNotLockedOut()

function to retrieve the current functional block index:

fblock_index_map[nv_table_index(nvoDigitalInput[uIndex])]

The DigitalInput[uIndex]::global_index clause is used to demonstrate the scope
operator (‘::’), and because this clause is more efficient.

15. Open DigitalOutput.nc from the Source Files folder. Add the following code in bold to the

FBC_WHEN_RESET

else-if statement:

else if ((TFblock_command)iCommand == FBC_WHEN_RESET)

{

Advertising