VisualHMI dynamic drawing: continuous register drawing commands, LUA set_array, and enclosed filling

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

The dynamic drawing control allows you tocreate and modify graphical elements(points, lines, circles, rectangles, closed shapes, image cropping) on the HMI, just like a drawing board. Core mechanism: By writing drawing commands through a continuous registersegments - both PLC and LUA can be used for drawing.of

1. Attribute introduction

AttributeDescription
Data addressDrawing command write address
Line thicknessLine segment width in pixels 1~4
Command modeSingle (write one command at a time) / Multiple (write multiple commands at a time)
Drawing modeRedraw (refresh old image with new instructions) / Overlay (continue to add on the screen)
Canvas colorRGB color
Completion notificationClear instructions and notify after drawing is completed

VisualHMI dynamic drawing: continuous register drawing commands, LUA set_array, and enclosed filling插图

Continuous register format:

LW     CMD         绘制图形类型
LW+1   Draw_Cnt    数据包数量(一个矩形=1个包)
LW+2   DATA        N 个字节数据段
LW+1+N END         结束字段,固定 0xFF00

VisualHMI dynamic drawing: continuous register drawing commands, LUA set_array, and enclosed filling插图1

2. Graphics command list

CommandData segment formatExample
Draw a point (0x0001)X, Y, ColorAA55 00 0F F1 2000 0001 0001 01F4 00F0 F800 FF00 CCCC (Red point 500,240)
Connect endpoints (0x0002)Number, X, Y of each point (connected as a line), color listAA55 00 1D F1 2000 0002 0003 FFFF 012C 012C 01F4 012C 01F4 0064 02BC 0064 FF00 CCCC
Rectangle (0x0003)Top left X, Y, bottom right X, Y, color (per rectangle)AA55 00 1F F1 2000 0003 0002 011E 00AA 01AA 010A 471A 0258 0064 02BC 012C 2C4A FF00 CCCC (Two rectangles)
Rectangle fill (0x0004)Same as aboveAA55 00 1F F1 2000 0004 0002 ... FF00 CCCC
Circle (0x0005)Center X, Y, Radius, ColorAA55 00 13 F1 2000 0005 0001 01F4 00FA 0096 FEA0 FF00 CCCC
Circle Fill (Command Code Also 0x0005, Source Text Does Not Distinguish Flag Bits)DittoAA55 00 13 F1 2000 0005 0001 0200 0100 0085 FEAA FF00 CCCC
Image (0x0007)PIC ID, Top Left X, Y, Bottom Right X, Y, Target X, YAA55 00 19 F1 2000 0007 0001 0000 0021 0027 00A3 0040 0168 0168 FF00 CCCC
Closed Area Fill (0x0008)X, Y, ColorAA 55 00 11 F1 1001 0008 0001 01A4 00F6 F800 FF00 CCCC
Spectrum (0x0009)Quantity, Color, Xn, Yn pairsAA55 00 33 F1 2000 0009 0005 F800 0168 0064 0064 ... FF00 CCCC (5 vertical lines)
Line Segment (0x000A)Quantity, Color, XnS, YnS, XnE, YnEAA55 00 33 F1 2000 000A 0004 ... FF00 CCCC
Rectangle Inverse Color (0x000D)Top Left, Bottom Right, Color (Inverse Color = 0xFFFF - Color)AA55 00 15 F1 2000 000D 0001 0168 00E6 0190 010E 49F1 FF00 CCCC

VisualHMI dynamic drawing: continuous register drawing commands, LUA set_array, and enclosed filling插图2

PIC ID View: After compilation, there is image.bin in the private resource package; for PIC ID comparison, open build/image.xml under the project directory (id=0 corresponds to the background image of scene 0).

VisualHMI dynamic drawing: continuous register drawing commands, LUA set_array, and enclosed filling插图3

Pits filled in enclosed areas:Requires two dynamic drawing controls- one for drawing an enclosed shape (e.g., 0x2000), and one for setting the fill color (e.g., 0x1001, CMD=0x0008). The control setting the fill color must belayered on top of the control drawing the enclosed shape; the background of the screen must be a solid color, otherwise normal filling cannot be achieved.

3. LUA drawing (set_array)

In LUA, continuous registers are used to implement drawing. Taking on_update triggering as an example (the word setting button writes values 1~13 of 0xF000 to switch graphics):set_array()Implement drawing by writing to continuous registers. Take triggering with on_update as an example (set the value of the button to 0xF000, and switch between graphics 1-13):

baseGraphCmd = {
  opint=0x0001, Connection=0x0002, rect=0x0003, rectFill=0x0004,
  circle=0x0005, PIC=0x0006, ICON=0x0007, fill=0x0008,
  Spectrum=0x0009, line=0x000A, rectFillOr=0x000D }
-- 画点: 命令, 点数, X, Y, 颜色, 结束
local data = {baseGraphCmd.opint, 0x0003,
  0x01F4, 0x00F0, 0xF800, 0x01F5, 0x00F1, 0xF800, 0x01F6, 0x00F3, 0xF800,
  0xFF00}
set_array(VT_LW, 0x2000, data)   -- 单条模式地址 0x2000

Multiple mode puts multiple graphic commands into an array in order and writes them at once (address 0x3000); overlay mode appends directly without clearing the screen (address 0x4000).

VisualHMI dynamic drawing: continuous register drawing commands, LUA set_array, and enclosed filling插图4

VisualHMI dynamic drawing: continuous register drawing commands, LUA set_array, and enclosed filling插图5

VisualHMI dynamic drawing: continuous register drawing commands, LUA set_array, and enclosed filling插图6

Three modes to choose from:Single = draw one graphic at a time (redraw), Multiple = draw multiple graphics at a time (redraw), Overlay = continuous drawing without clearing the screen. For dynamic refreshing like trends/spectra, use redraw, and for cumulative display like process schematics, use overlay.

Compiled from the VisualHMI development documentation of Guangzhou Dacai Technology (hmi-doc.gz-dc.com), the configuration control tutorial "Dynamic Drawing" is owned by Dacai Technology.

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

Leave a Reply

Your email address will not be published. Required fields are marked *.