EasyManua.ls Logo

DLI DIN4 - 7 Scripting; 7.2 Entering Scripts

Default Icon
57 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
7 Scripting 19
7 Scripting
On its own, a power switch isn't very smart. Programmers can easily add custom functionality by using the built-in
Lua-based scripting language in power controllers.
7.1 Hardware requirements
Lua-based scripting is available in all DIN4 controllers. Beeper, backlight, LCD, voltage and current monitoring
functions are limited to products with appropriate hardware installed.
7.2 Entering scripts
First, for a quick overview of the script language visit the sample scripts page on the Digital Loggers web
site. Log in as admin and use the Scripting link to access the programming page.
Scripting is based on the Lua programming language. A brief introduction is done below, but you may want to
consult the general description, especially if you intend to write more complex scripts.
Script code is organized in functions. Configuration items which allow some scripting reaction to an event (reboot,
autoping failure, etc.) will ask you for the name of the function to call (you will be offered a list of the functions
defined in the script).
Scriptlisting
Save
--[[Thisisasample/testsetofscriptsforDLIpowercontrollers.
Thescriptingimplementationhaschanged,andisnolongercompatible
withtheolderBASICimplementation.Themostimportantchangesare:
-NowLua-based.
-Nomorelinenumbers,blocksofcodeidentifiedbyfunctions.
-MostofON,OFF,etc.arekeptaslegacyfunctions,whichcanbecalledlike
e.gON(2345),ON("2345")orON"2345",yourchoice.
Executionisstillbasedonthreads.Nowthreadsaremorevisibleand
manageable.Trystartingsomeandyou'llseethemappearinginthe
list.
]]--
functionturn_outlets_on()
ON(1)
ON(2)
ON(3)
ON(4)
ON(5)
ON(6)
ON(7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
User script source editor
You will need to define your functions to be able to use scripting. Simply putting calls to existing functions in the
script will not work. Functions are defined like this:
function my_function()
... statements go here ...
end
DLI DIN4 User’s Guide: 20170809T111540Z