Scripts are divided into two parts: Declaration Part and Program Part. The declaration part is for the declaration of internal variables and input parameters. The program part includes all program statements except for the variable declarations.
Comments can be entered anywhere in the program. Strings starting with ‘//’ are treated as comments until the end of the line.
(1) Declaration Part
Item | Description |
Variable Declaration | Declares the internal variables in the following format: VAR variable_name [, variable_name];. The initial value of the declared variables is 0. To declare more than one variable, use a comma “ , ” between them. You can use several VAR keywords before the program part starts. The variable name cannot be duplicated with the tag names (Group, Digital, Analog, String). The duplicated name may cause compile errors or incorrect operation. |
Input Parameter Declaration | Declares the input parameters in the following format: PARAM 1st parameter [, 2nd parameter …]; . The input parameter is required when a program is called by another program or a command. The declaration order must be identical to the order of input parameters. The parameter will be initialized with the values assigned by the caller. To declare more than one parameter, use a comma “ , ” between them. You can use several PARAM keywords before the program part starts. |
Example | Program Name: MyPgm VAR a, b; VAR c; PARAM p1, p2; PARAM p3;
The program MyPgm can be called by the external caller as shown below. MyPgm(1,2,3); In the parameter p1, p2, p3, assigned values (1, 2, 3) will be stored. The variables a, b, c, will be initialized as 0. |
(2) Program part
In the program part, all program statements except the declaration (variables and parameters) can be used. The example of the most basic statement is the function call, calculation and storing the result.
The following program example is composed of basic statements.
Tag_a = Tag_a + 1;
Tag_b = MyPgm(Tag_a, 2, 3);
Each statement must end with a semicolon “ ; ”. Each function returns a single result to the caller. The program mentioned above returns the result to “Tag_b”.
(3) Constants
When you use constants in the program, you can use the notations as shown below.
Item | Description |
Octal Constants | Only used from 0 to 7. The octal constant must start with 0. (E.g. 01277) |
Decimal Constants | General notation is used. (E.g. 153, 3.14, 2.45E-12) |
Hexadecimal Constants | It must start with ‘0x’. Use alphabet or number characters between ‘0’ and ‘F’. (E.g. 0xFFFF) |
String Constants | Enter the string between the two double-quotation marks (“ ”). (E.g. “String Variable1”) |
You can also utilize the predefined constants as shown below.
Constant Name | Value | Usage |
_PI_ | 3.141592… (Value of π) | |
_LOCAL_ | 0 | Local Flash Memory |
_SDMEM_ | 1 | SD/MMC Memory |
_USBMEM_ | 2 | USB Memory |
_COM232_ | 0 | Uses COM1 port as RS232C mode. |
_COM422_ | 1 | Uses COM1 port as RS422 mode. |
_COM485_ | 2 | Uses COM1 port as RS485 mode. |
_COMAUX_ | 3 | Uses COM2 port as RS232C mode only. |
_BPS300_ |
| 300 bps |
_BPS600_ |
| 600bps |
_BPS1200_ |
| 1200bps |
_BPS2400_ |
| 2400bps |
_BPS4800_ |
| 4800bps |
_BPS9600_ |
| 9600bps |
_BPS19200_ |
| 19200bps |
_BPS38400_ |
| 38400bps |
_BPS56000_ |
| 56000bps |
_BPS57600_ |
| 57600bps |
_BPS115200_ |
| 115200bps |
_BPS128000_ |
| 128000bps |
_BPS256000_ |
| 256000bps |
_PARITY_NONE_ |
| No parity |
_PARITY_EVEN_ |
| Even parity |
_PARITY_ODD_ |
| Odd parity |
_PARITY_MARK_ |
| Mark parity |
_PARITY_SPACE_ |
| Space parity |
_STOPBIT_ONE_ |
| 1 stop bit |
_STOPBIT_TWO_ |
| 2 stop bits |
_STOPBIT_ONE5_ |
| 1.5 stop bit |
_ALMPRT_ALL_ |
| Prints all items of alarm data. |
_ALMPRT_TIME_ |
| Prints the time of alarm data. |
_ALMPRT_ADDR_ |
| Prints the address of the alarm point. |
_ALMPRT_VALUE_ |
| Prints the value of the alarm. |
_ALMPRT_TYPE_ |
| Prints the alarm type. |
_ALMPRT_DESC_ |
| Prints the alarm description. |
_UINT_ |
| Unsinged integer |
_INT_ |
| Singed integer |
_FLOAT_ |
| Floating point value |
_HEX_ |
| Hexa-decimal number |
_EXP_ |
| Real number with exponent |