Download presentation
1
SmartStruxure™ Lite Solution
Course SmartStruxure Lite Introduction LUA SCRIPTING PPT ver
2
Data Structure 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 N CFG1_Time.time Move to Lua presentation everything down
3
Data Structure – Node & Objects
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
4
Data Structure – Object Properties
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
5
Data Structure – Object Properties
Node . Object . Property . Content Frequent properties to all objects: Present_Value: value of the object Units: BACnet units
6
Data Structure – Content
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
7
Lua programming Lua and Lua4C
8
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
9
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.
10
Local Variable
11
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). Verify..
12
Lua: script execution period
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.
13
Lua: Script Editor The middle section contains the script.
Can be typed directly or pasted from another source (Notepad, etc.)
14
Lua: Script Editor (cont’d)
The output window provides feedback about your script. It will display error messages or print() statements
15
Lua: Script Editor (cont’d)
The “Global Watches” are a list of variables with their current values. Also provides program related values (time, cycle, etc.)
16
Lua keywords Lua support the followings keywords: and break do else
elseif end false for function if in local nil not or repeat return then true until while
17
Lua operators Lua support the followings operators: + - * / ^ =
* / ^ = ~= <= >= < > == ( ) { } [ ] ; : ,
18
Accessing local objects
Controller connected directly to computer or through LAN Use the shortcut ME.xxx 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
19
Accessing local objects (cont’d)
Instance : 150 Node: N001212 Instance : 100 Node: N001111 Instance : 200 Node: N001313 Monitor node Passive nodes print(DEV150.AV1) Print Analog Value 1 (AV1) of a remote object with BACnet device instance #150. print(N BV2) Print Binary Value 2 (BV2) of a remote object with Node ID DEV200.AV49 = ME.AV1 Assign the content of local Analog Value 1 into Analog Value 49 of DEV200 BACnet instance # is recommended; easier portability
20
Addressing (Instances)
Node: N001212 Instance : 100 Node: N001111 Instance : 200 Node: N001313 Monitor node Passive nodes 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.
21
Lua4c: Variable Declaration
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”, “N 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 # Note that the variable must be created before it is used. It is strongly recommended to perform all var() calls before any other operation in a Lua script. The var() is created in a way where it can be called every cycle. A single call is required though. In the case where the object property on which the hook is called does not exist in the database, the script is stopped at the position of the var() call and is restarted 10 seconds later from the beginning. There is some important timing consideration in using the state-time variables: • A state-time variable value is fetched from its hooked property just before a script cycle is started. • If state-time variable is changed by the Lua program, its value will be applied to the hooked property after the end of the cycle
22
Lua4c: Changed() Lua interface function changed.X() Inputs: Outputs:
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
23
Lua4c off_for() off_time() on_time()
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…
24
Lua4c utility functions
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
25
scale() function 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
26
More complex; arrays and for loops
27
More complex; ftp and file management
28
End
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.