| Module: | JavaLikeCalc |
| Name: | Calculator based on Java-like language. |
| Type: | DAQ |
| Source: | daq_JavaLikeCalc.so |
| Version: | 1.9.5 |
| Author: | Roman Savochenko |
| Translated: | Maxim Lysenko |
| Description: | Provides based on java like language calculator and engine of libraries. The user can create and modify functions and libraries. |
| License: | GPL |
The module of controller JavaLikeCalc provides a mechanism for creating of functions and libraries on Java-like language. Description of functions on Java-like language is reduced to the binding parameters of the function with algorithm. In addition, the module has the functions of the direct computation by creation of the computing controllers.
Direct computations are provided by the creation of controller and linking it with the function of this module. For linked function it is created the frame of values, with which the periodically calculating is carried out.
The module implements the functions of the horizontal redundancy, namely, working in conjunction with the remote station of the same level. In addition to the synchronization of the archives of values and archives of attributes of parameters the module implements synchronization of computational function, in order to shockless catch of the algorithms.
Parameters of functions can be freely created, deleted or modified. The current version of the module supports up to 65535 parameters of the function in the sum with the internal variables. View of the editor of functions is shown in Figure 1.

After any program changing or configuration of parameters recompiling of the programs with forestalling of linked with function objects of values of TValCfg is performed. Language compiler is built using well-known generator grammar «Bison», which is compatible with the not less well-known tool Yacc.
The language uses the implicit definition of local variables, which is to define a new variable in the case of assigning a value to it. This type of local variable is set according to the type of the assigning value. For example, the expression <Qr=Q0*Pi+0.01;> will define Qr variable with the type of variable Q0.
In working with various types of data language uses the mechanism of casting the types in the places where such casting is appropriate.
To comment the sections of code in the language it is provided «//» and "/ * ... * /" characters. Everything that comes after "//" up to the end of the line and between "/ * ... * /", is ignored by the compiler.
During the code generation language compiler produces an optimization of constants and casting the types of the constants to the required type. Optimizing of the constants means the implementation of computing of the constants in the process of building of the code under the two constants and paste the result in the code. For example, the expression <y=pi*10;> reduces to a simple assignment <y=31.4159;>. Casting the types of constants to the required type means formation of the constant in the code which excludes the cast in the execution process. For example, the expression <y=x*10>, in the case of a real type of the variable x, is transformed into <y=x*10.0>.
The language supports calls of the external and internal functions. Name of any function in general is perceived as a character, test for ownership of which by a particular category is done in the following order:
Call of the external function, attribute of system parameters is written as an address to the object of dynamic tree of the object model of the system OpenSCADA in the form of: <DAQ.JavaLikeCalc.lib_techApp.klapNotLin>.
To provide the possibility of writing custom procedures for the administration of the various components of OpenSCADA module provides the implementation of API pre-compilation of custom procedures of individual components of OpenSCADA on the implementation of Java-like language. These components are already: Templates of the parameters of subsystem "Data acquisition" and Visual control area (VCA).
Keywords: if, else, while, for, break, continue, return, using, true, false.
Constants:
Types of variables:
Built-in constants: pi = 3.14159265, e = 2.71828182, EVAL_BOOL(2), EVAL_INT(-2147483647), EVAL_REAL(-3.3E308), EVAL_STR("<EVAL>")
Attributes of the parameters of system OpenSCADA (starting from subsystem DAQ, as follows <Type of DAQ module>.< Controller>.<Parameter>.<Attribute>).
The functions of the object model of the system OpenSCADA.
Operations supported by the language presented in the table below. The priority of operations is reduced from top to bottom. Operations with the same priority is composed of one color group.
| Symbol | Îïèñàíèå |
| () | Call of the function. |
| {} | Program blocks. |
| ++ | Increment (post and pre). |
| -- | Decrement (post and pre). |
| - | Unary minus. |
| ! | Logical negation. |
| ~ | Bitwise negation. |
| * | Multiplication. |
| / | Division. |
| % | The remainder of integer division. |
| + | Addition |
| - | Subtraction |
| << | Bitwise shift left |
| >> | Bitwise shift right |
| > | Greater |
| >= | Greater than or equal to |
| < | Less |
| <= | Less than or equal to |
| == | Equals |
| != | Unequal |
| | | Bitwise «OR» |
| & | Bitwise «AND» |
| ^ | Bitwise «Exclusive OR» |
| && | Boolean «AND» |
| || | Boolean «OR» |
| ?: | Conditional operation (i=(i<0)?0:i;) |
| = | Assignment. |
| += | Assignment with addition. |
| -= | Assignment with subtraction. |
| *= | Assignment with multiplication. |
| /= | Assignment with division. |
Virtual machine of the language provides the following set of built-in functions general-purpose:
To ensure a high speed in mathematical calculations module provides embedded mathematical functions that are called at the level of commands of virtual machine. Predefined mathematical functions:
The total list of operators of the language:
The language of module supports two types of conditions. First — this is the operation of condition for use within the expression, the second — a global, based on the conditional operators.
Conditions inside the expression is based on the operations of «?» And «:». As an example we'll write the following practical expression <st_open=(pos>=100)?true:false;>, which reads as «If the variable <pos> greater than or equal to 100, the variable st_open is set to true, otherwise — to false.
The global condition is based on the conditional operators «if» and «else». An example is the same expression, but written by other means <if(pos>100) st_open=true; else st_open=false;>. As shown, the expression is written in a different way, but is read in the same way.
Two types of loops are supported: while, for and for-in. The syntax of the loops corresponds to programming languages: C++, Java, and JavaScript.
Loop while generally written as follows: while(<condition>) <body of the loop>;
Loop for is written as follows: for(<pre-initialization>;<condition>;<post-calculation>) <body of the loop>;
Loop for-in is written as follows: for( <variable> in <object> ) <body of the loop>;
Where:
The language supports the following special characters of string variables:
The language provides the data type "Object" support. The data type "Object" is associated container of properties and functions. The properties can support data of fourth basic types and other objects. The access to properties is doing through the dot to object <obj.prop> and also by property placement into the rectangle brackets <obj["prop”]>.It is obvious that the first mechanism is static, while the second lets you to specify the name of the property through a variable. Creating an object is carried by the keyword <new>: <varO = new Object()>. The basic definition of the object does not contain functions. Copying of an object is actually makes the reference to the original object. When you delete an object is carried out the reducing of the reference count, and when a reference count is set to zero then object is removed physically.
Different components can define basic object with special properties and functions. The standard extension of the object is an array "Array", which is created by the command <varO = new Array(prm1,prm2,prm3,...,prmN)>. Comma-separated parameters are placed in the array in the original order. If the parameter is the only one the array is initiated by the specified number of empty elements. Peculiarity of the array is that it works with the properties as the indexes and their complete naming is meaningless, and therefore the mechanism of addressing only by the placing the index into square brackets <arr[1]> is accessible. Array stores the properties in its own container of the one-dimensional array. Digital properties of the array are used to access directly to the array, and the characters work as object properties. For more details about the properties and functions of the array can be read here.
The object of regular expression RegExp is created by command <varO = new RegExp(pat,flg)>, where <pat> — pattern of regular expression, and <flg> — match flags. The object for work with regular expressions, based on the library PCRE. In the global search set object attribute "lastIndex", which allows you to continue searching for the next function call. In the case of an unsuccessful search for the attribute "lastIndex" reset to zero. For more details about the properties and functions of the array can be read here.
For random access to the arguments of the functions provided the arguments object, which you can refer to by the symbol "arguments". This object contains the property "length" with a number of arguments in functions and allows you to access to a value of the argument by its number or ID. Consider the enumeration of the arguments on the cycle:
args = new Array();
for(var i=0; i < arguments.length; i++)
arg[i] = arguments[i];
The basic types have the partial properties of the object. Properties and functions of the basic types are listed below:
Functions:
Functions:
var rez = "Java123Script".search("script","i"); // rez = 7
var rez = "Java123Script".search(new RegExp("script","i")); // rez = 7
var rez = "1 plus 2 plus 3".match("\\d+","g"); // rez = [1], [2], [3]
var rez = "1 plus 2 plus 3".match(new RegExp("\\d+","g")); // rez = [1], [2], [3]
rez = "1,2, 3 , 4 ,5".split(new RegExp("\\s*,\\s*")); // rez = [1], [2], [3], [4], [5]
rez = "Javascript".replace(4,3,"67"); // rez = "Java67ipt"
rez = "123 321".replace("3","55"); // rez = "1255 5521"
rez = "value = \"123\"".replace(new RegExp("\"([^\"]*)\"","g"),"``$1''")); // rez = "value = ``123''"
For access to system objects (nodes) of the OpenSCADA the corresponding object is provided which is created simply by specifying the enter point "SYS" of the root object OpenSCADA, and then with the point separator the sub-objects in accordance with the hierarchy are specified. For example, the call of the request function over the outgoing transport is carried out as follows: SYS.Transport.Sockets.out_testModBus.messIO(strEnc2Bin("15 01 00 00 00 06 01 03 00 00 00 05"));.
Here are some examples of programs on Java-like language:
//Model of the course of the executive machinery of ball valve
if( !(st_close && !com) && !(st_open && com) )
{
tmp_up=(pos>0&&pos<100)?0:(tmp_up>0&&lst_com==com)?tmp_up-1./frq:t_up;
pos+=(tmp_up>0)?0:(100.*(com?1.:-1.))/(t_full*frq);
pos=(pos>100)?100:(pos<0)?0:pos;
st_open=(pos>=100)?true:false;
st_close=(pos<=0)?true:false;
lst_com=com;
}
//Valve model
Qr=Q0+Q0*Kpr*(Pi-1)+0.01;
Sr=(S_kl1*l_kl1+S_kl2*l_kl2)/100.;
Ftmp=(Pi>2.*Po)?Pi*pow(Q0*0.75/Ti,0.5):(Po>2.*Pi)?Po*pow(Q0*0.75/To,0.5):pow(abs(Q0*(pow(Pi,2)-pow(Po,2))/Ti),0.5);
Fi-=(Fi-7260.*Sr*sign(Pi-Po)*Ftmp)/(0.01*lo*frq);
Po+=0.27*(Fi-Fo)/(So*lo*Q0*frq);
Po=(Po<0)?0:(Po>100)?100:Po;
To+=(abs(Fi)*(Ti*pow(Po/Pi,0.02)-To)+(Fwind+1)*(Twind-To)/Riz)/(Ct*So*lo*Qr*frq);
The controller of the module connects with the functions of libraries, built with his help, to provide immediate calculations. In order to provide calculated data in the system OpenSCADA parameters can be created in the controller. Example of the configuration tab of the controller of the given type depicted in Figure 2.

From this tab you can set:
Tab "Calculations" of the controller (Fig. 3) contains the parameters and the text of the program, directly performed by the controller. Also for monitoring of execution the time of calculating of the program is shown. Module provides a number of special options available in the controller program:

Parameter of the controller of the module executes the function of providing the access to the results of computation of the controller to the system OpenSCADA by attributes if the parameters. Configuration tab contains only one specific field of the , set the controller only contains a field of listing the parameters of calculated function, which should be reflected.
The module provides a mechanism to create libraries of user functions on Java-like language. Example of the configuration tab of the library is depicted in Figure 4. The tab contains the basic fields: status, identifier, name and description, and also address of the table, in which the library is kept. In the "Functions" tab of the library besides the list of functions the form of copying functions is contained.

Function, as well as the library, contains the basic configuration tab, tab of the formation of the program and the parameters of function (Fig. 1), as well as the performance tab of the created function.
Some objects of the module provides functions for user's programming.
The object "Functions library" (SYS.DAQ.JavaLikeCalc["lib_Lfunc"])
The object "User function" ( SYS.DAQ.JavaLikeCalc["lib_Lfunc"]["func"] )