# 9.2 Script usage

**Introduction**

Script can make project more convenient and flexible. Script is useful in realizing complex HMI function. If the script is used improperly, it may affect the efficiency of entire project. So pay attention to the follow issues:

1\) Do not use too much script loops, if the script loops that execute too many times; it might influence the efficiency of HMI.

2\) In the cycle scripts, avoid using external register, due to the relatively slow serial communication, frequent access to external registers may cause the execution of scripts severely reduced, even influence the screen respond efficiently. There is fine to use internal register.

3\) The maximum script length is 512 rows.

This section describes how to edit scripts and use some of the accompanying tools and features of the script editor.

### 9.2.1 Script Access to Device

Software script supports an efficiency way to access the device address by using symbol @.

| **Writing**                                                      | **Meaning**                                                                                                                                                                                                                                                                                     | **Examples**                                                                       |
| ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| @B\_;@b\_;                                                       | Access designated bit address                                                                                                                                                                                                                                                                   | <p>@B_I0.0: access bit address I0.0</p><p>@b_HDX0.0: access bit address HDX0.0</p> |
| @W\_;@w\_;                                                       | <p>Access designated word address</p><p>HMI connect more than automatic control devices, "#"stands for choosing number before the symbol,":" stands for accessing the station number before symbol.</p><p>Access the first protocol without "#", access default station number1 without":".</p> | <p>@W_IW0: access word address IW0</p><p>@b_HDW0:access word address HDW0</p>      |
| @B\_(the number of protocol connection)#(station number):address | <p>@B_2#2:I0.0:access the bit address I0.0, with the connection number 2 and station number 2;</p><p>@B_I0.0:access to bit address I0.0;</p>                                                                                                                                                    |                                                                                    |

The script can access with the device though: write and read.

**For example**

_If @B\_HDX0.0 = 1 then 'read the value from address HDX0.0._

_@B\_HDX0.0 = 0 'write 0 to address HDX0.0_

_Else_

_@B\_HDX0.0 = 1 'write 1 to address HDX0.0_

_Endif_

_@W\_QW0 = @W\_QW0 + 1 'read data from address QW0, add 1 to this value then write to address QW0._

### 9.2.2 Grammar Checking

**Operating procedures**

1\) Select ![](https://3950998874-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2Fpi-series-user-manual%2F-LvAGxupcpRjtZXZkX5I%2F-LvAIEh7v_ee0lFXRUgx%2F16.png?generation=1575368852961927\&alt=media) from script tool bar;

2\) System does not prompt grammar error if grammar is correct, or system will list all errors;

3\) Check error information, and modify errors;

**Error information**

1\) Identifier \*\*\* contains invalid characters

2\) Attempt to redeclare sub \*\*\*

3\) Attempt to redeclare function \*\*\*

4\) Attempt to use reserved word \*\*\* as identifier

5\) Attempt to use type \*\*\* as identifier

6\) Unexpected ')' while parsing arguments for function \*\*\*

7\) Could not parse expression (one of the arguments of function \*\*\*)

8\) Could not parse arguments of \*\*\*

9\) Too many arguments for function \*\*\*

10\) Not enough arguments for function \*\*\*

11\) '(' expected after sub name \*\*\*

12\) Unexpected '(' while parsing arguments for sub \*\*\*

13\) Could not parse expression (one of the arguments of sub \*\*\*)

14\) Could not parse arguments of \*\*\*

15\) Too many arguments for sub/function \*\*\*

16\) Not enough arguments for sub/function \*\*\*

17\) Could not parse expression

18\) '(' expected after function name \*\*\*

19\) Unexpected use of sub \*\*\* as a part of expression

20\) Illegal statements preceding subs/functions declaration

21\) Unexpected end of file while looking for 'endsub'

22\) End of line expected after 'else'.

23\) End of line expected after 'endif'.

24\) End of line expected after 'next'.

25\) End of line expected after 'wend'.

26\) 'while', 'until' or end of line expected afte r'do'.

27\) Could not parse expression after 'while'

28\) Could not parse expression after 'until'

29\) 'do' without 'loop'

30\) Sub \*\*\* contains invalid character'@'

31\) Sub \*\*\* already declared

32\) Function \*\*\* already declared

33\) Sub name expected after 'sub'

34\) Function name expected afte r'function'

35\) Variable name expected

36\) Argument \*\*\* contains invalid character '@'

37\) 'integer', 'floating' or 'string' expected

38\) ''',' or ')' expected

39\) 'endsub' without 'sub'

40\) 'end function' without 'function'

41\) End of line expected after 'beep'

42\) 'dim' unexpected here

43\) Variable name expected after 'dim'

44\) 'as' expected after variable name

45\) 'integer' 'floating' or 'string' expected after 'as'

46\) ',' or end of line expected after type in dim statement

47\) Could not parse expression after 'while'

48\) End of line expected after' while' condition

49\) 'while' without 'wend'

50\) End of line expected after 'wend'

51\) 'wend' without 'while'

52\) Variable name expected after' for'

53\) '=' expected after variable name

54\) Could not parse expression after 'for'

55\) 'to' expected

56\) Could not parse expression after 'to'

57\) Could not parse expression after 'step'

58\) End of line expected

59\) 'for' without 'next'

60\) End of line expected after 'next'

61\) 'Next' without 'for'

62\) Could not parse expression after'if'

63\) 'then' expected

64\) Unexpected end of file while looking for 'endif'

65\) Unexpected end of file while looking for 'else' or 'endif'

66\) 'else' without ‘if'

67\) 'end if' without 'if'

68\) Label name expected after 'goto'

69\) Unexpected end of line while looking for ')' in function call

70\) ',' expected

71\) Missing ')'

72\) Unexpected end of line in expression

73\) Unexpected end of file in expression

##
