23.03.2017 Views

wilamowski-b-m-irwin-j-d-industrial-communication-systems-2011

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LonWorks 41-7<br />

• Network management and diagnostic messages<br />

These messages are used for the node configuration, including the setting of the logical addresses<br />

(domain, subnet, node ID), writing to EEPROM (for application loading), and setting of bindings.<br />

Router configuration messages belong to this group, too.<br />

• Generic message passing<br />

Applications can create and send any messages, including the above-specified ones. With the help<br />

of application-specific message codes, own application-specific protocols can be implemented.<br />

41.4 the Application Layer Programming Model<br />

User applications for Neuron Chips are programmed in Neuron C, an extended ANSI C dialect. Since<br />

applications are event based, Neuron C contains a construct called task, which is called whenever an event<br />

has occurred or a condition is fulfilled. The event or condition is defined by a when clause. Events are,<br />

for example, changes of network variable inputs (nv _ update _ occurs), the expiration of timers<br />

(timer _ expires), the changing of I/O pins (io _ changes), or the reset event, which is called<br />

after a reset. The following listing shows a simple application in Neuron C, which controls the state of a<br />

LED using a network variable.<br />

network input SNVT _ switch nviSwitch;<br />

IO _ 0 output bit ledOutput; // specifies LED output<br />

#define LED _ ON 1<br />

#define LED _ OFF 0<br />

when (reset)<br />

{<br />

io _ out(ledOutput, LED _ OFF);<br />

}<br />

when (nv _ update _ occurs(nviSwitch) )<br />

{<br />

// set LED according to NV value<br />

if (nviSwitch.state == 1)<br />

io _ out(ledOutput, LED _ ON);<br />

else<br />

io _ out(ledOutput, LED _ OFF);<br />

}<br />

The first two lines declare an input network variable named nviSwitch and an output bit object<br />

using I/O pin 0. After that, two tasks are defined by when clauses. The first one is called after the reset<br />

of the node and sets the output pin to a defined state (LED off). The second task is called when the<br />

above-declared network variable is changed externally. Since nviSwitch has the structured type<br />

SNVT _ switch, the concrete switch state is taken by the appropriate structure member. According to<br />

the state value, the LED is switched on or off.<br />

As shown in the example, special directives declare network variables and I/O objects. Further directives<br />

are used for configuration parameters, function objects, and other node-specific properties.<br />

The interface between the Neuron C program and the application layer of the Neuron Chip is offered<br />

as a set of library functions. Important functions are implemented directly in the firmware. For example,<br />

there are functions to process application-specific messages, for the network management of the<br />

node itself, and for accessing the I/O objects. Other little-used functions, like floating point arithmetic<br />

functions, are linked to the application image by the Neuron C linker, if required.<br />

By running the Neuron C compiler, two kinds of files are created: First, application images contain<br />

the compiled code, which is loaded to the node later, and second, the associated external interface<br />

© <strong>2011</strong> by Taylor and Francis Group, LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!