REXLANG – User programmable block

Block SymbolLicensing group: REXLANG
PIC

Function Description
The standard function blocks of the REX control system cover the most typical needs in control applications. But there still exist situations where it is necessary (or more convenient) to implement an user-defined function. The REXLANG block covers this case. It implements an user-defined algorithm written in a scripting language very similar to the C language (or Java).

Scripting language
As mentioned, the scripting language is similar to the C language. Nevertheless, there are some differences and limitations:

Scripting language syntax
The scripting language syntax is based on the C language, but pointers are not supported and the data types are limited to long and double. Moreover the input, output and parameter keywords are defined for referencing the REXLANG block inputs, outputs and parameters. The syntax is as follows:

The input and parameter variables are read-only while the output variables are write-only. For example:

double input(1) input_signal; /* declaration of a variable of type  
                                  double, which corresponds with the  
                                  u1 input of the block */  
long output(2) output_signal; /* declaration of a variable of type  
                                  long, which corresponds with the y2  
                                  output of the block */  
 
input_signal = 3;               //not allowed, inputs are read-only  
sum = output_signal + 1;        //not allowed, outputs are write-only  
if (input_signal>1) output_signal = 3 + input_signal;  //correct

Available functions
The following functions are available in the scripting language:

Remarks

Debugging the code
Use the Trace command mentioned above.

Inputs

HLD

Hold – the block code is not executed if the input is set to on

bool

RESET

Rising edge resets the block. The block gets initialized again (all global variables are cleared and the Init() function is called).

bool

u0..u15

Input signals which are accessible from the script

unknown

Outputs

iE

Runtime error code. Unless iE = 0 or iE = 1 the algorithm is stopped until it is reinitialized by the RESET input or by restarting the executive)

error

0 ....

No error occurred, the whole main() function was executed (also the init() function).

-1 ...

The execution was suspended using the Suspend() command, i.e. the execution will resume as soon as the REXLANG block is executed again

xxx ..

Error code of the REX Control System, see Appendix B

y0..y15

Output signals which can be set from within the script

unknown

Parameters

srcname

Source file name  srcfile.c

string

srctype

Coding of source file  1

long

1: C-like 

Text file respecting the C-like syntax described above

2: STL 

Text file respecting the IEC61131-3 standard. The standard is implemented with the same limitations as the C-like script (i.e. no structures, only INT, REAL and STRING data types, function blocks are global variables VAR_INPUT, outputs are global variables VAR_OUTPUT, parameters are global variables VAR_PARAMETER, standard functions according to specification, system and communication functions are the same as in C-like).

3: RLB 

REXLANG binary file which results from compilation of C-like or STL scripts. Use this option if you do not wish to share the source code of your block.

4: ILL 

Text file with mnemocodes, which can be compared to assembler. This choice is currently not supported.

stack

Stack size defined as number of variables. Default and recommended value is 0, which enables automatic estimation of the necessary stack size.

long

debug

Debug level – checking is safer but slows down the execution of the algorithm. Option No check can crash REXapplication on target platform if code is incorect.  3

long

1 ....

No check

2 ....

Basic check

3 ....

Full check

strs

Total size of buffer for strings. Enter the maximum number of characters to allocate memory for. The default value 0 means that the buffer size is determined automatically.

long

p0..p15

Parameters which are accessible from the script

unknown

Example C-like
The following example shows a simple code to sum two input signals and also sum two user-defined parameters.

double input(0) input_u0;  
double input(2) input_u2;  
 
double parameter(0) param_p0;  
double parameter(1) param_p1;  
 
double output(0) output_y0;  
double output(1) output_y1;  
 
double my_value;  
 
long init(void)  
{  
  my_value = 3.14;  
  return 0;  
}  
 
long main(void)  
{  
  output_y0 = input_u0 + input_u2;  
  output_y1 = param_p0 + param_p1 + my_value;  
  return 0;  
}  
 
long exit(void)  
{  
  return 0;  
}

Example STL
And here is the same example in Structured Text.

VAR_INPUT  
  input_u0:REAL;  
  input_u1:REAL;  
  input_u2:REAL;  
END_VAR  
 
VAR_OUTPUT  
  output_y0:REAL;  
  output_y1:REAL;  
END_VAR  
 
VAR_PARAMETER  
  param_p0:REAL;  
  param_p1:REAL;  
END_VAR  
 
VAR  
  my_value: REAL;  
END_VAR  
 
FUNCTION init : INT;  
  my_value := 3.14;  
  init := 0;  
END_FUNCTION  
 
FUNCTION main : INT;  
  output_y0 := input_u0 + input_u2;  
  output_y1 := param_p0 + param_p1 + my_value;  
  main := 0;  
END_FUNCTION  
 
FUNCTION exit : INT;  
  exit := 0;  
END_FUNCTION