0% found this document useful (0 votes)
160 views25 pages

Lua Manual

This document describes Lua program execution functions in 3 steps: 1. It explains how to open the Lua programming window to write and edit Lua code, set breakpoints, and monitor variables. 2. It provides an example of debugging a Lua program using breakpoints and monitoring variables. 3. It demonstrates how to call subroutines to simplify code, with an example of loading and executing a subroutine from another file.

Uploaded by

Aydın Zeki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
160 views25 pages

Lua Manual

This document describes Lua program execution functions in 3 steps: 1. It explains how to open the Lua programming window to write and edit Lua code, set breakpoints, and monitor variables. 2. It provides an example of debugging a Lua program using breakpoints and monitoring variables. 3. It demonstrates how to call subroutines to simplify code, with an example of loading and executing a subroutine from another file.

Uploaded by

Aydın Zeki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

3.

Lua program execution function

HMI boots up or
exits system screen and enters HMI screen

Execute Clock macro Execute Lua

Repeat Clock macro execution completed Lua execution completed Repeat

Execute screen cycle macro based


on the delay time of cycle macro No delay and execution continues
(100 ms)

HMI power off


-- 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))
3.1 Lua program window

3.1.1 Lua programming window

Double-click on the Lua Program to open the Lua programming window as shown in
the figure below.
The

[Breakpoint setting] to set or cancel the breakpoints.


3.1.2 Program monitor variable window

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

You can go to [ View] to open the [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)

-- one cycle is 250ms


sys.Sleep(250)
end
function equal (val_1,val_2)
if val_1 == val_2 then
return 1
else
return 0
end
end

You might also like