Introduction

The Exemys script programming language runs in a loop. This means that it will run until the last program line and start from the beginning again.

Loop functions are not avaible. So, the program flow can't be stopped or looped. It runs like a ladder program in a PLC, but its syntaxis is similar to C language.

We suggest not only to read this manual but to read the examples to better understand how to write a script. You can download the examples from here www.exemys.com/GRDscriptsExamples

Script using the SMS feature will only work on the GRD.

Script Versions 1, 2 and 3

There are 3 versions of the script. Version 2 differs from version 1 in that it allows twice as many variables, since they can be written in either lowercase or uppercase. In version 1, variables can only be written in lowercase. Version 3 saves between 20% and 30% of the space used by the program in the device's memory, thus allowing longer programs to be loaded. You can notice the difference by pressing the verify button.

The GRD-XF-2G and cLAN V1.x devices work with version 1.

The GRD-XF-3G and cLAN V2.x devices work with version 2 (up to version 10.x) and version 3 starting from version 11.0 onward.

The GRD-MQ and cLAN MQ devices work with version 2 (up to version 10.x) and version 3 starting from version 11.0 onward.

Version 3 is fully compatible with version 2 and switches automatically to version 3 on compatible devices (V11.0 or higher).

Programs written in version 3 are identical to those in version 2. They simply take up less space in the device's memoryThere are two version of the script. Version 2 doubles the variables quantity, it allows upper and lower case variables. Version 1 only allows lower case variables.

Variables

There are two variable types. Numeric variables and String variables.

It's not necesary to define variables.

In Version 1 there are 21 numeric variables, from “a” to “u”. And there are 5 string variables from “v” to “z”.

In Version 2 there are 42 numeric variables, from “a” to “u” and from “A” to “U”. And there are 10 string variables from “v” to “z” and from “V” to “Z”.

String variable's maximum length is 100 characters.

Numeric variables are signed integer type, and their value range goes from −2,147,483,648 to 2,147,483,647. If a math operation gives a result with decimals, it will be truncated to the integer part.

Initial value es 0 for numeric variables and empty for strings.

Numeric variables can be mapped into GRD's I/O channels to send reports or create historical records based on its values.

Assigning a value to a variable:

                        a = 652;

                        v = 'Hello world'

String concatenation:

 

To concatenate two or more strings use the comma operator.

 

Example:

 

            a = 20;

 

     u = 'Temperature ';

 

     v = ' °F';

 

 

     w = u, a, v;

 

The result will be 'Temperature 20 °F'

 

Another way to do the same is:

 

            w = 'Temperature ', a,' °F';

 

 

String concatenation can only be done on string variables value assignment and write_str function

 

Assigning ASCII values to a string variable:

 

To assign ASCII values use the $ operator. After the operator type the ASCII value on decimal notation. ACII value zero is not allowed.

 

Example:

 

            z = 'Hello world',$13,$10;

 

ASCII values assignment can only be done on string variables value assignment and write_str function

 

Arithmetic operators

 

Operator

Description

=

Assignment

^

Exponential

|

Bitwise Or

&

Bitwise And

+

Addition

-

Subtraccion

*

Multiplication

/

Division

%

Modulo

 

Example:

 

a = 130;

b = a+5;

 

Result: b variable value is 135.

 

Program structure

Al instruction must end with the “;” symbol.

 

The program runs in a loop. This means that it will run until the last program line and start from the beginning again.

The script last instruction must be “end;”  

     a = a + 1;

     end;

 

 

On this example "a" variable will be incremented constantly. Its initial value is 0.

 

On-line comments:  

If you wish to add a comment line you must use the “#. On-line comments must also en with the “;” symbol.  

Flow control functions

“start” function

It marks a block that will be executed only once. It must be written at the beginning of the script.

 

          Syntax:


start
{
...;
...;
};

 

Example:

 

     start

     {

         a = 10;  #a initial value is 10;

     };

     a = a + 1;   #a is incremented by 1 constantly;

     end;

 

“if-else” function

 

The script will decide the script execution flow based on condition. If the condition is true the code in the block next to the "if" instruction will be executed. You can add also a code block that will be executed if the condition is no true.

The condition operators are the following ones:

Operator

Description

=

Equals to

!

Not equal to

Greater than

Less than

 

 

Syntax:            

Single “if”:

     if condition
   
  {
        ...;
        ...;
     };
 
           
A “;” symbol is required to close the block.

"if-else”:

     if condition
   
  {
        ...;
        ...;
     }

     else
   
 
{
        ...;
        ...;
     };
 
        

The“;” is only requiered on the "else" block.

“end” function

This function is used to mark the end of the program. When the interpreter finds this line it will jump to the first line of the script.

 

Syntax:

 

            end;

 

Interface functions

“read_io” funcion

With read_io you can get values from different sources like I/O channels, the real time clock, etc

The “source” is indicated with a number. Some sources will require an index number to point an address inside that source.

The result of this function will be loaded in the indicated numeric variable.  

Syntax:  

read_io source,numeric_variable,index;              

Available sources may change depending on the device where you are running the script and the script version. New sources can be added in the future.

Browse "Sources-Destinations" section for the currently available ones.

“write_io” function

With write_io you can set values in different destinations, like digital output channels, pulse channels, etc.

 

The “destination” is indicated with a number. Some destinations will require an index number to point an address inside that destination.

The value to be written can be a number or a numeric variable.

Syntax:  

write_io destination,index,value;                        

Available destinations may change depending on the device where you are running the script and the script version. New destinations can be added in the future.

 

Browse "Sources-Destinations" section for the currently available ones.  

“read_str” function

With read_str you can get incoming strings from different sources like the serial port or a SMS.

The “source” is indicated with a number.

The result of this function will be loaded in the indicated string and numeric variables. The numeric variable will contain the string length. If the value is 0 it means that there isn't a new incoming string from that source.

Syntax:

read_str source,numeric_variable,string_variable;

Available sources may change depending on the device where you are running the script and the script version. New sources can be added in the future.

 

Browse "Sources-Destinations" section for the currently available ones.  

“write_str” function

With write_str you can send strings to different destinations, like an SMS or the serial port. The “destination” is indicated with a number.

Syntax:

write_str destination,string;.

Available destinations may change depending on the device where you are running the script and the script version. New destinations can be added in the future.

Browse "Sources-Destinations" section for the currently available ones.  

The string can be a variable string or a text typed between single quotes. This function support string concatenation and including ASCII values.

String functions

“is_equal” function

Compares one string variables with a text (variable string or a text typed between single quotes). The numeric variable will contain the result, 1 if they are equal or 0 if they are different.

Syntax:

is_equal numeric_variable,string_variable,string;

Example:

v='PUMP RUN';
is_equal c,v,'PUMP RUN';
if c=1 {
         #texts are equal;
};

“finish_with” function

Compares the end of one string variables with a text (variable string or a text typed between single quotes). The numeric variable will contain the result, 1 if they match or 0 if they don't.

Syntax:

finish_with numeric_variable,string_variable,string;

Example:

v='PUMP RUN';
finish_with c,v,'RUN';
if c=1 {
         #The string ends with 'RUN';
};

“begin_with” function

Compares the beginning of one string variables with a text (variable string or a text typed between single quotes). The numeric variable will contain the result, 1 if they match or 0 if they don't.

Syntax:

begin_with numeric_variable,string_variable,string;

Example:

v='PUMP RUN';
end_with c,v,'RUN';
if c=1 {
         #The string ends with 'RUN';
};

“contains” function

Determines if one string (fixed text or string variable) is contained by a string variable. The numeric variable will contain the position where the string if found or 0 if its not contained.

Syntax:

contains numeric_variable,string_variable,string;

Example:

v='PUMP RUN';
contains c,v,'MP';
if c>0 {
         #The variable v contains the text 'MP' ;
};

“upper” function

Converts all character is one string variable to uppercase.

Syntax:

upper string_variable;

Example:

v='Turn ON';
upper v;
#v equals 'TURN ON';

“lower” function

Converts all character is one string variable to lowercase.

Syntax:

lower string_variable;

Example:

v='Turn ON';
upper v;
#v equals 'turn on';

“strlen” function

Gets the string length and stores it on a numeric variable.

Syntax:

strlen numeric_variable,string_variable;

Example:

v='PUMP RUN';
strlen c,v;
#c equals 8 ;

“substr” function

Returns part of a string within the same string variable

Syntax:

substr start,end,string_variable;

v='PUMP RUN';
substr 2,3,v;
#v equals 'UMP';

Conversion functions

“point” function

Converts a numeric variable to string and places a decimal point on a fixed position.

Syntax:

point string_variable,numeric_variable,decimals;

Example:

c=123;
point v,c,1;
#v equals '12.3'; 
         

“aton” function

Converts number inside a string variable to a numeric variable. It starts at the beginning of the string and ends where it finds a non-numeric character or reaches the end of the string.

Syntax:

aton numeric_variable,string_variable;

Example:

v='123 RPM';
aton c,v;
#c equals 123;
           

“day”,”month”,”year”,”hs”,”min”,”sec” and “nday” functions

These functions will convert a time_stamp to day, month, year, hour, minute, seconds or day of the week.

Current data/time can be read using read_io with source #7.

Syntax:

day day,timestamp;

month mont,timestamp;

year year,timestamp;

hs hour,timestamp;

min minutes,timestamp;

sec seconds,timestamp;

nday dayoftheweek,timestamp;

“nday” function will return the day of the week number starting with Sunday=0s.

Example:

read_io 7,e,0; #Reads current time and date into e;
day f,e;
month g,e;
year h,e;
hs i,e;
min j,e;
sec k,e;
#The current time and date is f/g/h i:j:k;

Mathematical and logic functions

“neg” function

It will invert the value of a numeric variable bitwise.

Syntax:

neg result,initialvalue;

Example:

a=32323; #7E43h
neg b,a;

# b equals 4294934972 (FFFF81BC);

“sqtr” function

Calculates the square root of a numeric variable. As numeric values are integers the fractional part will be truncated. Multiply the number before calculation if you need higher precision.

Syntax:

sqrt result,initialvalue;

Example:

a=225;
sqrt b,a;
#b equals 15;

“scale” function

Scales a number using the two point form of the linear equation.

Syntax:

scale result,initialvalue,x0,x1,y0,y1;

Example: Scale a 4-20mA signal on input AN1 to a number between 0 and 500

read_io 2,a,1; #a = AN1;
scale c,a,400,2000,0,500;
#c equals scaled number

Timming functions

This functions will allow you to control the program flow using timers.

“timer” and “check_timer” function

Use "timer" to store on a numeric variable the time you want to wait (in milliseconds)

Use “check_timer” to check if the time has expired or not.


Syntax:

timer numeric_variable,time_in_milliseconds;
...
check_timer numeric_variable
{
    ...
    ...
};

Once the time has expired the code inside the check_timer block will be executed. This code will be executed on every program loop until the timer is loaded again. Typically you will be reloaded the timer inside the check_timer block.

Note: The timing functions are no recommend on applications where precision timing is required because timers can have some dispersion.

2024-07-02