PIStudio Manual
  • 1. Welcome
  • 2. Installation
  • 3. Getting Started
    • 3.1 Creating a project
    • 3.2 Configuring communication
    • 3.3 Configuring the Screens
    • 3.4 Compiling project
    • 3.5 Simulation
    • 3.6 Download project
  • 4. Software Menu
    • 4.1 Home Menu
      • 4.1.1 Project
      • 4.1.2 Edit
      • 4.1.3 Screen
      • 4.1.4 Appearance
      • 4.1.5 Tool
      • 4.1.6 Help
    • 4.2 Project menu
    • 4.3 Project screens menu
  • 5. Project Settings
    • 5.1 Project Settings
    • 5.2 HMI IP
    • 5.3 Installment
    • 5.4 Extend
    • 5.5 Security
  • 6. Object
    • 6.1 Buttons/Switchs
      • 6.1.1 Bit switch
      • 6.1.2 Bit lamp
      • 6.1.3 Word switch
      • 6.1.4 Word lamp
      • 6.1.5 Keypad switch
      • 6.1.6 Function switch
      • 6.1.7 Combination switch
      • 6.1.8 Slider Switch
    • 6.2 Input/Display
      • 6.2.1 Numeric Input/Display
      • 6.2.2 Character Input/Display
    • 6.3 Charts
      • 6.3.1 Common settings in Chart objects
      • 6.3.2 Alarm Record Display
      • 6.3.3 Data Record Display
      • 6.3.4 Recipe display
      • 6.3.5 File list
      • 6.3.6 History Trend Chart
      • 6.3.7 Trend Chart
      • 6.3.8 XY Plot
      • 6.3.9 History XY Plot
    • 6.4 Meters
      • 6.4.1 Pointer Meter
      • 6.4.2 Clock
      • 6.4.3 Bar
      • 6.4.4 Runbar
    • 6.5 Display
      • 6.5.1 Indirect window
      • 6.5.2 QR code
      • 6.5.3 Drop-Down list
      • 6.5.4 Flow component
      • 6.5.5 Picture
      • 6.5.6 Rotation picture
      • 6.5.7 Camera display
      • 6.5.8 Camera Control
      • 6.5.9 Printer
    • 6.6 Draw
      • 6.6.1 Date
      • 6.6.2 Time
      • 6.6.3 Text
      • 6.6.4 Table
      • 6.6.5 Line
      • 6.6.6 Polygon
      • 6.6.7 Cycle/ Ellipse
      • 6.6.8 Arc
      • 6.6.9 Rectangle
      • 6.6.10 Broken line
      • 6.6.11 Linear scale
      • 6.6.12 Arc scale
    • 6.7 Custom Object
    • 6.8 Common Settings
      • 6.8.1 General window
      • 6.8.2 Text
      • 6.8.3 Graphic
      • 6.8.4 Security
      • 6.8.5 Animation
  • 7. Library
    • 7.1 Shape
    • 7.2 Address Library
    • 7.3 Text library
    • 7.4 Font Library
    • 7.5 Address Mapping
  • 8. Basic Functions
    • 8.1 Address Editor
    • 8.2 Installment
    • 8.3 Data Record
    • 8.4 Alarm
      • 8.4.1 Bit alarm
      • 8.4.2 Word alarm
    • 8.5 Recipe
    • 8.6 Trend Chart
    • 8.7 History XY Plot
    • 8.8 User Permission
    • 8.9 MessagePrompt
  • 9. Scripts
    • General script
      • 9.1 Script type
      • 9.2 Script usage
      • 9.3 Script Functions List
      • 9.4 Function Description
    • Lua script
      • 9.5 Lua Editor
      • 9.6 Lua Script Interfaces
      • 9.7 Lua Shortcut Hotkey
  • 10. Advanced Functions
    • 10.1 Remote Access
    • 10.2 Camera
    • 10.3 Email
    • 10.4 Video Player
    • 10.5 Audio Player
    • 10.6 LAN Monitoring
    • 10.7 USB keyboard
  • 11. PLC Protocols
    • 11.1Allen-Bradley FreeTag Ethernet/IP (CompactLogix)
    • 11.2 Allen-Bradley MicroLogix
    • 11.3 Barcode Scanner
    • 11.4 EPSON-TM-T82II/TM-XXX
    • 11.5 Hitachi EHV Series (Ethernet)
    • 11.6 IEC60870-5 104 Client
    • 11.7 LG XGK FEnet Ethernet
    • 11.8 Mitsubishi FX1S, 1N, 2N series
    • 11.9 Mitsubishi FX5U Ethernet
    • 11.10 Mitsubishi FX5U serial port
    • 11.11 Mitsubishi L02 MELSEC (Ethernet)
    • 11.12 Mitsubishi QJ71E71 Ethernet
    • 11.13 MODBUS RTU Master
    • 11.14 MODBUS RTU Slave (All function)/(All function OneBaseAddress)
    • 11.15 MODBUS TCP Slave (All function)
    • 11.16 Omron EC55
    • 11.17 Omron NX Ethernet/IP
    • 11.18 OpenCAN
    • 11.19 SHIMADEN FP23 protocol
    • 11.20 SHIMADEN SR90 protocol
    • 11.21 SHIMADEN Standard protocol
    • 11.22 Siemens S7-200 Smart (Ethernet)
    • 11.23 Siemens S7-300
    • 11.24 Siemens S7-1200 Ethernet
    • 11.25 Siemens Logo
    • 11.26 Siemens S7-XXX Ethernet
    • 11.27 User defined protocol
    • 11.28 WECON PLC LX2V/ LX2E/ LX3V/LX3VP/LX3VE/LX3VM
    • TSPL printer protocol user manual
  • 12. HMI internal registers
    • 12.1 System special address (HUW/HUX)
    • 12.2 System special address (HSW/HSX)
  • 13.Tools
    • 13.1 Off-line
    • 13.2 On-line
    • 13.3 USB flash disk download
    • 13.4 Font Pack
    • 13.5 Address List
    • 13.6 Decompile
    • 13.7 Password Tool
    • 13.8 Download Tool
  • 14. Others
    • 14.1 Setup Menu
    • 14.2 Touch Screen Calibration
    • 14.3 Levi2PI
Powered by GitBook
On this page

Was this helpful?

  1. 9. Scripts
  2. Lua script

9.5 Lua Editor

manual download link:https://drive.google.com/drive/folders/1XbyB-j_lFq6eirMnccR1HS4TkkKsMrtD?usp=sharing

PreviousLua scriptNext9.6 Lua Script Interfaces

Last updated 4 years ago

Was this helpful?

Foreword

Lua version:5.3.4

Lua script is currently only available in PI+ or models ending with i(like PI3070i). Only these two types of HMI can use the Lua editor and object to develop lua scripts. The following operations are based on PI3070i project.

This article only introduces the use of lua object in PIStudio.

1.Lua editor

The editor is divided into two areas, one is the script file area, and the other is the script editing area.

1.1 Script file area

The script file area is located on the left side, named after the Lua, It will be referred to as the Lua node hereinafter.

1.1.1 Lua node

1.Create new file: right-click the Lua node to select new file, and enter a name in pop-up window, (the name starts with an underscore or letter);

2.Refresh list: the file edited (new/deleted/renamed) by the user externally, the configuration is not refreshed. In this case this function needs to be used to synchronize changes;

✎Note:

There is no script file for the newly created project. Following two new files will automatically generate.

Script_BG.lua: is the global background script file, which includes initialization and timing functions

Script_Screen.lua: is a screen script file, and each screen can have initialization, timing, and close functions

At any time, as long as there is a new operation, the software will judge whether the above two files exist, and which one is missing will be automatically filled.

1.1.2 Lua child node

After creating a new file, expand the Lua node to display several script files. The following is referred to as child nodes.

Child node color description:

Red: encrypted file

Yellow: read-only file

Green: existed file or refresh the list to turn white to green

White: The newly created file, and the project will turn green after refreshing, protecting or reopening the project

1.Delete: right-click the child node to delete. The deleted node will be placed in the recycle bin.

2.Rename: right-click child node to rename.

3.Encryption: right-click the child node, select encryption. Each file can be set with an independent password(length 1-6, only uppercase/lowercase letters and numbers are accepted).

Encryption mode: When this mode is turned on, you need to verify the password to view and edit.

Read-only mode: This mode is opened without verifying the password, if you want to edit, you must first release the protection

4. Unprotect: Right-click on the child node, select Unprotect, enter the password to release.

✎Note:

If user forgets the password, the script file can never be recovered, the software will not storage any passwords, developers need to keep the password by themselves carefully.

1.2 Script editor

The script editor is divided into three blocks: the upper part is the toolbar, the middle part is the editing area, and the lower part is the output area.

1.2.1 Tool bar

Open any script file, the toolbar is as follows:

Save, cut, copy, paste, word address, bit address, zoom in, zoom out, display spaces and tabs, grammar check.

Find and replace, undo and redo and more functions see shortcut keys manual.

1.2.2 Editor area

1. Highlight color: Lua's built-in keywords has a different color with the Lua interface functions. The functions written by users will not be highlighted

2. Auto-complete: Lua function auto-complete prompts, Lua chunk auto-complete (such as if xx then end), also supports the completion of all the words in this script file. Use the Enter key to select candidates words, use the Tab key to turn off automatic completion.

3. Automatic indentation: The tab key can add 4 spaces

4. Calling prompt: only available for Lua interface functions

5. Hovering hint: for example the mouse stays near the o letter position of demo() , it will display the prototype of the function

6. Shortcut keys: In order to facilitate users, various shortcut keys have been added. Detailed description: Configure Lua shortcut keys.doc

7. Interface document: The scripts listed in the interface document will be distinguished by the highlighted color in the editing area. You can check whether the interface is called incorrectly by judging the color change. Detailed description: Lua interface manual.

1.2.3 Output area

Click the syntax button in the toolbar to perform a grammar check. If the script is written incorrectly, it will be displayed in the window. Double-click the prompt to locate the "near" line of the error.

2.Lua object

Lua objects are mainly used to call functions and complete user interface interactions. Normally, functions should not be written in objects. Next, we will explain how to use the objects.

2.1 How to use LuaScrip object

Find the custom part->LuaScript on the right side, drag and draw to generate a part. Double-click the part to pop up a dialog box.

Click Lua object will trigger two actions, that is, rising and falling scripts;

1. Falling script: after the button is pressed, the code chunk of the area is executed;

2. Rising script: after the button is raised, the code chunk in the area is executed;

3. Timing script: periodically execute the code.

✎Note:

The timing script is not commonly used because it is similar to the screen background script function. It is not recommended to write and call function here. It should be written in Script_Screen.lua, which is convenient for editing, searching, and replacing operations.

Warning: It is not allowed to write endless loops or call functions that will loop enlessly in the widget. Once used, the entire screen will be stuck, and any buttons will no longer be used. We have to restart the screen to restore.

3.Platform

3.1 File header identification

Any new file will automatically generate a line of code, as shown below:

The format of this variable: file name_limits = number

The file name comes from the newly created file name (without suffix):

_limits:Fixed format, cannot be modified

Description:

Tens digit=1:indicates that the function or global variable defined in this file can be used in the background code file (Script_BG.lua). If it is 0, it is not available.

Ones digit=1:indicates that the functions or global variables defined in this file can be used in the screen code file (Script_Screen.lua) or LuaScript components. If it is 0, it is not available.

✎Note:

If you rename the file manually, you must modify the limits in the file accordingly, otherwise the script file will not take effect.

3.2 Special script file

As mentioned above, the first new build will automatically generate two script files. These two files cannot be deleted and renamed, which will be explained in detail here.

1. Script_BG.lua is a global background script file, which includes initialization and polling functions

we_bg_init(): global initialization, that is, execute once when power on.

we_bg_poll():Global polling, that is, the cycle is repeated after power on.

2.Script_Screen.lua is a screen script file, and each screen has an initialization, polling, and closing functions

we_scr_init_0(): execute this function when screen 0 is initialized

we_scr_poll_0(): when in picture 0, the function is executed repeatedly

we_scr_close_0(): execute this function when screen 0 is closed

The above is the initialization function of screen 0. For screen 100, you can replace 0 with 100. You can add your own function: function we_scr_init_100() end

✎Note:

The above function has a fixed name. If it is modified, it will not cause crash, but the function can be found.

Example: After the screen 0 initialization function is changed to we_scR_init_0(), the script will not be executed when screen 0 is initialized, and then no script will be executed, and nothing will be done because the "we_scr_init_0" function cannot be found.

3.2 Script type (operating mechanism)

There are two types of scripts:

Active: script automatically executed by HMI

Passive: Script executed only after user trigger

The active types includes:

Global _bg_ related functions in Script_BG.lua

Screen _scr_ related functions in Script_Screen.lua

Polling script in Lua object

The passive type scripts include:

The rising and falling script in Lua object.

IMG_256
IMG_256
IMG_256
IMG_256