Lua Manual
Lua Manual
HMI boots up or
exits system screen and enters HMI screen
s1 = "Hello World!"
mem.inter.WriteAscii(300,s1,string.len(s1))
3.1 Lua program window
Double-click on the Lua Program to open the Lua programming window as shown in
the figure below.
The
You can go to [View] to open the [Program monitor variable window]. This window
allows you to monitor the Lua program execution results by specifying the
variables. You can also change the variable in this window. For the operation
example, please refer to the description in 3.2 Debug mode.
3.1.3 Program example helper window
This window lists all the Lua functions, including Basic syntax, Internal memory -$
(for reading and writing), Static memory- $M (internal register for non-volatile
reading and writing), External link (reading / writing address for controller), File
read / write / export / list, Math, Screen (for screen operation), String, System
library, Serial port communication, Text encoding, and Utility.
The window has two parts, the upper part is the instruction list and the lower is
the description and example of each instruction.
By clicking the Add button, you can add the instruction example in the Lua
program. Please refer to Table 3.2 Example of adding Lua instruction.
Table 3.2 Example of adding Lua instruction
3.2 Debug mode
For the Lua program debugging method, please refer to Table 3.3 Lua program debugging
example.
Table 3.3 Lua program debugging example
-- read $100
v1 = mem.inter.Read(100)
-- add 10
v1 = v1 + 1
-- write to $200
rev = mem.inter.Write(200,v1)
s1 = "Hello World!"
mem.inter.WriteAscii(300,s1,string.len(s1))
Step 2: create four numeric display elements on Screen_1. Set the read address as NET1_IP1,
NET1_IP2, NET1_IP3, and NET1_IP4 of Internal Parameter.
3.3 Subroutine execution
You can use subroutines in the Lua program to simplify the program for easy maintenance
and development. In the M instruction to load the
subroutine. Please refer to Table 3.4 Subroutine execution example.
Table 3.4 Subroutine execution example
require "Prog001"
while true do
-- Add loop code here (cyclic run)
-- read $100,$101
v1 = mem.inter.Read(100)
v2 = mem.inter.Read(101)
-- compare these values
result = equal(v1,v2)
--write result to $200
rev = mem.inter.Write(200,result)