Top Banner
SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0
28

SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Dec 30, 2015

Download

Documents

Amber Crawford
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

SmartStruxure™ Lite Solution

Course SmartStruxure Lite IntroductionLUA SCRIPTING

PPT ver. 1.1.0.0

Page 2: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 2- SmartStruxure™ Lite solution Training

●Objects follow a BACnet property based format

●Pre-determined list of objects in the database

Node . Object _ Property . Content

eg: ME.AV1_Present_Value.value

DEV100.TL1_Description.type

N000123.CFG1_Time.time

Data Structure

Page 3: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 3- SmartStruxure™ Lite solution Training

Node . Object . Property . Content

●Node is one of the following:

● Node # : SSLite entity

● Device # : BACnet reference, used to create sub-devices

● ME : Local manager (used in Lua programming)

●Object is any of the objects from SSLite database with its sequential

number

● AI#,AIC#,AO#,AV#,BI#,BO#,BV#,CAL#,EV#,FLO#,PG#,MV#,SCH#,TL#,PFC1

● BAC1,C2G1,CBC1,CFG1,EOC1,ETH1,MOD1,SNTP1,ZBC1,ZPC1

Data Structure – Node & Objects

Page 4: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 4- SmartStruxure™ Lite solution Training

Node . Object . Property . Content

●Common properties to all objects:

● Profile_Name: Object profile. Internal use only. DO NOT MODIFY

● Flags: Define Status of object in database. DO NOT

MODIFY

● Object_Name: Name of object. Shown in Building Expert

● Description: Description of object. Shown in Building Expert

● Property_List: List of properties of object. Internal use only. DO NOT

MODIFY

● Tags: User definable field

Data Structure – Object Properties

Page 5: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 5- SmartStruxure™ Lite solution Training

Node . Object . Property . Content

●Frequent properties to all objects:

● Present_Value: value of the object

● Units: BACnet units

Data Structure – Object Properties

Page 6: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 6- SmartStruxure™ Lite solution Training

Node . Object . Property . Content

●Content refers to the metatable values contained in the property

● .value: value of the object

● .time: timestamp (sysclock) of the last change of value of

the object

● .refresh: timestamp of the last update of the object from the

Can2go protocol (object on remote nodes)

● .type: type of the object

Data Structure – Content

Page 7: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Lua programmingLua and Lua4Chttp://www.lua.org/manual/5.2/

Page 8: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 8- SmartStruxure™ Lite solution Training

Lua and Lua4C overview

“Powerful, simple, fast, lightweight, embeddable scripting language”

● Easy syntax

● Easy structure

● No need to define data type

● Total of 8 Lua PG objects

● Maximum size per PG: 64 kB

● Case-sensitive language

Page 9: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 9- SmartStruxure™ Lite solution Training

Optimizing Lua Programs

●Lua Program Information● ”Size used” is a good indicator of how much memory is currently

being used by the Lua tasks.● "Avg. Execution Time" is the most interesting value to complete all

Lua tasks.●Less then 100 ms is used for an “empty” system●500 ms is used for a “good” system●1000 ms or more is used for a overloaded system

●Using Local Variables● To improve memory usage, the "local" keyword can be used when

declaring variables in the Lua code.●It forces the variable name to be temporary and only available from that specific piece of code.

Page 10: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 10- SmartStruxure™ Lite solution Training

Local Variable

Page 11: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 11- SmartStruxure™ Lite solution Training

Optimizing Lua Programs

●Sequence Tuning● PG (program) objects are executed sequentially (from PG1 to PG8).● A critical or heavy (by execution) program should be placed as the first

program (PG1) and the least important as the last program (PG8).

Page 12: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 12- SmartStruxure™ Lite solution Training

● Scripts are executed top-down● Period (sec) defines how often script executes● CPU and function dependent

A period of 1 second means the script will execute at a minimum rate of once per second.

Shortest period is 100 ms.

Lua: script execution period

Page 13: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 13- SmartStruxure™ Lite solution Training

The middle section contains the script.Can be typed directly or pasted from another source (Notepad, etc.)

Lua: Script Editor

Page 14: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 14- SmartStruxure™ Lite solution Training

The output window provides feedback about your script.It will display error messages or print() statements

Lua: Script Editor (cont’d)

Page 15: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 15- SmartStruxure™ Lite solution Training

The “Global Watches” are a list of variables with their current values.Also provides program related values (time, cycle, etc.)

Lua: Script Editor (cont’d)

Page 16: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 16- SmartStruxure™ Lite solution Training

and break do else elseif end false

for function if in local nil not

or repeat return then true until while

Lua support the followings keywords:

Lua keywords

Page 17: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 17- SmartStruxure™ Lite solution Training

Lua support the followings operators:

+ - * / ^ =

~= <= >= < > ==

( ) { } [ ]

; : , . .. ...

Lua operators

Page 18: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 18- SmartStruxure™ Lite solution Training

● Local object properties can be accessed using the following syntax: ● print(ME.AI1) – Print the current value of Analog Input 1 ● print(ME.BV1) – Print the current value of Binary Value 1 ● print(ME.SCH1) – Print current value of Scheduler● ME.BO2 = ON – Assign ON to Binary Output 2● ME.AV2 = 40.3 – Assign 40.3 to Analog Value 2

Controller connected directly to computer or through LANUse the shortcut ME.xxx

Accessing local objects

Page 19: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 19- SmartStruxure™ Lite solution Training

Monitor node

Passive nodes

Instance : 150Node: N001212

Instance : 200Node: N001313

Instance : 100Node: N001111

● print(DEV150.AV1)

● Print Analog Value 1 (AV1) of a remote object with BACnet device instance #150.

● print(N001313.BV2)

● Print Binary Value 2 (BV2) of a remote object with Node ID 001313.

● DEV200.AV49 = ME.AV1

● Assign the content of local Analog Value 1 into Analog Value 49 of DEV200

● BACnet instance # is recommended; easier portability

Accessing local objects (cont’d)

Page 20: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 20- SmartStruxure™ Lite solution Training

Addressing (Instances)

Monitor node

Passive nodes

Instance : 100Node: N001111

Instance : 150Node: N001212

Instance : 200Node: N001313

Keep at least 50 addresses between each MPM node. Every new added device to the MPM, ZigBee, EnOcean etc requires an address in the span.

Page 21: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 21- SmartStruxure™ Lite solution Training

Lua4C extensions have been developed to simplify building automation scripting on SmartStruxure™ Lite Managers.

fanspeed = ME.AI1 -- simple declaration

var(“fanspeed”,”ME.AI1”) -- enables time-based functions (change etc)

Syntaxes also accepted: ● var(“relay_1”, “N001023.BO1” ) – Using Node ID

● var(“relay_2”, “ME.BO2_Description” ) – Description field

● var(“relay_3”, “ME.BO3” )

● var(“relay_4”, “DEV200.BO4” ) – Using Device Instance #

Lua4c: Variable Declaration

Page 22: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 22- SmartStruxure™ Lite solution Training

Lua interface function changed.X() ● This function returns true when the value of X (the variable) has changed

during the previous cycle.

Inputs: ● State-time - X: Variable to monitor for a change.

Outputs:● Boolean - value_changed: true if value changed in the last cycle

Use example: ● var("light","ME.BV1")

● if changed.light and light == ON then -- “Is the statement True or False?”

● print("Someone has turned the light ON")

● end

Lua4c: Changed()

Page 23: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 23- SmartStruxure™ Lite solution Training

off_for() ● Lua interface operator off_state = off_for.variable(off_period)

● The operator off_for returns true if the variable has been OFF (or 0) for the specified amount of time in seconds.

● The operator return false otherwise.

off_time() ● Lua interface operator elapsed_time = off_time.variable()

● The operator off_time returns the period of time elapsed since the value of the variable was turned OFF.

on_time() ● Lua interface operator elapsed_time = on_time.variable()

● The operator on_time returns the period elapsed since the value of the variable turned ON.

Consult Lua guide for more Lua4C Control function…

Lua4c

Page 24: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 24- SmartStruxure™ Lite solution Training

scl.clock: ● return current local time in seconds.milliseconds elapsed since 1970.

scl.reset() ● forces a full reset of the system.

scl.getmac ● returns the ethernet port MAC address of the controller.

scl.getmodel ● returns the controller model.

scl.getserial ● returns the controller serial number.

Consult Lua guide for more utility functions

Lua4c utility functions

Page 25: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 25- SmartStruxure™ Lite solution Training

scale(temperature,0,0,60,255,80)● Linear scale with 2 inputs and 2 outputs

● The example above would linearly translate 0 to 60 and 255 to 80

● The first 0 serves as a bias to the result

scale() function

Page 26: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 26- SmartStruxure™ Lite solution Training

More complex; arrays and for loops

Page 27: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

Schneider Electric 27- SmartStruxure™ Lite solution Training

More complex; ftp and file management

Page 28: SmartStruxure™ Lite Solution Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver. 1.1.0.0.

End