0% found this document useful (0 votes)
9 views

Help

Uploaded by

dsrdakota97
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Help

Uploaded by

dsrdakota97
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Machine Translated by Google

Serial port HMI command set

Note:

1. The device receives the command end character of "0XFF 0XFF 0XFF" three bytes (HEX data, not string data).

2. All command names and parameters use ASCII string data, not HEX data, for easy reading and debugging.

3 . All command names use lowercase letters (here only refers to the command names are lowercase, parameters should still be uppercase when they should be uppercase).

Summary table of object and system operation instructions (clicking the instruction name or parameter will automatically jump to the detailed explanation of the instruction)

Serial number command name Function parameter

1 Refresh the page


page page request

2 ref Redraw the control ref obj

3 click Activate control press/pop events click obj,event

4 get Get variable value/constant value with format give that

5 prints Print a variable/constant from the serial port prints att,length

6 printh Print a Hex value from the serial port printh hex

7 always Hide/Show Controls vis obj,state

8 smell Control touch enable smell obj, state

9 edge set Random number range setting edge set minval,maxval

10 add Add data to the curve control add objid,ch,val

11 cle Clear the data in the curve control cle objid,ch

12 add Curve data transparent transmission instruction add objid,ch,qyt

13 doevents transfers system control to screen refresh No parameters

14 let's go Send the current page ID to the serial port No parameters

15 cox Variable type conversion covx att1,att2,length,format

16 stren String variable character length test strlen att0,att1

17 btlen String variable byte length test btlen that0,that1

18 substr String interception substr att0,att1,star,length

19 spstr String Splitting spstr src,dec,key,index

20 touch_j Touch calibration No parameters

21 ref_stop Pause screen refresh No parameters

22 ref_star resume screen refresh No parameters


Machine Translated by Google

sequence

Command name Command function parameter


Number

23 com_stop Pause serial port command execution No parameters

24 com_star Restore serial port command execution No parameters

25 code_c clears the serial port command buffer No parameters

26 rest Reset No parameters

27 there Write a variable to user memory wepo to,add

28 repo Read data from user memory to variables repo to,add

29 wept Transmitted data is written into the user storage area wept add,length

30 rept Transmit data from the user storage area to the serial port rept add,lenth

31 cfgpio Extended IO mode configuration cfgpio id,state,obj

32 crcrest Reset crc initial value crcrest crctype,initval

33 crcputs crc check a variable/constant crcputs att,length

34 crcputh crc check a set of Hex crcputh Hex

crc checks a section of serial port buffer data


35 crcputu crcputu star,length
(valid when recmod=1)

Change the control layer order during operation (only X3, X5


36 setlayer setlayer obj0,obj1
Series Support)

move
37 move Control movement (supported only by X3 and X5 series)
obj,starx,stary,endx,endy,first,time

38 play Audio playback (supported only by X3 and X5 series) play ch,audio,loop

39 twfile Serial port transparent transmission file (only supported by X3 and X5 series) twfile filepath,filesize

40 delfile Delete files (supported only by X3 and X5 series) delfile filepath

41 refile Rename file (supported only by X3 and X5 series) refile srcfilepath,decfilepath

42 findfile Search for files (supported only by X3 and X5 series) findfile filepath, that

43 rdfile Transparent reading of files (supported only by X3 and X5 series) rdfile filepath,addr,size,crc

44 newfile Create a file (supported only by X3 and X5 series) newfile filepath,size

45 newdir creates a folder (supported only by X3 and X5 series) new you

46 deldir delete folder (only supported by X3 and X5 series) It's crazy.

47 run Rename folder (supported only by X3 and X5 series) redir srcdir,decdir

48 finddir Search folder (only supported by X3 and X5 series) you find that
Machine Translated by Google

GUI drawing command summary table (click the command name or parameter to automatically jump to the

Detailed description of the instruction)

Note: GUI drawing instructions are mainly used in the following situations:

When the upper interface editing software cannot meet your special display requirements, use GUI instructions to draw your own pictures to achieve what you want.

Display effect

In most cases, it is not necessary to use these drawing commands. Most applications can be operated through the controls of the interface editing software.

to achieve it.

sequence instruction
Instruction function parameters
Number name

1 cls clear screen command cls color

2 pic refresh command pic x,y,picid

3 picq cut picture command picq x,y,w,h,picid

Advanced Cutting Tool


4 xpic xpic x,y,w,h,x0,y0,picid
make

xstr
5 xstr write command
x,y,w,h,fontid,pointcolor,backcolor,xcenter,ycenter,sta,string

Area filling
6 fill fill x,y,w,h,color
make

7 line drawing command line x,y,x2,y2,color

8 draw draw rectangle draw x,y,x2,y2,color

9 cir draw hollow circle cir x,y,r,color

10 cirs Draw a solid circle cirs x,y,r,color

Detailed explanation of objects and system operation instructions

1.page refresh page

page request
pageid: page ID or page name
Example 1: page 0 (refresh page with ID 0)
Example 2: page main (refresh the page named main)

Remark:

1. The device automatically refreshes page 0 when it is powered on.

2. You can also assign a value to the system variable dp to jump to the page (such as dp=0). The system variable dp can be set and read. For details, please refer to the system

A list of variables.

3. The page instruction is a jump instruction. The code written after the page instruction will be ignored and will not be executed.
Machine Translated by Google

2.ref redraw the control

ref obj

obj: control ID or control name

Example 1: ref 1 (redraw the control with ID

1) Example 2: ref t0 (redraw the control with name t0)

Remark:

If a control is obscured by content drawn by GUI instructions or needs to be displayed again after being obscured by other controls, use ref to redraw it.

3.click activates the press/pop-up event of the control

click obj, event obj:

control ID or control name

event: event number: 0 for pop-up, 1 for press

click b0, 1 (activate the press event of the control named b0)

click 2, 0 (activate the pop-up event of the control with ID 2)

Remark:

The press/pop-up event of the control is automatically activated when the screen is touched. If you want to activate it manually without touching it, just use the click command.

4.get Get variable value/constant value with format

get att att:

variable name

Example 1: get t0.txt (returns the txt attribute value of

control t0) Example 2: get j0.val (returns the val attribute

value of control j0) Example 3: get "123" (returns the constant

string "123") Example 4: get 123 (returns the constant value: "123")

Remark:

1. When the variable obtained by using the get command is of string type, the returned data is 0X70+string internal code+terminator. If it is of numerical type (such as the val

attribute of the progress bar), the device returns 0X71+4-byte hexadecimal data of the variable (int type)+terminator. The storage mode of the numerical value is little-endian

mode (that is, the low bit is in front and the high bit is in the back).

2. The get command can be sent via the serial port, or it can be written into the user code in the upper software editing interface to implement active screen sending of variables

(when actively sending, you can use the printh command to add a custom mark in front to tell the microcontroller which control this variable belongs to).

3. The get command is very similar to the print command, the only difference is that the data returned by get has a start identifier (0x70 or 0x71) and an end identifier (0xff

0xff 0xff), while print does not. 4. For the specific data return format, please refer to the "Serial Port HMI Device Return Data Format" at the end of this table.
Machine Translated by Google

5.prints prints a variable/constant from the serial port

prints att,lenth att:


variable name

lenth: send length (0 is automatic

length) Example 1: prints t0.txt,0 (Send the txt attribute value of control t0, the

length is the actual length) Example 2: prints j0.val,0 (Send the val attribute value of control j0, the default length is 4-

byte integer data, stored in little-endian mode) Example 3: prints "123",0 (Send the

constant string "123", i.e.: 0x31 0x32 0x33) Example 4: prints 123,0 (Send constant value:

123, i.e.: 0x7b 0x00 0x00 0x00) Example 5: prints 123,1 (Send constant value: the lower 1 bit of 123, i.e.: 0x7b)

Remark:

1. When the variable sent using prints is of string type, the device directly returns the string code. If it is of numeric type (such as the val attribute of the progress bar), the device

directly returns the 4-byte integer data of the variable (Hex data, stored in little-endian mode, that is, the low bit is first).

2. When using the prints command to obtain data, the device only sends the data content, without a start identifier or an end identifier.

3. The prints command can be used in conjunction with the printh command to add a custom mark in front to tell the microcontroller which control the variable belongs to).

4. The prints command is very similar to the get command, the difference is that the data sent by get has a start identifier (0x70 or 0x71) and an end identifier (0xff 0xff 0xff), while

prints does not. However, prints can continue to use the printh statement to add any custom identifiers.

6.printh prints a Hex from the serial port

printh hex
hex: hexadecimal string expression of the character to

be sent Example: printh d0 a0 (let the device send two bytes 0xd0 0xa0)

Remark:

1. When using the printh command to send data, the device only sends the specified characters, and does not send the start character, space, or end character.

2. Each group of characters in the parameter must be separated by one and only one space. Both uppercase and lowercase hexadecimal string expressions are supported.

3.printh can only send constants, not variables. Variables need to use the prints command.

7.vis hide/show controls

vis obj,state obj:

control name or control ID


state: state (0 or 1)

Example 1: vis b0,0 (hide b0 control)

Example 2: vis b0,1 (show b0 control)

Example 3: vis 1,0 (hide control with ID 1)

Example 4: vis 1,1 (show control with ID 1)

Remark:

The first parameter is 255, which means all controls on the current page. For example: vis 255,0 (hide all controls on the current page) vis 255,1 (show all controls on the current

page).
Machine Translated by Google

8.tsw control touch enable

tsw obj,state obj:

control name or control ID state:

state (0 or 1) Example 1:

tsw b0,0 (disable the touch of the control named b0) Example 2: tsw

b0,1 (enable the touch of the control named b0) Example 3: tsw 1,0

(disable the touch of the control with ID 1) Example 4: tsw 1,1

(enable the touch of the control with ID 1)

Remark:

The first parameter is 255, which means all controls on the current page. For example, tsw 255,0 (touch screen of all controls on the current page is disabled) tsw 255,1 (touch screen of all controls on

the current page is enabled).

9.randset random number range setting

randset minval, maxval minval:

minimum value maxval:

maximum value

Example: ranset 1,100 (set the current random number generation range to a minimum of 1 and a maximum of 100)

Remark:

1. Before using random numbers, you need to use the randset command to set the random number generation range. If not set, the default is 0 for the minimum and 2147483647 for the maximum.

After setting the range, each time the system variable rand is read, a random number will be obtained.

2. Each time you set a range using the randset command, it will remain valid until the power is turned on again or the device is reset, at which point the default value will be restored.

3. The data type of the random number setting range is int type (i.e. minimum -2147483648, maximum 2147483647).

10.add Add data to the curve control

add objid,ch,val objid:

curve control ID number (must be the ID number here, the control name is not supported) ch: curve

control channel number val: data (maximum 255, minimum 0) Example

1: add 1,0,30 (add data 30 to channel 0 of the curve control with ID 1) Example 2: add 1,1,n0.val

(add data n0.val to channel 1 of the curve control with ID 1)

Remark:

1. The curve data only supports 8-bit data, with a minimum of 0 and a maximum of 255.

2. Each page supports up to 4 curve controls, and each curve control supports up to 4 channels. Data can be sent continuously, and the control will automatically push and display the data. During the

data sending process, the control properties can also be modified at any time, such as modifying the foreground color or background color of each channel at any time.
Machine Translated by Google

11.cle Clear the data in the curve control

cle objid,ch objid:

curve control ID number (must be the ID number here, the control name is not supported)

ch: curve control channel number (255 means all

channels) Example 1: cle 1,0 (clear the 0 channel data of the curve

control with ID 1) Example 2: cle 1,255 (clear all channel data of the curve control with ID 1)

Remark:

1. When the channel number is 255, it means clearing all channel data in this curve control.

12.addt curve data transparent transmission instruction

addt objid,ch,qyt objid: curve

control ID number (must be the ID number here, the control name is not supported) ch: the channel number in the

curve control qyt: the number of points of

the transparent data transmitted this time

Example: addt 1,0,100 (the curve control with ID 1 enters the data transparent transmission mode, and the number of transparent transmission points is 100)

Remark:

1. Curve data only supports 8-bit data, with a minimum of 0 and a maximum of 255. The maximum amount of data transmitted in a single pass is 1024 bytes

2. After sending the transparent transmission command, the user needs to wait for the device to respond before starting transparent transmission of data. After the device receives the transparent transmission

command, it takes about 5ms to prepare the transparent transmission initialization data (if there are many other commands in the serial port buffer before the transparent transmission command is executed, the

time will be longer). After the device is ready for transparent transmission initialization, it will send a transparent transmission ready data to the user (0XFE+terminator), indicating that the device is ready and

can start sending transparent transmission data at this time. The transparent transmission data is pure hexadecimal data, no longer using strings, and no longer requiring terminators. The device will resume

the command receiving state only after receiving the specified amount of data. Otherwise, it will always be in the data transparent transmission state. After the transparent transmission of data is completed,

the device will send an end mark to the user (0XFD+terminator).

3. The curve will not refresh before the specified transparent transmission quantity is transmitted. It will refresh automatically immediately after the transparent transmission is completed.

13.doevents transfers system control to screen refresh

doevents

Example: doevents (this command does not require parameters)

Remark:

1. In the execution of a process with more instructions, or in a long loop statement, all control rights of the system are occupied by this process. Before the end of the process, although the corresponding

memory data can be read and written normally, the screen will not refresh. After adding doevents, the control right can be transferred to the screen refresh. After executing doevents, the screen will refresh all

the changed controls. After the refresh is completed, the control right is returned to the current process to continue execution. Prevent the screen from showing a false dead display state.

2. In most cases, doevents is used in conjunction with while or for statements. For usage, please refer to the examples of while or for statements.
Machine Translated by Google

14.sendme sends the current page ID to the serial port

sendme

Example 1: sendme (this command does not require parameters)

Remark:

When the device receives this command, it will immediately send the ID of the current page to the serial port. If you want to automatically send the page ID every time you refresh the page,

please write a sendme statement in the initialization event of the page. For the sending format, please refer to the "Serial Port HMI Device Return Data Format" table behind this table.

15.covx variable type conversion

covx att1,att2,lenth,format att1: source

variable att2:

target variable lenth:

length of the string (0 is automatic length, non-0 is fixed length) format: declare

the value type (0-number; 1-currency; 2-Hex) Example 1: covx

h0.val,t0.txt,0,0 (convert the val value variable of the slider h0 into a decimal string and assign it to the txt variable of the text t0, the length is automatic) Example 2: covx

t0.txt,h0.val,0,0 (convert the txt decimal string variable of the text t0 into a numeric value and assign it to the val value variable of the slider h0, the length is automatic)

Remark:

1. lenth always indicates the length of the string. When converting a number to a string, it is the length of the target variable. When converting a string to a number, it is the length of the source

variable.

2. If the target variable and source variable are of the same type, the conversion fails.

16.strlen string variable character length test

strlen att0,att1 att0: string

variable to be tested att1: assign the test

result to this variable Example: strlen t0.txt,n0.val

(assign the actual character length of string variable t0.txt to n0.val)

Remark:

1. strlen tests the length in characters, while btlen tests the length in bytes. For example, the length of a Chinese character tested by btlen is 2 bytes, while the length tested by strlen is 1

character.

2. The variable being tested must be of string type, and the variable being written must be of numeric type, otherwise an error will be reported.

17.btlen string variable byte length test

btlen att0,att1 att0:

string variable to be tested att1: assign the

test result to this variable Example: btlen

t0.txt,n0.val (assign the actual byte length of string variable t0.txt to n0.val)
Machine Translated by Google

Remark:

1.btlen tests the length in bytes, while strlen tests the length in characters. For example, the length of a Chinese character tested by btlen is 2 bytes, while the length tested by strlen is 1

character.

2. The variable being tested must be of string type, and the variable being written must be of numeric type, otherwise an error will be reported.

18.substr string interception

substr att0,att1,star,lenth att0: source variable

(must be a string variable) att1: target variable (must

be a string variable) star: the starting position of the

character in the source variable lenth: the length of the intercepted string

Example: substr t0.txt,t1.txt,0,2 (tick 2 characters from position 0 in t0.txt and assign them to t1.txt)

19.spstr string segmentation

spstr src,dec,key,index src: source

variable (must be a string variable) dec: target

variable (must be a string variable) key: separator string

(must be a string variable) index: which part to take (after splitting

the src string with the key string, take the index-th part and assign it to the dec variable) Example: The d character content of data0.txt is: aaaa^bbbb^cccc^dddd

Execute command: spstr data0.txt,t0.txt,"^",2 Running result: The content of t0.txt is: cccc

20.touch_j touch calibration

touch_j

Example 1: touch_j (enter the touch calibration function, this command does not require parameters)

Remark:

All devices have been calibrated before leaving the factory, so this function is usually not necessary.

21.ref_stop Pause screen refresh

ref_stop

Example: ref_stop (This command does not require parameters)

Remark:

1. After pausing screen refresh, all statements will continue to be parsed and executed, and the corresponding attribute assignment operations will also run normally, but the controls on

the screen will not be refreshed, and modifying any attribute of any control will not automatically refresh the display (but the attribute has been modified normally). Until the device receives

the resume refresh instruction (ref_star), the modified control will be refreshed immediately.
Machine Translated by Google

2. After pausing the refresh, even if the ref command is used, the refresh will not be immediate until the ref_star command is executed. However, all gui drawing commands (such as

drawing points, lines, circles, etc.) are not affected and will be displayed immediately.

22.ref_star resume screen refresh

touch_j

Example 1: touch_j (enter the touch calibration function, this command does not require parameters)

Remark:

This command is used in conjunction with ref_stop.

23.com_stop pauses serial port command execution

com_stop

Example 1: com_stop (this command does not require parameters)

Remark:

1. After pausing the serial port command execution, the device will continue to receive commands, but will not execute them. All commands will be placed in the command buffer until

the "com_star" command is received. The device will then execute all commands from the command at the time of the pause to the current one.

2. When using the command pause and resume function, please evaluate whether the serial port buffer size and the maximum number of command buffer queues of your device are

sufficient to support the number of commands you need to cache. These two parameters can be found in the parameter table in the specification of the device you purchased.

24.com_star resumes serial port command execution

com_star

Example 1: com_star (This command does not require parameters)

Remark:

1. After receiving this instruction, the device will execute all instructions from the instruction when it was paused to the current one.

2. When using the command pause and resume function, please evaluate whether the serial port buffer size and the maximum number of command buffer queues of your device are

sufficient to support the number of commands you need to cache. These two parameters can be found in the parameter table in the specification of the device you purchased.

25.code_c Clear all unexecuted commands in the serial port command buffer

code_c

Example 1: code_c (This command does not require parameters)

Immediately clear all the unexecuted commands in the serial port command buffer.
Machine Translated by Google

26.rest Reset

rest

Example: rest (This command does not require parameters)

27.wepo writes a variable to the user storage area (EEPROM)

(Supported only by hardware with user storage)

wepo att,add att:

variable/constant

add: user storage area position (starting from

0) Example 1: wepo t0.txt,10 (write the content of t0.txt to the 10th position of the user storage area, and the space occupied in the storage area is the maximum

setting value of t0.txt + 1, that is, the size represented by the txt-

maxl attribute of t0 + 1) Example 2: wepo "abcd",10 (write the string "abcd" to the 10th position of the user storage area, and the size occupied in the storage area

is 5 bytes) Example 3: wepo 125,10 (write the value 125 to the 10th position of the user storage area, and the size occupied in the storage area is 4 bytes)

Remark:

1. When the content written is a variable string, the space occupied in the storage area is the maximum number of characters of the variable + 1; when the content written is a constant string, the

space occupied in the storage area is the actual number of characters of the constant string + 1.

2. When the written content is a variable value or a constant value, the space occupied in the storage area is uniformly 4 bytes.

3. When using the user storage area for read and write operations, please remember to plan the data area location to avoid data overwriting errors caused by interlaced locations.

28.repo Read data from the user storage area (EEPRO) into a variable

(Supported only by hardware with user storage)

repo att,add att:

target variable add:

user storage area position (starting from 0)

Example 1: repo t0.txt,10 (read data from position 10 of the user storage area to the t0.txt variable. The amount of data read in the storage area is the maximum setting

value of t0.txt + 1, that is, the size indicated by the txt-maxl attribute

of t0 + 1) Example 2.repo n0.val,10 (read data from position 10 of the user storage area to n0.val. The amount of data read in the storage area is 4 bytes)

Remark:

1. When the content read is a variable string, the amount of data read in the storage area is the maximum number of characters of this variable + 1.

2. When the content read is a variable value, the amount of data read in the storage area is uniformly 4 bytes.

3. When using the user storage area for read and write operations, please remember to plan the data area location to avoid data overwriting errors caused by interlaced locations.

29.wept writes transparent data to user storage area (EEPROM)

(Supported only by hardware with user storage)


Machine Translated by Google

wept add,lenth add: user

storage area location (starting from 0) lenth:

transparent transmission

length Example: wept 10,30 (transmit 30 bytes of data to the 10th position of EEPROM, occupying space 10-39)

Remark:

1. After sending the transparent transmission command, the user needs to wait for the device to respond before starting transparent transmission of data. After the device receives the transparent transmission

command, it takes about 5ms to prepare the transparent transmission initialization data (if there are many other commands in the serial port buffer before the transparent transmission command is executed, the

time will be longer). After the device is ready for transparent transmission initialization, it will send a transparent transmission ready data to the user (0XFE+terminator), indicating that the device is ready and

can start sending transparent transmission data at this time. The transparent transmission data is pure hexadecimal data, no longer using strings, and no longer requiring terminators. The device will resume

the command receiving state only after receiving the specified amount of data. Otherwise, it will always be in the data transparent transmission state. After the transparent transmission of data is completed,

the device will send an end mark to the user (0XFD+terminator).

30.rept Read data from the user storage area and transparently transmit it to the serial port

(Supported only by hardware with user storage)

rept add, lenth add:

user storage area position (starting from 0)

lenth: length read and transparently

transmitted Example: rept 10, 30 (read 30 bytes from position 10 of the user storage area and transparently transmit to the serial port)

Remark:

Regardless of whether the data in the storage area is a string or a value, the device reads and sends the specified number of bytes to the serial port in hexadecimal, and does not send a terminator.

31.cfgpio extended IO mode configuration

(Supported only by hardware with extended IO)

cfgpio id,state,obj id: serial

number of extended IO

state: configuration mode (0-pull-up input mode, 1-control event binding input mode, 2-push-pull output mode, 3-PWM output mode, 4-open-drain mode) obj: bound

control name or ID (this parameter is only valid when configured as control event binding input mode, and invalid in other modes) Example

1: cfgpio 0,0,0 (Configure io0 as pull-up input. After configuring this mode, the system variable pio0 can be used to read the current input level at any time, such as:

n0.val=pio0) Example 2: cfgpio

1,2,0 (Configure io1 as push-pull output. After configuring this mode, the system variable pio1 can be used to control the current output level at any time, such as: pio1=1)

Example 3: cfgpio 2,1,b0

(Configure io2 as the control event binding input, and the binding control is b0. After configuration in this mode, when io2 generates a falling edge, it will trigger the press

event of the b0 control, and when it generates a rising edge, it will trigger the pop-up event of the b0 control)

Example 4: cfgpio 4,3,0 (Configure io4 as PWM output mode. Before configuration, you need to set the duty cycle, that is, pwm4 in the system variable)

Remark:

1.Only io4-io7 of K0 series supports PWM output, and only io6-io7 of X5 series supports PWM output. Other IOs do not support it. Configuring other IOs to PWM mode will result in an error.
Machine Translated by Google

2. When using the control event binding input mode, the controls on the current page at the current configuration moment can be bound. Controls on other pages cannot be bound

(even controls that occupy global memory). After binding the controls on the current page, when you refresh the page or switch to another page, the binding event will no longer

be triggered. Therefore, you need to re-bind each time you refresh the page. It is recommended that the binding code be written in the pre-initialization event of the page.

32.crcrest resets the initial value of crc

crcrest crctype,initval crctype:

crc check type (must be 1, Modbus crc16 check method) initval: initial
value (usually 0xffff) Example 1:

crcrest 1,0xffff (reset CRC initial value to 0xffff for subsequent data verification)

Remark:

1. After resetting, you can use crcputs or crcputh or crcputu to verify the specified data. After the verification, read the system variable crcval to obtain the verification result.

2. For the complete CRC check example code, please refer to: Using CRC check data in the program

33.crcputs crc checks a variable/constant

crcputs att,length att:


variable name

length: length of data to be checked (0 is automatic

length) Example 1: crcputs t0.txt,0 (CRC check string variable t0.txt)

Example 2: crcputs "abc",0 (CRC check string constant "abc")

Remark:

1. Use crcputs or crcputh or crcputu to verify the specified data. After the verification is completed, read the system variable crcval to obtain the verification result.

2. For the complete CRC check example code, please refer to: Using CRC check data in the program

34.crcputh crc check a group of Hex

crcputh Hex
Hex: hexadecimal string expression of the data to be verified (each byte is separated by a

space) Example 1: crcput 03 25 (CRC verification hex: 0x03, 0x25)

Remark:

1. Use crcputs or crcputh or crcputu to verify the specified data. After the verification is completed, read the system variable crcval to obtain the verification result.

2. For the complete CRC check example code, please refer to: Using CRC check data in the program
Machine Translated by Google

35.crcputu crc checks a section of serial port buffer data (valid when recmod=1)

crcputu star,length star:


the starting bit of the serial port

buffer data length: the length of the

data to be verified Example 1: crcputu 0,22 (verify the first 22 bytes of the serial port buffer, valid when recmod=1)

Remark:

1. Use crcputs or crcputh or crcputu to verify the specified data. After the verification is completed, read the system variable crcval to obtain the verification result.

2. For the complete CRC check example code, please refer to: Using CRC check data in the program

36.setlayer changes the control layer order during operation

(Only supported by X3 and X5 series)

setlayer obj0,obj1 obj0:

the control ID or control name of the layer to be

changed obj1: control ID or control name (place obj0 control above this control, this parameter 0 means to place obj0 control below all controls,

this parameter 255 means to place obj0 control above all

controls) Example 1: setlayer n0,b0 (place n0 control above b0

layer) Example 2: setlayer n0,255 (place n0 control on the top layer)

37.move control movement

(Only supported by X3 and X5 series)

move obj,starx,stary,endx,endy,first,time obj:control name

or control ID starx:starting
coordinate X

stary:starting
coordinate Y

endx:ending
coordinate X endy:ending coordinate Y first:priority

(0-100, the larger the number,

the higher the priority) time:moving time (in ms) Example:move t0,0,0,200,200,0,300 (control t0 moves from (0,0) to (200,200), priority is 0, time is 300ms)

Remark:

You can write multiple move instructions of different priorities at the same time, and the system will move in order of priority. The one with the highest priority will move first, and after the move is completed, the

next priority instruction will be started.

38.play Audio playback

(Only supported by X3 and X5 series)


Machine Translated by Google

play ch,audio,loop ch:


audio channel
number audio:

audio ID loop:
whether to loop Example: play 1,3,0 (play the audio file with ID 3 on audio channel 1, not looping)

Remark:

1.The play command is only used to configure and start audio playback. To pause and stop, please use the system variables audio0 and audio1.

2. The play command controls an audio channel that is independent of the video. It has nothing to do with the audio channel used in the video and will not cause any conflict.

3. The audio playback function is global and does not belong to a specific page. Therefore, after the play command starts the playback, the audio will continue to play even if the page is jumped. If you want to

stop playing after leaving the page, you can use the audio0/audio1 system variables in the page's leave event to close or pause the audio playback status of the specified channel.

39.twfile serial port transparent transmission file

(Only supported by X3 and X5 series)

twfile filepath,filesize
filepath: target file path (e.g. "ram/0.jpg" or "sd0/1.jpg") filesize:
file size Example: twfile "ram/0.jpg",10345 (transmit a file of size 10345 to the memory file system, the file name is "0.jpg")
Example:
twfile "sd0/a.jpg",10345 (transmit a file of size 10345 to the SD card root directory, the file name is "a.jpg")

Remark:

1. To use the memory file system, you must first configure the size of the memory file system in the project configuration options. The default memory file system size for a new project is 0, which means it cannot

be used.

2. For detailed file transmission logic, please refer to the "Advanced Application and Special Instructions Detailed Explanation" document. Click here to jump to the detailed description page.

40.delfile delete files

(Only supported by X3 and X5 series)

delfile filepath
filepath: file path (e.g. "ram/0.jpg" or "sd0/1.jpg") Example
1: delfile "ram/0.jpg" (delete the "0.jpg" file in the memory file system)
Example 2: delfile "sd0/a.jpg" (delete the "a.jpg" file in the root directory of the SD card)

Remark:

To use the memory file system, you must first configure the size of the memory file system in the project configuration options. The default memory file system size for a new project is 0, which means it cannot be

used.
Machine Translated by Google

41.refile renames a file

(Only supported by X3 and X5 series)

refile srcfilepath,decfilepat srcfilepath:

source file path decfilepath:

target file path Example 1: refile "ram/

0.jpg","ram/1.jpg" (rename 0.jpg in the memory file system to 1.jpg) Example 2: refile "sd0/a.jpg","sd0/b.jpg"

(rename a.jpg in the SD card root directory to b.jpg)

Remark:

To use the memory file system, you must first configure the size of the memory file system in the project configuration options. The default memory file system size for a new project is 0, which means it cannot

be used.

42.findfile Find files

(Only supported by X3 and X5 series)

findfile filepath,att filepath:

file path att: write the

search result to the variable, which must be a numeric variable (0-search failed; 1-search

successful) Example 1:findfile "ram/0.jpg",va0.val (search for 0.jpg in the memory file system and return the result to va0.val)

Example 2:findfile "sd0/a.jpg",sys0 (search for a.jpg in the root directory of the SD card and return the result to sys0)

Remark:

To use the memory file system, you must first configure the size of the memory file system in the project configuration options. The default memory file system size for a new project is 0, which means it cannot

be used.

43.rdfile transparent reading file

(Only supported by X3 and X5 series)

rdfile filepath,addr,size,crc filepath: file

path addr: starting

address of file data size:

transparent read data size**(if 0, a 4-byte integer in little endian mode is returned to represent the file size)** crc:

add CRC checksum to the end of the data (0-no crc; 1-crc16; 10-crc32) Example

1:rdfile "ram/0.jpg",0,10,1 (starting from data position 0 of the "0.jpg" file in the memory file system, read 10 bytes transparently transmitted to the serial

port, and add a crc16 checksum to the end of the data. The total is 10+2=12

bytes) Example 2:rdfile "sd0/a.jpg",0,10,10 (starting from data position 0 of the "a.jpg" file in the root directory of the SD card, read 10 bytes transparently

transmitted to the serial port, and add a crc32 checksum to the end of the data. The total is 10+4=14 bytes)

Remark:

1. To use the memory file system, you must first configure the size of the memory file system in the project configuration options. The default memory file system size for a new project is 0, which means it

cannot be used.

2. The CRC16 check algorithm is MODBUS CRC16. Click here to view the reference function code . The CRC32 check algorithm is standard CRC32.
Machine Translated by Google

44.newfile creates a file


(Only supported by X3 and X5 series)

newfile filepath,size filepath:

file path (e.g. "sd0/1.txt") size: file size (in

bytes, up to 2147483647) Example 1: newfile "ram/0.txt",4096

(create a file named "0.txt" in the memory file system with a size of 4096 bytes) Example 2: newfile "sd0/1.txt",4096 (create a file named

"1.jpg" in the root directory of the SD card with a size of 4096 bytes)

Remark:

1. To use the memory file system, you must first configure the size of the memory file system in the project configuration options. The default memory file system size for a new project is 0, which means it

cannot be used.

45.newdir creates a folder


(Only supported by X3 and X5 series)

new you

dir: folder directory (such as: "sd0/newfolder/")

Example: newdir "sd0/a/" (create a subdirectory named a in the root directory of the SD card)

Remark:

1. The internal memory file system does not support subdirectories, but the SD card supports subdirectories. The directory path must end with "/".

46.deldir delete folder


(Only supported by X3 and X5 series)

deldir dir dir:

folder directory (such as: "sd0/newfolder/") Example:

deldir "sd0/a/" (delete the subdirectory named a in the root directory of the SD card)

Remark:

1. The internal memory file system does not support subdirectories, but the SD card supports subdirectories. The directory path must end with "/".

47.redir rename folder


(Only supported by X3 and X5 series)

redir srcdir,decdir srcdir:

source folder directory (such as: "sd0/newfoldersrc/") decdir:

target folder directory (such as: "sd0/newfolderdec/") Example: redir

"sd0/a/", "sd0/b/" (change the subdirectory named a to b in the root directory of the SD card)

Remark:

1. The internal memory file system does not support subdirectories, but the SD card supports subdirectories. The directory path must end with "/".
Machine Translated by Google

48.finddir find folder

(Only supported by X3 and X5 series)

finddir dir,att dir: folder

directory (such as: "sd0/newfolder/") att: write the search

result to the variable (0-search failed; 1-search successful. This variable must be a numeric type variable) Example: finddir

"sd0/a/",sys0 (find whether there is a subdirectory a in the root directory of the SD card, and return the result to sys0)

Remark:

1. The internal memory file system does not support subdirectories, but the SD card supports subdirectories. The directory path must end with "/".

Detailed explanation of GUI drawing instructions

Note: GUI drawing instructions are mainly used in the following situations:

When the upper interface editing software cannot meet your special display requirements, use GUI instructions to draw by yourself to achieve the display effect you want. In most cases, there is no need to

use these drawing instructions, and most applications can be achieved through the control operations of the interface editing software.

1.cls clear screen command

cls color color:

decimal color value or color code Example 1: cls

1024 (use the decimal color value 1024 to refresh the screen) Example 2:

cls RED (use the color code RED (RED represents red) to refresh the screen)

Remark:

1. For the color code table supported by the device, please refer to the "Serial Port HMI Color Code Table" after this table.

2. All color parameters in the instructions in this instruction table can use color codes supported by the device or decimal color values. Please be aware.

2.pic brush command

pic x,y,picid x: x

coordinate of the starting

point; y: y coordinate of

the starting point;

picid: picture ID; Example 1: pic 10,20,0 (displays the picture with picture ID 0 in the resource file at the coordinate

position (10,20)) Example 2: pic 40,50,1 (displays the picture with picture ID 1 in the resource file at the coordinate position (40,50))
Machine Translated by Google

3.picq picture cutting command

Format: picq x,y,w,h,picid x: x coordinate

of the screen starting point; y: y

coordinate of the screen starting

point; w: width of the

area; h: height of the

area; picid: picture ID;

Example 1: picq 20,50,30,20,0 (cut the area of picture 0 starting coordinate (0,0) with width 30 and height 20 to the screen for display, and the starting coordinate of the screen is (20,50))

Remark:

This command requires that the image must be a full-screen image, otherwise the cut image is not what you want. The cut area on the image overlaps the display area on the screen.

4.xpic advanced image cutting instructions

Format: xpic x,y,w,h,x0,y0,picid x: x coordinate of the

screen starting point; y: y coordinate

of the screen starting point; w: area

width; h: area height; x0: x coordinate of the

picture starting point; y0: y coordinate

of the picture starting point; picid:

picture ID; Example 1:

xpic 20,50,30,20,40,15,0 (cut the area of picture 0 starting coordinate (40,15) width 30 height 20 to the screen for display, and the display starting coordinate on the screen is (20,50))

5.xstr writing instruction

xstr x,y,w,h,fontid,pointcolor,backcolor,xcenter,ycenter,sta,string x: starting point coordinate x; y: starting point coordinate y; w:

area width; h: area height;

fontid: font library ID;

pointcolor: font color;

backcolor: background

color (when sta is set to a

cut image or picture, backcolor indicates

the picture ID); xcenter: horizontal alignment (0 is left alignment, 1 is center alignment, 2 is right alignment); ycenter: vertical

alignment (0 is top alignment, 1 is center alignment, 2 is bottom alignment); sta: background fill mode (0 is

cut image, 1 is monochrome, 2 is picture, 3 is no background, when sta is set to a cut image or picture,

backcolor indicates the picture ID) string: character content; Example 1: xstr 0,0,100,30,1,RED,BLACK,1,1,1,"ÿÿ" Example explanation: Use font library 1 to write "ÿÿ" in the area with the starting

coordinates (0,0), width 100,

height 30, font color RED, background color

BLACK (if you don't want to write the background color (i.e. no background), you can set the sta parameter to 3), the horizontal alignment is centered, and the vertical alignment is also centered.

Remark:

1. When the characters written exceed the set w, the line will be automatically wrapped. If there are remaining characters after wrapping to h, they will be ignored.

2. For an explanation of the color value, see the remarks of the cls directive.
Machine Translated by Google

6.fill area filling instruction

fill x,y,w,h,color x: starting

point coordinate x; y:

starting point coordinate

y; w: area width; h:

area height; color:

fill color; Example 1: fill

0,0,100,30,RED (fill the area with RED color at the starting coordinate (0,0) with a width of 100 and a height of 30)

Remark:

For an explanation of the color value, see the remarks of the cls directive.

7. Line drawing command

line x,y,x2,y2,color x: starting

point coordinate x; y:

starting point coordinate

y; x2: ending point

coordinate x; y2: ending

point coordinate y; color:

line color; Example 1: line 0,0,100,100,RED (draw a RED line between coordinates (0,0) and (100,100))

Remark:

For an explanation of the color value, see the remarks of the cls directive.

8.draw draw rectangle

draw x,y,x2,y2,color x: starting

point coordinate x; y:

starting point coordinate

y; x2: ending point

coordinate x; y2: ending

point coordinate y; color:

line color; Example 1: draw 0,0,100,100,RED (draw a rectangle with the upper left corner at (0,0), the lower right corner at (100,100), and the color is RED)

Remark:

1.Draw draws a hollow rectangle. If you need to fill a solid rectangle, please use the fill area filling command directly.

2. For an explanation of the color value, see the remarks of the cls directive.
Machine Translated by Google

9.cir draw a hollow circle

cir x,y,r,color x:

center coordinate

xy: center

coordinate yr: radius

color: line color; Example 1: cir 100,100,30,RED Draw a hollow circle with a radius of 30 and a color of RED with coordinates (100,100) as the center

Remark:

For an explanation of the color value, see the remarks of the cls directive.

10.cirs draw a solid circle

cirs x,y,r,color x:

center coordinate

xy: center

coordinate yr: radius

color: fill color; Example 1: cirs 100,100,30,RED Draw a solid circle with a radius of 30 and a fill color of RED with the coordinates (100,100) as the center.

Remark:

For an explanation of the color value, see the remarks of the cls directive.

Tip: All color parameters in the instructions in this instruction table can use color codes supported by the device or decimal color values.
Machine Translated by Google

HMI Writing Syntax

ÿTable of contentsÿ

1. Assignment Operation

2. Operation

3. Cross-page operation control properties

4. HMI logic statements

1. [Assignment operation]

•All assignment operations can be written into the control event in the upper editing state, or transmitted through the serial port (remember to add three 0xff terminators for serial

port transmission)

ÿString attribute assignment:

t0.txt="123" Assigns "123" to the txt property of the t0 control

t0.txt=t1.txt Assigns the txt property of the t1 control to the txt property of the t0 control

The following is an incorrect assignment:

t0.txt=123 Cause of error: The txt attribute of the t0 control is of string type, and the attribute value constant of string type must be enclosed in double quotes

t0.txt=h0.val Error reason: The val attribute of the h0 control is a numeric type and cannot be assigned to a string type attribute

ÿAssigning numerical attributes

n0.val=123 Assign 123 to the val attribute of the n0 control

n0.val=h0.val Assign the val attribute of the h0 control to the val attribute of the n0 control

dim=80 Assign 80 to the system variable dim (the backlight brightness immediately changes to 80

brightness) baud=115200 Assign 115200 to the system variable baud (the screen baud rate immediately changes to

115200) n0.val=baud Assign the current baud rate system variable of the screen to the val attribute of the n0 control

The following is an incorrect assignment:


Machine Translated by Google

n0.val="123" Error reason: The val attribute of the n0 control is a numeric type, and the attribute assignment constant of the numeric type should not have double quotes.

n0.val=t0.txt Error reason: The txt attribute of the t0 control is a string type and cannot be assigned to a numeric type attribute

Kind tips:

1. So far, only the txt attribute is of string type, and the other attributes are of numeric type.

2. String types and numeric types can be converted and assigned to each other through the covx instruction. For details, please refer to the covx instruction description in the instruction

set.

2. [Calculation Operation]

1All operations do not support multiplication and division priority, nor do they support bracket priority. The order is unified from left to right. Please pay special attention.

•All calculation operations can be written into the control event in the upper editing state, or transmitted through the serial port (remember to add three 0xff terminators for

serial port transmission)

ÿNumerical type variable operation

Supported operators: + - * / % & | ^ << >>

Examples:

n0.val=n0.val+n1.val+2
n0.val++
n0.val+=2
n0.val=n1.val%3
n0.val=h0.val*10
n0.val*=10
n0.val=n1.val&3
n0.val=n1.val^5
.....

1The following is an incorrect calculation method:

n0.val=t0.txt+1 Cause of error: Numeric variables must be operated on and assigned to numeric variables.

n0.val=1+"2" Error reason: Numeric variables must be operated on and assigned to numeric variables.

ÿString type variable operation

Operator "+"

Examples:

t0.txt="1"+"2"
t0.txt=t0.txt+t1.txt
t0.txt+="abc"+"xy"

The following is an incorrect way of writing operations:

t0.txt=1+2 Cause of error: 1 and 2 are both numeric constants. String type variables can only be added to string constants/variables, not to a numeric constant/variable.
Machine Translated by Google

t0.txt=t0.txt+h0.val Error reason: h0.val is a numeric variable and cannot be added to a string variable

Operator "-"

Examples:

t0.txt=t0.txt-1 delete the last character of t0.txt

t0.txt=t0.txt-3 delete the last 3 characters of t0.txt t0.txt-

=n0.val delete the last n0.val characters of t0.txt

In string variable operations, "-" means deletion, so when using "-", the string variable must be "-" a numerical constant/variable to indicate how many characters to delete. This is different

from using "+". When using "+", it must be string + string; when using "-", it must be string - numerical value.

3. [Cross-page operation control properties]

In most cases, we are operating the control properties of the current page. If you need to operate the control properties of other pages, please write as follows:

[Page].[Control].[Property]=XXX

Example:

main.t0.txt="123" Assign the value "123" to the t0.txt attribute of

the main page main.t0.txt=set.t3.txt Assign the value of t3.txt of the set page to t0.txt of the
main page set.t4.txt="abc" Assign the value "abc" to t4.txt on the set page

Special note: When operating control properties across pages, whether reading or assigning values, the vscope property of the operated control must be set to global (private by default),

otherwise the operation will fail.

4. [HMI logic statements]

•Note: All logic statements can only be written into the control event in the upper editing state, and serial port transmission logic statements are not supported.

1. If statement

Example 1: (If t0.txt is equal to "123456" then switch to page 1)

if(t0.txt=="123456") {

page 1
}

Example 2: (If t0.txt is not equal to "a" nor equal to "b", then switch to page 1)
Machine Translated by Google

if(t0.txt!="a"&&t0.txt!="b") {

page 1
}

Example 3: (If t0.txt is equal to "a" or equal to "b", then switch to page 1)

if(t0.txt=="a"||t0.txt=="b") {

page 1
}

Example 4: (The following statement written in the press event of button b0 will switch the txt content of b0 back and forth between start and stop)

if(b0.txt=="start") {

b0.txt="Stop" }
else {

b0.txt="Start"
}

Example 5: (The following statement written in the press event of button b0 will switch the txt content of b0 back and forth between 1, 2, and 3)

if(b0.txt=="1")

{ b0.txt="2"
}else if(b0.txt=="2") {

b0.txt="3"
}else

{ b0.txt="1"
}

Remark:

1. Numeric type variables support: >; <; ==; !=; >=; <=

2. The string type only supports: ==; !=

3. If judgment does not support bracket priority, for example: if((t0.txt=="a"||t0.txt=="b")&&t1.txt=="1") is not supported! Also, do not have extra spaces.

4. Operations are not allowed during if judgment, for example: if(n0.val+2==3) is not supported.

2. While Statement

Example 1: (n0.val keeps increasing until it reaches 100. During the increase, the screen will not refresh until all statements in the whole process are completed)
Machine Translated by Google

while(n0.val<100) {

n0.val++
}

Example 2: (n0.val keeps increasing until it reaches 100. During the process of increasing, the screen will continuously refresh the display of n0 control)

while(n0.val<100) {

n0.val++
doevents
}

Remark:

1. In the execution of a process with more instructions, or in a long loop statement, all control rights of the system are occupied by this process. Before the end of the process,

although the corresponding memory data can be read and written normally, the screen will not refresh. After adding doevents, the control right can be transferred to the screen

refresh. After executing doevents, the screen will refresh all the changed controls. After the refresh is completed, the control right is returned to the current process to continue

execution. Prevent the screen from showing a false dead display state.

2. During the while statement loop, the device will not respond to touch events, and the serial port instructions will be received in the buffer but will not be executed until all

statements in the current process are executed. Please use it with caution to avoid entering an infinite loop.

3. for statement

Example 1: (n0.val keeps increasing until it reaches 100. During the increase, the screen will not refresh until all statements in the whole process are completed)

for(n0.val=0;n0.val<100;n0.val++) { }

Example 2: (n0.val keeps increasing until it reaches 100. During the process of increasing, the screen will continuously refresh the display of n0 control)

for(n0.val=0;n0.val<100;n0.val++)

{ doevents
}

Remark:

1. In the execution of a process with more instructions, or in a long loop statement, all control rights of the system are occupied by this process. Before the end of the process,

although the corresponding memory data can be read and written normally, the screen will not refresh. After adding doevents, the control right can be transferred to the screen

refresh. After executing doevents, the screen will refresh all the changed controls. After the refresh is completed, the control right is returned to the current process to continue

execution. Prevent the screen from showing a false dead display state.

2. During the for statement loop, the device will not respond to touch events, and the serial port instructions will be received in the buffer but will not be executed until all statements

in the current process are executed. Please use it with caution to avoid entering an infinite loop.
Machine Translated by Google

Serial port HMI system variable list

Note: All variable names use lowercase characters.


Machine Translated by Google

sequence

Name Meaning Examples/Notes


Number

1.dp=1 (set the current page to 1, equivalent to page 1)

1
dp Current page ID 2.prints dp,0 (send the current page ID to the string

ÿ)3.n0.val=dp (the current page ID is assigned to n0.val)

2 dim Current backlight brightness value (0-100) 1.dim=50 2.dim=dim+10 3.dim=dim-10

1.dims=50 2.dims=dims+10 3.dims=dims-


3 dims: default backlight brightness value after power on (0-100)
10

baud=9600 Note: The baud rates supported by the device are: 2400
Current baud rate value (this modification, drop
4 baud 4800 9600 19200 38400 57600
Lost after power on)
115200230400 256000 512000 921600

Default baud rate value on power-on (after power-off

5 bauds Save, and continue to have it after next power-on bauds=9600

effect)

spax=2 Note: Only characters written by xstr instruction have


Character display horizontal spacing (power-on default
6 spax The character display spacing of the control is determined by the properties inside the control.
is 0)
Decide.

spay=2 Note: Only for characters written by xstr command


Character display vertical spacing (power-on default
7 spay The character display spacing of the control is determined by the properties inside the control.
is 0)
Decide.

8 thc touch brush color when drawing 1.thc=RED 2.thc=1024

9 thdra touch drawing function switch thdra=0 (off) thdra=1 (on)

Automatic sleep time without serial port data (single

Bit: seconds, minimum 3, maximum 65535,


10 ussp ussp=30 (automatically enters sleep mode if there is no serial port data for 30 seconds)
The default value of power on is 0 [0 means closing the serial port data

Automatic sleep after timeout])

Automatic sleep time without touch operation (single

Bit: seconds, minimum 3, maximum 65535,


11 thsp thsp=30 (automatically enters sleep mode after 30 seconds of no touch operation)
The default value is 0 when powered on [0 means turning off the touch timeout

Automatic sleep])

thup=0 (touch will not automatically wake up after sleep) thup=1 (sleep

Touch to automatically wake up in sleep mode Touch to wake up automatically after sleep) Note: No matter thup is 0 or 1,
12 thup
Off (power-on default 0) When there is a touch operation in sleep mode, the device will send a touch

Touch the coordinates to the serial port.


Machine Translated by Google

Serial

name meaning Examples/Notes


number

usup=0 (the serial port will not wake up automatically after

sleep) usup=1 (the serial port will wake up automatically after sleep)

Serial data automatic wake-up switch in sleep Note : The default setting is 0 when powered on, and it will not wake
13 usup
mode (power-on default 0) up automatically. You need to send sleep=0 to wake up the screen.

If it is set to 1, the serial port will automatically wake up immediately

after receiving any data.

wup=255 (default at power-on, refresh the page before

sleep after waking up) wup=2 (refresh the specified page

14 whoops Refresh page settings after waking up from sleep after waking up: 2) Note: When the device is in sleep state,

the wup=X assignment transmitted from the serial port can

also be executed.

sleep=0 (exit sleep) sleep=1 (enter sleep ) Note: The

following instructions can be executed in sleep mode: get,

print, printh. You can also execute the assignment

statement of sleep=1, wup=X, and support upper software


15 sleep Sleep
online, and other instructions will not be executed. If it is

hardware with extended IO, when IO is configured to bind

control events, no interrupt events will be generated in

sleep mode.

bkcmd=0 (no result returned) bkcmd=1 (only successful

result returned) bkcmd=2 (only failed result returned)

bkcmd=3 (result returned for both success and failure )

Note: This setting only affects the result returned when

Set the data returned when the serial command is executed the serial port command is executed successfully or failed.
16 bkcmd
successfully or failed (the default value is 2 when powered on) When the command written in the upper software editing

interface is executed incorrectly, an error result will be

returned. When it is successful, no execution result will be

returned. This setting will not affect the data returned when

obtaining device control data.

sendxy=0 (off) sendxy=1 (on) Note : 1 After turning on

the sending function, the device will send the touch

coordinates through the serial port when a touch is


17 sendxy Send touch coordinates in real time
pressed. 2. For the format of sending coordinates, please

refer to the "Serial Port HMI Device Return Data Format"

table behind this table.

delay=100 (make the device pause for 100ms) Note : After

executing the delay command, the device CPU will not execute
18 delay Delay
any instructions, but will continue to accept serial port commands

and save them in the serial port command buffer.


Machine Translated by Google

Serial

name meaning Examples/Notes


number

dim=rand (assign a random number to the backlight

brightness)n0.val=rand (assign a random number to the n0.val

variable)Note: 1. Before using random numbers, you need to

use the randset command to set the random number

generation range. If not set, the default is 0 for the minimum

19 rand Random Numbers and 2147483647 for the maximum. After setting the range, each

time you read the system variable rand, you will get a random

number. 2. Each time you set the range using the randset

command, it will remain valid until the power is turned on

again or the device is reset to restore the default.

tch0: Current touch coordinates Xtch1: Current touch coordinates

Ytch2: Coordinates when last pressed Xtch3: Coordinates

20 tch0-tch3 Real-time touch coordinates when last pressed y Note: Touch coordinates can only be read,

not assigned. When not pressed, the real-time coordinate data

is 0.

String writing: addr=256HEX writing:

addr=0x0100The above two writing methods have the same

meaning, and the same address is configured. After configuration,

there is a power-off save function. Note: 1. The valid address

range is 256-2815 (i.e. 0x0100- 0x0aff), 0 is no address,

65535 is the broadcast address, the broadcast address can

only be used for broadcast data, and a certain device cannot be

configured as a broadcast address. The factory default address

21 addr Device Address is 0, that is, there is no address. 2. When sending a command

to a device with an address, you need to add 2 bytes of address

data before the command, send it in hex mode, 2 bytes little end

mode, for example, the address configured for the device is

addr=256, then when sending it to him, you need to add two

bytes in front of the command: 0x00 0x01 (note that it is 0x0100

when configuring, and the low bit is in front when sending the

command, so it is 0x00 0x01, which is the opposite of the

configuration writing).

n0.val=crcval (the current CRC check result is assigned to n0.val)

prints crcval,2 (the lower 2 bits of the current CRC check result

are printed to the serial port) Note: 1. Use crcrest to reset the

CRC verification result (can only be obtained but CRC value first. After resetting, you can use crcputs or

22 crcval not set. Please use crcrest command to reset the crcputh or crcputu to check the specified data. After the

initial value before use) check is completed, read the system variable crcval to obtain

the check result) 2. For the complete CRC check example

code, please refer to: Using CRC Check Data in the Program
Machine Translated by Google

Serial

name meaning Examples/Notes


number

n0.val=rtc5 (the current RTC second value is assigned to

n0.val) rtc0=2016 (the RTC year is set to 2016) cov

rtc5,t0.txt,0 (the current RTC second value is converted to


RTC clock variable (supported only by hardware
23 rtc0-rtc6 t0.txt) Notes: 1. rtc0-rtc6 represent year, month, day, hour,
with RTC)
minute, second, and day of the week respectively. 2. rtc6

(day of the week) is read-only. It is automatically calculated

based on the current year, month, and day.

pio4=1 (IO4 is set to 1)n0.val=pio2 (io2's level status is

assigned to n0.val)cov pio3,t0.txt,0 (io3's

level status is transferred to t0.txt)Note: 1. Before using


Extended IO port (supported only by hardware with
24 pio0-pio7 the pio port, you must first use the cfgpio command to
extended IO)
configure the IO mode. 2. At power-on, all extended

IO modes are defaulted to pull-up input (internal pull-up

resistor is 50K).

pwm6=30 (set pwm6 duty cycle to 30) pwm7=90

(set pwm7 duty cycle to 90) Note: 1. The minimum duty

cycle is 0 and the maximum is 100. The default value

is 50. 2. pwm4-pwm7 corresponds to io4-io7 in the

Extended IO duty cycle (supported by extended IO. 3. Set

hardware with extended IO) K0 series only After the PWM duty cycle is set, you need to use the cfgpio
25 pwm4-pwm7
supports io4-io7 PWM X5 series only supports io6-io7 command to configure the IO mode to PWM output mode, and

PWM the corresponding IO will start to output PWM. After the PWM

mode is configured, the duty cycle can be modified at any time

during the PWM output process without reconfiguration. 4.

When powered on, the default mode of all extended IOs is

pull-up input (the internal pull-up resistor is 50K). >

pwmf=1024 (set the pwm frequency to

1024HZ)n0.val=pwmf (assign PWM frequency to

n0.val)cov pwmf,t0.txt (convert PWM frequency to

PWM output frequency ( supported only by t0.txt)Remarks: 1. The frequency unit is: HZ, the range
26 pwmf
hardware with extended IO) is minimum 1, maximum 65535HZ, and the

power-on default is 1000HZ. 2. All PWM outputs are

unified into one frequency and cannot be set individually.

Setting range: 0-150-6 for attenuation, the smaller the number,

eql-Bass attenuation (31HZ- the greater the attenuation; 8-15 for boost, the larger the

125HZ)eqm-midrange attenuation number, the greater the boost; 7 for balance, no

(250HZ-2000HZ)eqh-treble attenuation attenuation, no boost. Note: The underlying system operates


27 eqleqmeqh
(4000HZ-1600HZ) ( supported only by according to the settings of eq0-eq9. If you modify eql, eqm,

hardware with audio) not supported by the and eqh separately, it is equivalent to modifying eq0-eq2,

upper simulator eq3-eq6, eq7-eq9 separately; however, modifying eq0-eq9

will not affect the values of eql, eqm, and eqh.


Machine Translated by Google

sequence

name meaning Examples/Notes


Number

Independent frequency attenuation (with audio hardware The setting range is 0-150-6 for attenuation. The smaller the number, the attenuation

Only supported) The upper simulator does not support The greater the reduction, 8-15 is an improvement, the larger the number, the greater the improvement

eq0@31HZ eq1@62HZ Big 7 is balanced, no attenuation, no boost Notes:

eq2@125HZeq3@250HZ The underlying system operates according to the settings of eq0-eq9


28 eq0-eq9
eq4@500HZ If you modify eql, eqm, and eqh separately, they are equivalent

eq5@1000HZeq6@2000HZ Modify eq0-eq2, eq3-eq6, eq7-

eq7@4000HZ eq9; however, modifying eq0-eq9 will not affect

eq8@8000HZeq9@16000HZ To the values of eql,eqm,eqh.

volume=60 (set volume to 60) Note: Volume


System volume (minimum 0, maximum 100)
29 volume The setting range is 0-100, and each setting will automatically
(Supported only by hardware with audio)
Save, it will still be valid after power off and then restart.

audio0=2 (pause audio playback on channel 0

audio0=0 (stop audio playback of channel 0

play)audio1=1 (continue playing audio on channel 1)

Note: 1. The play command is used to configure and start the audio

Audio playback system variables audio0, audio1 are used for

Control channel status. 2. Only when the channel status is

When paused, it can be configured to continue playing.


Audio channel control 0-stop; 1-play
If the channel status is stopped, it cannot be configured as
30 audio0audio1 Play; 2- Pause (supported by hardware with audio)
To continue playing, you need to use the play command to configure
hold)
And start playing. 3. The audio playback function is global

It does not belong to a certain page, so the play instruction

After starting playback, even if you jump to another page, the audio

It will continue to play. If you want to leave the page

After stopping the playback, you can exit the page

Use the audio0/audio1 system variables to turn off

Close or pause the audio playback status of the specified channel.

ÿSerial port HMI color code tableÿ

Note: All codes are written in uppercase >

Code Decimal The color represented

RED 63488 red

BLUE 31 blue

GRAY 33840 grey

BLACK 0 black

WHITE 65535 White

GREEN 2016 green

BROWN 48192 orange color

YELLOW 65504 yellow


Machine Translated by Google

Serial port HMI device return data format

Table 1: Notification format for successful or failed serial command execution

1. The command execution success or failure data will be returned only when the system variable bkcmd is non-zero. After each power-on, bmcmd defaults to 2, which means

that only the result of the command execution error is returned.

2. The code written into the resource file when editing the upper software is not affected by bkcmd. If there is an error in the execution, error data will be returned, and no data will be

returned if it succeeds.

3: The end character of the data returned by the device is three bytes: "0XFF 0XFF 0XFF".

<<<<<<<<<<<<<< <<<<<<<

Return the first bit of data meaning Format

>>>>>>>>>> >>>>>>>

0X00 Invalid command 0X00 + end character (this data is returned when an invalid command is received from the user)

The command was


0X01 0X01+terminator (this data is returned when the instruction sent by the user is successfully executed)
successfully executed

Invalid 0X02+terminator (this data is returned when the command sent by the user contains an invalid control
0X02
control ID ID or invalid control name)

Invalid 0X03+end character (this data is returned when the instruction sent by the user contains an invalid
0X03
Page ID page ID or invalid page name)

Invalid 0X04+end character (this data is returned when the command sent by the user contains an invalid
0X04
image ID image ID)

Invalid font 0X05+terminator (this data is returned when the command sent by the user contains an invalid font ID)
0X05
ID

File operation
0x06 0X06+end character (returned when the file operation fails)
failed

CRC check 0X09+end character (this data is returned when the command with verification fails, instruction verification
0x09
failed description

0X11+terminator (the baud rate configuration command sent by the user contains invalid baud rate
Invalid baud
0X11 parameters) The baud rates supported by the device are: 2400 4800 9600 19200 38400
rate setting
57600 115200
Machine Translated by Google

Curve Controls
0X12+terminator (When the user uses the add command to add data to the curve control, this data is returned when the curve control
0X12 Invalid ID or
ID number or channel number is invalid)
channel number

0X1A+terminator This data is returned when the variable name received by the serial port is an invalid name. Note: Control properties
Invalid variable
0X1A are also called variables. For example, when you set the properties of a control, if you enter a property name that it does not have,
name
this data will also be returned.

0X1B+terminator For example, the txt attribute of the text control t0 should be written as t0.txt=”abc”. If you write t0.txt=abc, it will be
Invalid variable
0X1B wrong. For example, the val attribute of the progress bar j0 should be a numeric value, so it should be written as j0.val=50. If you
operation
write j0.val=”50” or j0.val=abc, it will also be wrong.

The assignment
0X1C 0X1C+Terminator This data is returned when the attribute assignment fails
operation failed

EEPROM
0X1D 0X1D+end character returns this data when EEPROM operation fails
Operation failed

Invalid number of
0X1E 0X1E+terminator This data is returned when the number of parameters in the command entered by the user is incorrect
parameters

IO operation
0X1F 0X1F+terminator This data is returned when the IO operation fails
failed

Error using
0X20 0X20+ This data is returned when the end character escape character is used incorrectly
escape characters

Variable name is
0X23 0X23+terminator The maximum length of the variable name is 29 characters. If it exceeds this value, this data will be returned.
too long

0X24+terminator This data will be returned when the serial port buffer is full (after the buffer overflows, the instructions in the buffer
Serial port buffer
0X24 queue will be executed to make room for the buffer to continue receiving instructions. Before this, the data received by the serial port
overflow
will be discarded)
Machine Translated by Google

Table 2: Other data return formats

1. The end mark of the data returned by the device is three bytes "0XFF 0XFF 0XFF". 2. The return of the following data is not affected by bkcmd.

Return
<<<<<<<
the first
meaning Format
bit of
>>>>>>>
data

0X65+page ID+button ID+touch event+end character (this data is returned when the user-created control is pressed or popped

Touch hot zone up, provided that you have checked the "Send key value" checkbox of the control) (definition of touch event: press event 0x01 pop-
0X65
event return up event 0X00) Example: 0X65 0X00 0X02 0X01 0XFF 0XFF 0XFF Meaning: Page 0 Button 2 pressed

The ID number of
0X66+page ID+end character (the device will return this data when it receives the "sendme" command) Example:
0X66 the current
0X66 0X02 0XFF 0XFF 0XFF Meaning: The current page ID is 2
page is returned

0X67+coordinate X high bit+coordinate X low bit+coordinate Y high bit+coordinate Y low bit+touch event status+terminator (when

Touch coordinate the system variable "sendxy" is 1, this data is returned when there is a touch event) (definition of touch event: press event 0x01 pop-
0X67
data returned up event 0X00) Example: 0X67 0X00 0X7A 0X00 0X1E 0X01

0XFF 0XFF 0XFF Meaning: Coordinate (122,30) Event: Press

0X68++Coordinate X high bit+Coordinate X low bit+Coordinate Y high bit+Coordinate Y low bit+Touch event status+Terminator

Sleep mode (When the device enters sleep mode, this data is returned when there is a touch event) (Definition of touch event: Press event
0X68
touch events 0x01 Pop-up event 0X00) Example: 0X68 0X00 0X7A 0X00 0X1E 0X01

0XFF 0XFF 0XFF Meaning: Coordinate (122,30) Event: Press

String variable 0X70+ variable content ASCII code + terminator When the variable obtained by the get command is a string type, this data is

0X70 data return returned. Example: 0X70 0X61 0X62 0X63 0XFF 0XFF 0XFF Meaning: Return string data: "abc"

0X71+variable binary data (4-byte little-endian mode, low-order first)+terminator When the variable obtained by the get instruction is a
Numeric variable
0X71 numerical value, this data is returned. Example: 0X71 0X66 0X00 0X00 0X00 0XFF 0XFF 0XFF Meaning: Return numerical data:
data return
102

The device
0x86+end character This data is returned only when the device automatically enters sleep mode. This data is not returned if the serial
0X86 automatically
port command sleep=1 is executed to enter sleep mode.
enters sleep mode

Automatic device 0x87+end character This data is returned only when the device wakes up automatically. If the sleep state is awakened by executing
0X87
wake-up the serial port command sleep=0, this data will not be returned.

System startup
0X88 0x88+end character The device sends this data after power-on initialization is successful
successful

Start SD
0X89 0x89+end character After the device detects the SD card after power-on, it will send this data and then enter the upgrade interface
card upgrade

Transparent data
0XFD 0xFD+end character After the transparent transmission of data ends and the data processing is completed, this data is sent
transmission completed

Data transmission After receiving the data transparent transmission command, the device enters the transparent transmission data initialization. After the initialization is completed,
0XFE
ready this data is sent, indicating that it has entered the data transparent transmission mode and can start data transparent transmission.
Machine Translated by Google

Name Group Usage Instructions

In most cases, we operate control properties like this (this is also the recommended way to operate controls):

t0.txt="123" //Assign "123" to the txt attribute of the t0 control n0.val=15 //

Assign 15 to the val attribute of the n0 control z0.val=185 //Assign 185

to the val attribute of the z0 control

What if we don't know the name of the control but only know the control ID? This requires name groups to implement

ÿControl name group format: b[control ID].properties

example:

b[5].txt="123" //The txt attribute of the control with ID 5 on the current page is assigned to "123"

b[n0.val].txt="123" //The txt attribute of the control with ID n0.val on the current page is assigned to "123"

Note: You must ensure that this control on the current page has the txt attribute, otherwise the assignment will fail.

ÿPage name group format: p[page ID].b[control].properties

example:

p[2].b[4].txt="456" //In the page with ID 2, the txt attribute of the control with ID 4 is assigned the value "456"

p[n0.val].b[n1.val].txt="456" //In the page with ID n0.val, the txt attribute of the control with ID n1.val is assigned the value "456"

Note: You must ensure that this control in this page has the txt attribute, otherwise the assignment will fail.

ÿ Use the for statement to batch change the control properties (load the continuous values starting from eeprom address 100 to the numeric controls n0~n9 (ID: 5~14)):

//Set eeprom reading position sys1=100

for(sys0=5;sys0<=14;sys0++) //for loop reads eeprom and assigns value to numeric control {

repo b[sys0].val,sys1 //Read the eeprom data at the specified location sys1+=4 }

//The eeprom read address plus 4, because a numerical type occupies 4 bytes of space.

Note: You must ensure that controls with IDs from 5 to 14 have the val attribute, otherwise the assignment will fail.

•The ID numbers of all controls are automatically assigned by the software and cannot be set manually. When the user edits the UI interface, the software will assign IDs consecutively for controls

placed in sequence.

•Using the "Top" and "Bottom" functions on the shortcut bar will change the control ID, because the front and back relationships of the layers are related to the control ID. The one with the smallest ID

is at the bottom layer (so the page ID is 0), and the one with the largest ID is at the top layer. Each control has its own layer, and the front and back relationships are all distinguished by ID.
Machine Translated by Google

Detailed explanation of HMI advanced applications and special instructions

This document mainly describes some advanced applications and implements some special functions. Most projects do not use these functions. If your project does not use them, you can ignore this

document.

ÿChapter Indexÿ

1. Detailed explanation of the application of active analysis mode in serial port data analysis mode

2. Detailed explanation of HMI download protocol

3. Add CRC check to serial port instructions

4. Using CRC to check data in the program

5. Serial port transfers images to memory or SD card during operation

1. Detailed explanation of the application of active analysis mode in serial port data analysis mode

The screen is in passive parsing mode by default when it is powered on. All serial port commands must be operated on the screen in the format of the instruction

set. If you need to customize the protocol and send serial port data to the screen in a format you customize instead of the instruction set format, you need to

configure the screen in active parsing mode. To use this function, please

make sure you have the following two basics: 1. Understand what HEX, String, and ASCII are, their

relationship, and how to convert them. 2. Understand the differences between single-byte values, double-byte values, and four-byte values, how they are stored in

memory, and understand what little-endian mode and big-endian mode are. Understand what low-order bits are in the front. If you understand the above two points,

please continue reading. Otherwise, it is strongly recommended not to continue reading, because most projects do not use this function. Use the default passive

parsing mode. There is no need to configure it to the following active parsing mode.

This article covers the following contents:

1. Serial port data analysis mode system variable: recmod 2. Serial port

buffer data size system variable: usize 3. Serial port buffer data group:

u[index] 4. Serial port buffer data copy instruction: ucopy 5.

Serial port data analysis mode exit password

1. Serial port data parsing mode system variable recmod (0 is passive parsing mode, 1** is active parsing mode**)

When the screen is powered on, recmod is 0, that is, passive analysis mode. In this mode, the external device sends serial port commands to the screen for execution according to the command

format of the standard command set; if you set recmod to 1 (you can write recmod=1 in the initialization event of the power-on default page), the screen will enter the active analysis mode, and then

all serial port commands will not be executed (note: the serial port commands will not be executed, and the firmware commands written in the event when the upper software edits the interface will

not be affected and will still be executed normally), and all serial port data are stored in the serial port buffer, waiting for you to actively read. After reading the data each time, use the udelete command

to delete the number of bytes that have been read in the buffer, otherwise the buffer will overflow and new data cannot be received.

Note: When the screen is set to active analysis mode and the screen is connected to the host computer software simulator, the screen will be forced to exit the active analysis mode. At this time, the screen

needs to be powered on again before the simulator can be normally connected to debug the screen.
Machine Translated by Google

2. Serial port buffer data size system variable usize (can only be read, not set)

By reading this variable, you can know how much data is cached in the current serial port buffer.

3.Serial port buffer data group

The serial port buffer data group is written as u[index] (index is the sequence number)

Example 1: Get a 1-byte value from position 0 in the buffer and assign it to the digital control n0. The writing is as follows:

n0.val=u[0]

Example 2: Get a 2-byte value (little-endian mode, low-order first) from position 0 in the buffer and assign it to the digital control n0. The writing is as follows:

n0.val=u[1]
n0.val<<=8
n0.val+=u[0]

Example 3: Get a 4-byte value (little-endian mode, low-order first) from the buffer starting at position 0 and assign it to the digital control n0. The writing is as follows:

n0.val=u[3]
n0.val<<=8
n0.val+=u[2]
n0.val<<=8
n0.val+=u[1]
n0.val<<=8
n0.val+=u[0]

Is it true that the only way to assign the contents of a buffer to a 4-byte integer variable is to assign the values of the bytes four times and then shift them three times? Of course

not! There is a more convenient way, please read on!

4. Serial port buffer data copy instruction ucopy

Format: ucopy,att, srcstar, lenth, decstar Description:


Copy the data in the serial port buffer to the variable (valid in recmod=1 mode) att: target
variable name srcstar:

serial port buffer data start position

lenth: copy length

decstar: target variable data start position

This instruction can continuously copy a specified amount of data from the specified location of the serial port buffer to the target variable (the target variable can be a string

variable or a numeric variable).


Machine Translated by Google

Example 1: Get a 4-byte value (little-endian mode, low-order first) from position 0 in the buffer and assign it to the digital control n0. The writing is as follows:

ucopy n0.val,0,4,0 udelete 4 //

Delete the first 4 bytes in the buffer. If there is other data behind, it will be automatically pushed up.

Tips: Each numeric variable is allocated 4 bytes of memory. If you use ucopy to obtain a value less than 4 bytes from the buffer, you must pay attention to the

processing of the remaining byte data to avoid data anomalies. Please refer to the following example for the operation method:

Example 2: Get a 2-byte value (little-endian mode, low-order bits first) from position 0 in the buffer and assign it to the lower 16 bits of the digital control n0.val. The

writing is as follows:

n0.val=0

ucopy n0.val,0,2,0 //If you want to assign a value to the upper 16 bits, write ucopy n0.val,0,2,2 udelete 2 //Delete

the first 2 bytes in the buffer. If there is other data behind, it will be automatically pushed up

Explanation: n0.val is first assigned a value of 0 to ensure that all 4 bytes of n0.val are set to 0, and then 2 bytes are copied from the buffer. Otherwise, because you

only copy 2 bytes, the remaining 2 bytes of data in n0.val will still be there, and the final value of n0.val will not be what you want.

Example 3: Get a 10-byte string from position 0 in the buffer and assign it to the text control t0. The writing is as follows:

if(usize>=10) { ucopy // Make sure the buffer size is large enough for 10

t0.txt,0,10,0 udelete 10

//Delete the first 10 bytes in the buffer. If there is other data behind, it will be automatically pushed up

Important note: The code_c command will clear the buffer data, which may cause the data that has not been read to be deleted prematurely. Therefore, in active

parsing mode, it is recommended to use the udelete command to delete the content that has been read instead of using the code_c command.

All the statements and instructions used in the above cases are firmware instructions written into the event in the upper editing interface. Once the serial port is

configured in active parsing mode, serial port instructions can no longer be executed. Therefore, the serial port data must be read by firmware instructions, not by

serial port instructions (otherwise it would be contradictory).

5. Exit active parsing mode

The conventional method to exit the active parsing mode is to write the firmware instruction recmod=0 in the event. If you want to exit through serial port data,

sending recmod=0 through the serial port is definitely useless. You can exit the active parsing mode by sending a string of exit passwords. The exit password is a

string of 24 bytes + 3 bytes of terminator.

24-byte string:

DRAKJHSUYDGBNCJHGJKSHBDN (string data, must be uppercase)

3-byte terminator (Hex data): 0xff 0xff 0xff

Total 27 bytes
Machine Translated by Google

2. Detailed explanation of HMI download protocol

The HMI download protocol described in this article is only suitable for users who want to make their own download programs or want the microcontroller to control the HMI to download

resource files . It belongs to the category of advanced applications, not the category of HMI interface design, so users with a certain foundation are required to operate it. Shenzhen Taojingchi

Electronics Co., Ltd. only makes a public statement on this protocol and does not provide any technical support related to the download protocol. If you are not familiar with serial port operations,

it is recommended to ignore this statement and directly use the USART HMI software to download without any understanding of this protocol.

Tips: The official has developed a dedicated download tool (TFTFileDownload) in accordance with this agreement, and the source code is open. You are welcome to download

and use it: Click here to download

ÿDownload step 1: Online operationÿ

This step is mainly used to search which serial port the HMI device is on and the current baud rate of the device. If these two conditions are known, you can skip this step and directly fix the serial port

number and the current baud rate of the device in your program and jump directly to step 2 to start downloading.

•Search method:

Send a connection command to each serial port of the computer at different baud rates: connect+terminator. After receiving the connection

command, the device will return the connection data. If the correct connection data is received, it means that the device is successfully connected. At this point, the serial port number of the current

device and the currently used baud rate are obtained.

•Online command sending instructions:

Because the instructions are sent in a loop, when the screen receives data at the correct baud rate, there will definitely be some erroneous data at the last wrong baud rate at the front of the data, so

the first instruction will definitely be regarded as an erroneous instruction. Therefore, two instructions need to be sent each time. The first one is a 4-byte HEX empty instruction (00 ff ff ff), and the

second one is the connect+terminator. Delay description: After each attempt to connect, the shortest time to wait for data to return is (unit: ms):

(1000000/attempted baud rate) + 30. If you try to connect at 9600 baud rate, the shortest time to wait for return is: 1000000/9600+30=134ms. The same applies to other baud rates.

Data explanation:

Taking the TJC4024T032_011R device as an example, the device returns the following 8 groups of data (each group of data is separated

by a comma): comok 1,101,TJC4024T032_011R,52,61488,D264B8204F0E1828,16777216 comok: handshake response 1: indicates with touch

(0 means without touch) 101:

device internal reserved data

TJC4024T032_011R: Device model 52: Device firmware

version 61488: Internal code of

the device main control chip

D264B8204F0E1828: Device unique serial number 16777216: Device

FLASH size (unit: bytes)

ÿDownload step 2: Start downloadingÿ


Machine Translated by Google

Now we know which serial port the device is on and its current baud rate, and we can send the download command.

ÿStep 1: Send command whmi-wri filesize,baud,res0

filesize: size of tft file (unit: byte) baud: baud rate

used for forced download res0: reserved

data, any ASCII character can be used. If the size of the

tft file to be downloaded is 10000 bytes, it needs to be downloaded at 115200 baud rate, then send the command: whmi-wri

10000,115200,0 After sending this

command, you need to change the baud rate of the computer to the forced baud rate just set (if the current baud rate is inconsistent with the forced

download baud rate)

ÿStep 2: Send binary data of tft file

After receiving the whmi-wri command, the device will return a 0x05 data in about 250ms (only one byte, without the three 0XFF terminators, and the baud rate is the

forced download baud rate just set). After receiving this data, you can start sending the binary data of the tft file. The sending format is 4096 bytes per package, and

the number of remaining bytes in the last package is the same. After each package is sent, you need to wait for the screen to return a response signal. The response

signal is still a single byte 0x05.

3. Serial port commands add CRC check (supported by 0.56 and above host computer versions)>

Under normal circumstances, the command can be sent directly without verification. If your project has strict requirements on command transmission and verification must be enabled, please follow the instructions

below to send the command.

Please note: The CRC instruction is only supported from version 0.56 onwards, and earlier versions do not support it.

No configuration is required for verification or non-verification. You only need to modify the command. You can run the previous command with verification and the next command without

verification. The differences between the two commands are as follows:

1. Change the end character

The terminator of a normal instruction is 0xff 0xff 0xff, and the terminator of an instruction with checksum is 0xfe 0xfe 0xfe.

2.CRC16 checksum algorithm

The instruction CRC16 check algorithm uses the MODBUS CRC16 check algorithm, and the calculation function is as follows:

The data that needs to be verified are all instruction data. If it is an instruction with an address, it starts from the address. If it is an instruction without an address, it starts from the first byte of

the instruction, and the end character is not included.

static U8 InvertUint8(U8 data) {

int i;

U8 newtemp8 = 0; for (i =

0; i < 8; i++) {

if ( (data & (1 << i) ) != 0) newtemp8 |= (U8)(1 << (7 - i));


Machine Translated by Google

} return newtemp8;

} static U16 InvertUint16(U16 data) {

int i;
U16 newtemp16 = 0; for
(i = 0; i < 16; i++) {

if ( (data & (1 << i) ) != 0) newtemp16 |= (U16)(1 << (15 - i));

} return newtemp16;
}

U16 CRC16_MODBUS(U8* data, int lenth) {

int i;
U16 wCRCin = 0xFFFF;
U16 wCPoly = 0x8005;
U16 wChar = 0;
while (lenth > 0) {

wChar = *data;
data++;
wChar = InvertUint8( (U8)wChar);
wCRCin ^= (U16)(wChar << 8); for (i
= 0; i < 8; i++) {

if ((wCRCin & 0x8000) != 0) {

wCRCin = (U16)( (wCRCin << 1) ^ wCPoly); }else

{ wCRCin = (U16)(wCRCin << 1); }

} length=length-1;

} wCRCin = InvertUint16(wCRCin);
return (wCRCin);
}

3. CRC16 check code writing method

After the instruction and before the terminator, add a 2-byte CRC16 checksum (HEX) + a 1-byte constant: 0x01 (HEX), which is equivalent to inserting 3 bytes

between the instruction and the terminator. The CRC checksum is stored in little-endian mode, with the low bit first.

If the screen receives a command with verification and finds that the verification fails, it will return an error: 0x09 0xff 0xff 0xff
Machine Translated by Google

4. Use CRC check data in the program (supported by 1.60.1 and above host computer versions)

1. The following code will enable the screen to send 2 sets of constant data to the external device, and add the Modbus CRC16 check result at the end:

crcrest 1,0xffff Reset CRC

crcputs "hex date is:",0 CRC check string: hex date is:

crcputh 03 25 prints CRC check hex:0x03,0x25

"hex date is:",0 The serial port sends a string: hex date is:

printh 03 25 Serial port sends hex: 0x03, 0x25

prints crcval,2 Serial port sends verification results

2. The following code will enable the screen to send 2 sets of variable data to the external device, and add the Modbus CRC16 check result at the end:

crcrest 1,0xffff crcputs Reset CRC

t0.txt,0 crcputs n0.val,0 CRC check string variable t0.txt

prints t0.txt,0 prints CRC check value variable n0.val

n0.val,4 prints The serial port sends the string variable t0.txt

crcval,2 The serial port sends the numerical variable n0.val

Serial port sends verification results

3. The following code will implement CRC check on the data in the serial port buffer in active parsing mode, and display the success or failure result to t0.txt

if(usize>=24)

crcrest 1,0xffff Reset CRC

crcputu 0,22 sys0=0 Verify the first 22 bytes of the serial port buffer

sys0 is a 4-byte integer data, and the CRC result is only 2 bytes, so clear the extra bytes first

ucopy sys0,22,2,0 Assign the CRC result received in the receive buffer to sys0

if(sys0==crcval) verification passed

t0.txt="Verification passed"

}else

t0.txt="Verification failed"

delete 24 Delete the 24 bytes that have been processed

5. Transferring images from the serial port to the memory or SD card during operation (supported by host computer versions 0.56 and above)

If you want to transfer image files to memory, please configure the memory file system space size in the project settings. The default is 0, which means there is no space.

To store memory files.

If you are transferring image files to an SD card, please make sure that the SD card disk format is FAT32, and the maximum supported card capacity is 32G.

Tips: The official has developed a dedicated serial port transparent file transmission tool (SerialFileUp) according to this protocol, and the source code is open. Welcome to

Download: Click here to download

1. How to use the image files in memory


Machine Translated by Google

Use the "External Picture" control and set the path property to the file path, such as: ram/0.jpg

2. How to use the image files in the SD card

Use the "External Picture" control and set the path property to the file path, such as: sd0/0.jpg

3. What types of image files are supported?

Jpg format: If you use jpg format images, make sure that the image is encoded as baseline DCT, otherwise it will not be displayed. If the screen direction is set to 0 degrees, you can

directly use the original jpg image. If the screen direction is set to 90 degrees, you need to rotate the image 90 degrees clockwise before using it on the screen, otherwise the displayed

image will be in the wrong direction. Other directions are 180 degrees, 270 degrees, and so on. You need to rotate the image clockwise in advance according to the screen direction.

xi format: This format is a special image format for HMI, supports transparent background, and is recommended. To obtain images in xi format, you can use the image conversion tool

in the software tool menu: PictureBox conversion

Currently, only the above two formats of image files are supported.

4.Serial port transmission protocol

Step 1: Send serial port file transfer command: twfile filepath, filesize

filepath: file storage path such as: ram/a.jpg or sd0/a.jpg filesize: actual file size If you

want to transfer a file to the memory,

the name is a.jpg, the size is 3282, the command is: twfile "ram/a.jpg", 3282 If you want to transfer a file to the SD card, the name is a.jpg, the size is 3282,

the command is: twfile "sd0/a.jpg", 3282 After receiving this command, the screen will immediately create a file of the specified size on the target path. If the

creation is successful, it will return: 0xfe + terminator, indicating that it has entered the transparent transmission state and can start to sub-packet transparent transmission data. If the file creation

fails, it will return: 0x06 + terminator, and continue to work in the command receiving state.

Step 2: Sub-packet transparent transmission of file data

After receiving 0xfe+terminator, you can start to sub-packet transparent transmission of data; a complete data packet consists of 2 parts: header + data

Packet header: 3a a1 bb 44 7f ff fe + check type (1-byte integer data) + packet ID (2-byte integer data) + data size (2-byte integer data), a total of 12 bytes

Check type: 0x00 is no check, 0x01 is CRC16 (CRC16 check algorithm of MODBUS, there is a calculation function reference in the instruction check section), 0x0A is standard CRC32 Package

ID: The first package

ID of the file transparent transmission is 0, and the ID increases by 1 for each successful transparent

transmission. Data size: The data size can be specified by the user, with a minimum of 1 byte and a maximum of 4096 bytes (this data size does not include the 12-byte packet header, but includes

the CRC check code)

Data: file data + CRC checksum data (little endian mode, low bit first). If it is a non-checked packet, there is no CRC checksum. If it is CRC16, it is a 2-byte checksum. If it is CRC32, it

is a 4-byte checksum. Remember to record the checksum data in the data size parameter of the packet header.

The CRC16 check algorithm is MODBUS CRC16, click here to view the reference function code) The CRC32 check algorithm is standard CRC32.

After the screen receives a complete packet of data, if the processing is successful, it will return 0x05 (single byte, no end mark), and then the next packet can be sent.
Machine Translated by Google

If the packet ID is not accumulated according to the rules or the packet data is wrong, the screen will return the error of the packet processing failure: 0x04 (single byte, no end character).

After all packets are sent, the screen will return 0xfd + terminator, and automatically exit the transparent transmission mode and switch to the command mode.

If the transparent transmission of this packet fails (no screen response is received for more than 500ms or the screen returns an error message indicating that the verification of this packet has failed), resend the data of this

packet. The packet ID does not need to be increased by 1 when resending the data of this packet.

If you regret sending a data packet halfway through, just pause for more than 20ms and resend the data packet.

If you want to stop transparent transmission in the middle of the file transmission, please send a data packet with a packet ID of 65535, no checksum, and a data size of 0, that is: 3a a1 bb 44 7f ff fe 00

ff ff 00 00. After receiving such a packet data, the screen will immediately force the transparent transmission to end and return the data indicating the end of the transparent transmission: 0xfd + end

character.

If your file data contains exit packet data, don't worry, because if there is no pause of more than 20ms before the data, the screen will only store it as data and will not process it as an end packet.

Communication protocol between device and serial screen

ÿChapter Indexÿ

1. Passive parsing mode of serial port data parsing mode

2. Active parsing mode of serial port data parsing mode

3. Serial port screen sends data

1. Passive parsing mode of serial port data parsing mode

By default, the screen receiving device sends data in the complete format of a string instruction plus three hexadecimal ffs. If the screen receives an incomplete or

Error instructions will return data. For example, ÿ1a ff ff ff

ÿ1c ff ff ff, etc.; you can use the ckcmd command to turn on and off the return data. (Under normal circumstances, it is recommended to find and solve the cause of the screen error first, and then turn

off the return data with the command)

1.1 Take the text control display as an example

How to control the screen with a single chip microcomputer (text control)

1. Create a text control in the host computer project, assuming it is t0, and download the program to the serial screen. 2. The serial port of the

serial screen is connected to the serial port of the microcontroller. The baud rate of the two should be the same. The MCU RX is connected to the serial screen TX, and the MCU TX is

connected to the serial screen RX. 3. Send command: The microcontroller serial port sends t0.txt="ÿÿÿ" through string mode

4. Send end character: The microcontroller sends 0xff 0xff 0xff through HEX mode 5. At this time, the text in

the t0 control on the screen becomes "ÿÿÿ"

1.2 Take digital control display as an example

How to control the screen with a single chip microcomputer (digital control)
Machine Translated by Google

1. Create a new digital control in the host computer project, assuming it is n0, and download the program to the serial port screen. 2. Connect the serial port of the serial

port screen to the serial port of the microcontroller. The baud rate of the two should be the same. The microcontroller RX is connected to the serial port screen TX, and the microcontroller TX is connected to the serial port screen.

RX.

3. Send command: The MCU serial port sends n0.val=666 in string mode 4. Send end character: The MCU

sends 0xff 0xff 0xff in HEX mode

5. At this time, the text in the n0 control on the screen changes to "666"

1.3 MCU sends variables to the screen

In general, the MCU rarely sends a constant to the screen. In most cases, the MCU assigns a variable to the screen. The following code is in C language.

printf("n0.val=666"); Send command printf("\xff\xff\xff");

Send terminator printf("n0.val=666\xff\xff\xff");

printf("n0.val=%d\xff\xff\xff",MyData); Send command and

terminator at one time printf("t0.txt="%d"\xff\xff\xff",MyTxt); Send command and terminator at one time

Note: Here, \xff is used to send hexadecimal. If you don’t understand how to use “\”, search “C language escape character” on Baidu.

2. Active parsing mode of serial port data parsing mode

By default, the screen receiving device sends data in the complete format of a string instruction plus three hexadecimal ffs. If the screen is set to

recmod=1, the screen will enter active parsing mode, that is, custom communication protocol.

For detailed usage information, click here to view.

Note: 1. In active parsing mode, only the timer control can parse data, and the fastest parsing time of the timer is 50ms.

2. In active parsing mode, all serial port commands will not be executed, but will be stored in the serial port buffer, waiting for you to actively read them.

3. Under normal circumstances, it is recommended to use the default communication protocol of the screen. If the device does not follow the screen communication protocol format,

Active parsing mode.

3. Serial port screen sends data

The serial port screen sends data using the get prints printh command.

Note: 1. In the same event, if you write the send command in separate lines, they are actually sent in the same line.

2. To send variables, you can only use the prints and get commands. To send hexadecimal data, you can only use the printh command.

3. The screen can use the printh command and the prints command to implement any communication protocol.

You might also like