X-600M Users Manual
Appendix G: Lua Scripts
As another example, set a register named
register1
to the value 100:
reg.register1 = 100
or
reg["register1"] = 100
To turn a relay on that has been configured and named
relay4
we could write a Lua script:
io.relay4 = 1
To turn that same relay off, write:
io.relay4 = 0
To only turn relay4 on if event1 is true, write:
if event.event1 == true then
io.relay4 = 1
end
The X-600M will take care of the communication with the device the I/O is found on regardless of where
it is located. If relay4 were half way across the world on a WebRelay device, the single statement
io.relay4 = 1 would still turn it on. The X-600M takes care of making sure that happens.
It is recommended to check the validity of I/O in Lua scripts before using it. If the I/O is not readable by
the X-600M or has not been updated yet, it will read not a number (NaN). This is especially important for
the five Lua scripts. These scripts start running immediately and therefore the I/O states will generally
read NaN until the X-600M can update them.
To check if a number is NaN in a Lua script, check to see if the number is equal to itself. If a number is
not equal to itself, then it is considered to be NaN.
If io.relay1 ~= io.relay1 then
print(“io.relay is NaN”)
end
Variables and Scope
Within the Lua language, a variables scope begins at the first statement after its declaration and lasts
until the last statement of the inner-most block that includes the declaration. For example:
enableDebug()
y = 100
do
local y = 200
print(y)
end
print(y)
This example will print the following to the debug console:
200
100
Y
is a global variable, but inside the “do end” statements,
y
is a local version. If
y
had not been declared
as local, then the global version would have been used and the output would have been.
100
100
Xytronix Research & Design, Inc.
Page 125
Содержание X-600M
Страница 1: ...X 600MTitle Page Goes Here...
Страница 6: ...X 600M Users Manual Page 4 Xytronix Research Design Inc...
Страница 99: ...X 600M Users Manual Setup Pages Xytronix Research Design Inc Page 97...
Страница 116: ...Appendix B Installing New Firmware X 600M Users Manual Page 114 Xytronix Research Design Inc...