EasyManua.ls Logo

Technology SPX5 - User Programmable Scripts; Examples of Useful Lua Scripts; Actions at Constant Intervals; Read and Write of the SPX5 Database Values

Technology SPX5
35 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...
IZI Technology Inc, 3651 Pegasus Dr. Ste. 117 Bakersfield, CA 93308 USA.
Tel: (661) 412-3494 -- email: sales@izitechnology.com
www.izitechnology.com
User Programmable Scripts
The User Programmable Scripts are programmed using Lua. Lua is mature easy to use scripting
language that is used in many products.
Covering the language is out of the scope of this manual but many tutorials and programming
guides can be found on the Internet. The main website for the Lua language is www.lua.org
Examples of Useful Lua Scripts
Actions at Constant Intervals
To time actions at constant intervals, the user can use this snippet of code:
Startup
initialTime = os.time()
Continuous
if os.difftime(os.time(),initialTime)>1 then
initialTime = os.time()
-- Your script action goes in here
end
In the Startup Script an initialTime Variable is declared. This variable will contain the last time the
action has been executed.
In the Continuous Script the script checks how much time has elapsed since the last time that the
action was executed. If the time exceeds one second, then the user script is executed. For other
times, just replace the number 1 by the time you require.
Read and Write of the SPX5 Database values
This example takes a unsigned integer from Word 80 on the internal database and copies it into
Word 90. The functions that will be used for this example are:
mainDatabase:getUINT16(index,swapCode) and mainDatabase:setUINT16(index,value). In both
functions index corresponds to the database address in bytes.
Continuous
local input =mainDatabase:getUINT16(2*80,0)
mainDatabase:setUINT16(2*90,input)