OpenSCADAWiki: Home Page En/Doc/ Java Like Calc ...

Home | Каталог | »зменени€ |  омментарии | ѕользователи | Регистрация | ¬ход  ѕароль:  

The module <JavaLikeCalc> of subsystem "Data Acquisition"

Module: JavaLikeCalc
Name: Calculator based on Java-like language.
Type: DAQ
Version: 3.6.0
Author: Roman Savochenko, Maxim Lysenko (2009-2010)
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.

View of the editor of functions. (126  б)
Fig.1. View of the editor of functions.

After any program changing or configuration of parameters recompiling of the programs with forestalling of linked with function objects of values of TValCfg notification. 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 byte-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.

Assignement expressions can be writed through symbol ',', for example:

var1=1, var2=3, var4=var1+var2;
for(var1=0, var2=0, var3=-1; var1 < 10; var1++, var2++) var3++;

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. For static functions you are allowed to the dynamic linking also in following way:

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 for example are: Templates of the parameters of subsystem "Data acquisition" and Visual control area (VCA).

1. Java-like language

1.1. Elements of the language

Keywords: if, else, while, for, break, continue, return, function, using, true, false.

Types of variables:

Built-in constants: pi = 3.14159265, e = 2.71828182, EVAL_BOOL(2), EVAL_INT(-9223372036854775807), EVAL_REAL,EVAL(-1.79E308), 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.

1.2. Operations of the language

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.

()Call of the function.
{}Program blocks.
++Increment (post and pre).
--Decrement (post and pre).
-Unary minus.
!Logical negation.
~Bitwise negation.
%The remainder of integer division.
<<Bitwise shift left
>>Bitwise shift right
>=Greater than or equal to
<=Less than or equal to
|Bitwise "OR"
&Bitwise "AND"
^Bitwise "Exclusive OR"
&&Boolean "AND"
||Boolean "OR"
?:Conditional operation "i=(i<0)?0:i;"
+=Assignment with addition.
-=Assignment with subtraction.
*=Assignment with multiplication.
/=Assignment with division.

1.3. Embedded functions of the language

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:

1.4. Operators of the language

The total list of operators of the language:

1.4.1. Conditional operators

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.

1.4.2. Loops

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};

{condition} Ч expression, determining the condition;
{body of the loop} Ч the body of the loop of multiple execution;
{pre-initialization} Ч expression of pre-initialization of variable of the loop;
{post-calculation} Ч expression of modification of parameters of the loop after the next iteration;
{variable} Ч variable, which will contain object's properties name at scan;
{object} Ч object for which properties scan gone.

1.4.3. Internal functions

The language supports internal functions declaration and it's follow call. For an internal function declare used the keyword "function" and in whole it have that syntax: function {fName} ({var1}, {var2}, ... {varN}) { {the function body} }. Declaration of an internal function into other one is unallowable but call of a function declared previously is allowed.

Call the internal function performs at the typical way, as a procedure {fName}({var1}, {var2}, ... {varN}); or as a function {vRez} = {fName}({var1}, {var2}, ... {varN});. Call of the internal function allowed only after it's declaration bottom!

All defined variables into the main body inaccessible into the internal function and can be pass in only as two way arguments of the internal function call. All defined variables into the internal function have itself namespace and inaccessible from the main body or any other internal function and can be pass out to the main body only as two way arguments or return of the internal function call.

Operator "return" into the internal function makes controllable finishing of the function execution and places a pointed variable or an expression result as the internal function call result.

An example of the internal function declaration and using in typical way shown bottom:

1.4.4. Special characters of string variables

The language supports the following special characters of string variables:

"\n" Ч line feed;
"\t" Ч tabulation symbol;
"\b" Ч culling;
"\f" Ч page feed;
"\r" Ч carriage return;
"\\" Ч the character itself '\'.
"\041" Ч symbol '!' wrote by octal number;
"\x21" Ч symbol '!' wrote by hex number.

1.5. Object

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. Object's properties removing you can perform by the operator "delete". 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 the main mechanism of addressing is 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 regular expression object 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++)
  args[i] = arguments[i];

The basic types have the partial properties of the object. Properties and functions of the basic types are listed below:





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(Special.FLibSYS.strEnc2Bin("15 01 00 00 00 06 01 03 00 00 00 05"));.

1.6. Examples of programs on the language

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);

2. Controller and its configuration

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.

Configuration tab of the controller. (99  б)
Fig.2. Configuration tab of the controller.

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 provide processing a number of special options available in the controller program:

Tab "Calculations" of the controller. (125  б)
Fig.3. Tab "Calculations" of the controller.

3. The parameter of the controller and its configuration

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.

4. Libraries of functions of module

The module provides a mechanism to create libraries of user's functions on Java-like language. Example of the configuration tab of the library is depicted in Figure 4. The tab contains the basic fields: accessing, address of the DB table, date and time of modification, identifier, name and description.

Tab of the configuration of the library. (77  б)
Fig.4. Tab of the configuration of the library.

5. User functions of the module

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.

6. User programming API

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"] )

7. Productivity

Source texts of procedures on the language compiled to byte-code of the virtual machine which next executed by the virtual machine. The byte-code is not native machine code and achieving to productivity of the hardware platform into the virtual machine that executing is theoretical unreal, sure if the virtual machine code is not executed direct by the CPU. That is, productivity of the byte-code execution approximately low by ten to the hardware productivity by overheads to the virtual machine commands, separating multi-threads access to data, clear cast and the lack of strict typing, and also dynamic nature of the language and present complex types "String" and "Object".

ќснование: ѕервична€ оценка производительности виртуальной машины системы OpenSCADA на основе выражени€ "y=x1+x2", где все переменные глобальные вещественного типа.

—тади€ ƒействие K7_1G-0, мкс
1 »нициализаци€ списка регистров 2.3
2 ¬ход в функцию exec() 3
3 ќбход команд 4.4
4 „тение 9
5 ѕолное врем€ 10.2

ќснование: ќбоснование текущей производительности, оценка и оптимизаци€. »змерени€ проводились выборкой минимального времени из п€ти вызовов по 1000 исполнений формулы "a -= b*(a-c)" и еЄ сокращений в каждом вызове. ¬се переменные глобальные вещественного типа.

Formula Time on AMDGeode-500 (the operation time), мкс Notes
a -= b*(a-c) 4.52 (0.74)
a -= b*c 3.78 (0.72)
a -= b 3.06 (0.56)
=> full call: 3.06 (0.49): getValR() = 0.49/2 = 0.245
=> only write const = 2.57 (0.17)
=> pass.code = 2.4
a = b 2.5 (1.21)
!> use unified TVariant function setVal() and getVal() = 7.6 (2.7 write only) => fix to 5.0 by prevent default set to string EVAL.
=> full call: 2.5 (0.33)
=> only write const: 2.17 (0.47)
=> only check for type: 1.7 (0.3)
=> pass code: 1.4 (0.11)
Write to function IO is longer then read from local register by other context call and additional checking for NAN and real modification.
Empty 1.29 Infrastructure and measurement method utilization time.

Reason: Estimate performance of access to low level IO lines on Raspberry Pi GPIO in different ways of JavaLikeCalc language of OpenSCADA.
Conditions: Raspberry Pi 3, GPIO40, DAQ.BCM2835 (based on library bcm2835)

Operation Result, us
Sleep. Lag on sleep in 1ms measured, which mostly limited by the realtime reaction about 100us.
SYS.sleep(); +110
Special.FLibSYS.fnc_tmSleep(); +70
Sleep. Lag on sleep in 100us measured, which performs in the measuring cycle.
SYS.sleep(); +17
Special.FLibSYS.fnc_tmSleep(); +2
Get GPIO pin's level
From an attribute res = BCM2835.pi2.pi2.gpio17; 5.4
By the static accessing function res = DAQ.BCM2835.pi2.pi2.fnc_get(17); 1.6
By the static accessing function with prepare the link function get = "DAQ.BCM2835.pi2.pi2.fnc_get"; for(i = 0; i < 10000; i++) res = get(17); 1.7
By the dynamic accessing function res =; 80
By the dynamic accessing function with prepare the end object tO = SYS.DAQ.BCM2835.pi2.pi2.fnc_get; for(i = 0; i < 1000; i++) res =; 14.3
Put GPIO pin's level
To an attribute BCM2835.pi2.pi2.gpio18 = true; 2.1
By the static accessing function DAQ.BCM2835.pi2.pi2.fnc_put(18, true); 1.4
By the static accessing function with prepare the link function put = "DAQ.BCM2835.pi2.pi2.fnc_put"; for(i = 0; i < 10000; i++) put(17, false); 1.5
By the dynamic accessing function, true); 79
By the dynamic accessing function with prepare the end object tO = SYS.DAQ.BCM2835.pi2.pi2.fnc_put; for(i = 0; i < 1000; i++), true); 14.3


—траницы, ссылающиес€ на данную: HomePageEn/Doc
/Home Page En / Using /  рамоторск Ўаров ћельница

ћного файлов (5).[ѕоказать файлы/форму]
 омментариев нет. [ѕоказать комментарии/форму]