<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html class="client-nojs" dir="ltr" lang="en">
<head>
<meta charset="UTF-8" />
<title>Modules/JavaLikeCalc - OpenSCADAWiki</title>
<meta content="MediaWiki 1.26.4" name="generator" />
<link href="https://www.gnu.org/copyleft/fdl.html" rel="copyright" />
<link href="../files/doc.css" rel="stylesheet" /></head>
<body><div class="floatright"><a href="../index.html"><img alt="OpenSCADA" src="../../en/files/index.png" /></a></div><div id="mw_header">
			<div class="mw-indicators">
</div>
			<h1 id="firstHeading" lang="en">Modules/JavaLikeCalc</h1>
		</div><div class="mw-content-ltr" dir="ltr" id="mw-content-text" lang="en"><div class="mw-pt-languages" dir="ltr" lang="en"><div class="mw-pt-languages-list autonym"><span class="mw-pt-languages-ui mw-pt-languages-selected mw-pt-progress mw-pt-progress--complete">English</span>&nbsp;• ‎<a class="mw-pt-progress mw-pt-progress--complete" href="../../ru/Modules/JavaLikeCalc.html" title="Модули/Вычислитель похожий на Java (85% translated)">mRussian</a>&nbsp;• ‎<a class="mw-pt-progress mw-pt-progress--complete" href="../../uk/Modules/JavaLikeCalc.html" title="Модулі/Обчислювач подібний до Java (100% translated)">Українська</a></div></div>
<table class="wikitable">

<tr>
<th> Module </th>
<th> Name </th>
<th> Version </th>
<th> License </th>
<th> Source </th>
<th> Languages </th>
<th> Platforms </th>
<th> Type </th>
<th> Author </th>
<th> Description
</th></tr>

<tr>
<td> <a href="../Modules/JavaLikeCalc.html" title="Special:MyLanguage/Modules/JavaLikeCalc">JavaLikeCalc</a> </td>
<td> Calculator on the Java-like language
</td>
<td> 5.7 </td>
<td> GPL2 </td>
<td> daq_JavaLikeCalc.so </td>
<td> en,uk,ru,de </td>
<td> x86,x86_64,ARM
</td>
<td> DAQ </td>
<td> Roman Savochenko<br />&nbsp;&nbsp;<font size="-2"><i>Maxim Lysenko (2009-2010) — the page initial translation</i></font> </td>
<td> Provides a calculator and libraries engine on the Java-like language. The user can create and modify functions and their libraries.
</td></tr></table>
<p>The data source module provides OpenSCADA for a mechanism of creating functions and their libraries on Java-like language. The writing of the function in the Java-like language is reduced to the binding of the parameters of the function by an algorithm.
</p><p>Direct computations are provided by the creation of controller object and linking it with the function of this module. For linked function it is created the frame of values (context), with which the periodically calculating is carried out.
</p><p>The module implements the functions of the horizontal redundancy, that is 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 holding of the algorithms.
</p><p>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. The view of editing functions in the OpenSCADA configurator is shown in Figure 1. <a class="image" href="http://oscada.org/wiki/File:At.png"><img alt="At.png" height="22" src="../files/At.png" width="22" /></a> The parameter name's rows after the first one treat as help.
</p>
<div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:944px;"><a class="image" href="http://oscada.org/wiki/File:JavaLikeCalc_funcedit.png"><img class="thumbimage" height="680" src="../files/JavaLikeCalc_funcedit.png" width="942" /></a>  <div class="thumbcaption">Fig.1. View of editing functions in the OpenSCADA configurator.</div></div></div></div>
<p>After any change in the program text or parameter configuration, the program is recompiled by notifying the values objects <i>TValCfg</i> associated with the function. The language compiler is built using the well-known grammar generator "Bison", which is compatible with the no less well-known "Yacc" utility.
</p><p>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 <b>Qr=Q0*Pi+0.01;</b> will define <b>Qr</b> variable with the type of variable <b>Q0</b>. And with implementing the built-in functions, there also added the statement <b>var</b> for defining the variables in the function scope instead global one.
</p><p>In working with various types of data the language uses the mechanism of casting the types in the places where such casting is appropriate.
</p><p>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.
</p><p>During the code generation, the language compiler produces an optimization of constants and casting the types of the constants to the required type. The optimization of the constants means the calculation of two constants and the insertion of the result into the code in the process of constructing a byte-code. For example, the expression <b>y=pi*10;</b> reduces to a simple assignment <b>y=31.4159;</b>. 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 <b>y=x*"10";</b>, in the case of the real type of the variable <b>x</b>, is transformed into <b>y=x*10;</b>.
</p><p>Assignment expressions can be recorded through symbol ',', for example:
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="nx">var1</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">var2</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span> <span class="nx">var4</span> <span class="o">=</span> <span class="nx">var1</span><span class="o">+</span><span class="nx">var2</span><span class="p">;</span>
<span class="k">for</span><span class="p">(</span><span class="nx">var1</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">var2</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">var3</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">;</span> <span class="nx">var1</span> <span class="o">&lt;</span> <span class="mi">10</span><span class="p">;</span> <span class="nx">var1</span><span class="o">++</span><span class="p">,</span> <span class="nx">var2</span><span class="o">++</span><span class="p">)</span> <span class="nx">var3</span><span class="o">++</span><span class="p">;</span>
</pre></div>
<p>The language supports calls of the external and internal functions. Name of any function in general is perceived as a character, which is tested to belong a particular category in the following order:
</p>
<ul><li> does not begin with a point:
<ul><li> keywords (if, else, while, ...);</li>
<li> variables-attributes of that function;</li>
<li> named-builtin constants (EVAL, pi, e, ...) and objects-constants (SYS, arguments)</li>
<li> builtin functions (sin, cos, ...);</li>
<li> internal, external functions, object functions and <a href="../User_API.html" title="Special:MyLanguage/Documents/User API">nodes of the object model OpenSCADA</a>;</li>
<li> previously registered automatic variables;</li>
<li> global attributes of DAQ parameters and properties of variables;</li>
<li> keywords (in, var);</li>
<li> creating a new automatic variable, whose name does not have to intersect with the categories above, start with a digit and contain operations symbols.</li></ul></li>
<li> begins with a point:
<ul><li> element of the path to the property and function of the object, whose name should not begin with a digit and contain operations symbols.</li></ul></li></ul>
<p>Calling an external function, like the global attribute of the DAQ parameter, is written as an address to <a href="../User_API.html" title="Special:MyLanguage/Documents/User API">the node of the object model OpenSCADA</a>: "DAQ.JavaLikeCalc.lib_techApp.klapNotLin". For static functions you are allowed to the dynamic linking also in the following way:
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="kd">function</span> <span class="nx">klapNotLin</span> <span class="o">=</span> <span class="s2">"DAQ.JavaLikeCalc.lib_techApp.klapNotLin"</span><span class="p">;</span>
<span class="nx">rez</span> <span class="o">=</span> <span class="nx">klapNotLin</span><span class="p">(</span><span class="nx">prm1</span><span class="p">,</span> <span class="nx">prm2</span><span class="p">,</span> <span class="p">...,</span> <span class="nx">prmN</span><span class="p">);</span>
</pre></div>
<p>To provide the writing of custom control procedures for various components of OpenSCADA, this module provides the implementation of the precompiling API of custom procedures for individual components of OpenSCADA in the Java-like language. These components for example are: templates of the parameters of <a href="../Program_manual.html#DAQ" title="Special:MyLanguage/Documents/Program manual">the subsystem "Data acquisition"</a> and <a href="../Modules/VCAEngine.html" title="Special:MyLanguage/Modules/VCAEngine">the visual control area (VCA)</a>.
</p>
<div class="toc" id="toc"><div id="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#The_Java-like_language"><span class="tocnumber">1</span> <span class="toctext">The Java-like language</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Elements_of_the_language"><span class="tocnumber">1.1</span> <span class="toctext">Elements of the language</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#Operations_of_the_language"><span class="tocnumber">1.2</span> <span class="toctext">Operations of the language</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#Embedded_functions_of_the_language"><span class="tocnumber">1.3</span> <span class="toctext">Embedded functions of the language</span></a></li>
<li class="toclevel-2 tocsection-5"><a href="#Operators_of_the_language"><span class="tocnumber">1.4</span> <span class="toctext">Operators of the language</span></a>
<ul>
<li class="toclevel-3 tocsection-6"><a href="#Conditional_operators"><span class="tocnumber">1.4.1</span> <span class="toctext">Conditional operators</span></a></li>
<li class="toclevel-3 tocsection-7"><a href="#Loops"><span class="tocnumber">1.4.2</span> <span class="toctext">Loops</span></a></li>
<li class="toclevel-3 tocsection-8"><a href="#Internal_functions"><span class="tocnumber">1.4.3</span> <span class="toctext">Internal functions</span></a></li>
<li class="toclevel-3 tocsection-9"><a href="#Special_characters_of_the_string_variables"><span class="tocnumber">1.4.4</span> <span class="toctext">Special characters of the string variables</span></a></li>
</ul>
</li>
<li class="toclevel-2 tocsection-10"><a href="#Object"><span class="tocnumber">1.5</span> <span class="toctext">Object</span></a></li>
<li class="toclevel-2 tocsection-11"><a href="#Examples_of_programs_on_this_language"><span class="tocnumber">1.6</span> <span class="toctext"><span>Examples of programs on this language</span></span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-12"><a href="#Controller_object_and_its_configuration"><span class="tocnumber">2</span> <span class="toctext"><span>Controller object and its configuration</span></span></a></li>
<li class="toclevel-1 tocsection-13"><a href="#Parameter_of_the_controller_object_and_its_configuration"><span class="tocnumber">3</span> <span class="toctext">Parameter of the controller object and its configuration</span></a></li>
<li class="toclevel-1 tocsection-14"><a href="#Libraries_of_functions_of_the_module"><span class="tocnumber">4</span> <span class="toctext"><span>Libraries of functions of the module</span></span></a></li>
<li class="toclevel-1 tocsection-15"><a href="#User_functions_of_the_module"><span class="tocnumber">5</span> <span class="toctext">User functions of the module</span></a></li>
<li class="toclevel-1 tocsection-16"><a href="#User_programming_API"><span class="tocnumber">6</span> <span class="toctext">User programming API</span></a></li>
<li class="toclevel-1 tocsection-17"><a href="#Service_commands-functions_of_the_Control_Interface"><span class="tocnumber">7</span> <span class="toctext">Service commands-functions of the Control Interface</span></a></li>
<li class="toclevel-1 tocsection-18"><a href="#Productivity"><span class="tocnumber">8</span> <span class="toctext"><span>Productivity</span></span></a></li>
<li class="toclevel-1 tocsection-19"><a href="#Links"><span class="tocnumber">9</span> <span class="toctext">Links</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="The_Java-like_language"><span class="mw-headline-number">1</span> The Java-like language</span></h2>
<h3><span class="mw-headline" id="Elements_of_the_language"><span class="mw-headline-number">1.1</span> Elements of the language</span></h3>
<p><i>Keywords:</i> <b>if</b>, <b>else</b>, <b>while</b>, <b>for</b>, <b>in</b>, <b>break</b>, <b>continue</b>, <b>return</b>, <b>function</b>, <b>using</b>.<br />
<i>Constants:</i>
</p>
<ul><li> decimal: digits <b>0-9</b> (12, 111, 678);</li>
<li> octal: digits <b>0-7</b> (012, 011, 076);</li>
<li> hexadecimal: digits <b>0-9</b>, letters <b>a-f</b> or <b>A-F</b> (0x12, 0XAB);</li>
<li> real: <b>345.23</b>, <b>2.1e5</b>, <b>3.4E-5</b>, <b>3e6</b>;</li>
<li> boolean: <b>true</b>, <b>false</b>;</li>
<li> string: <b>"hello"</b>, without going to the next line, however, with the support of direct concatenation of the string constants.</li></ul>
<p><i>Types of variables:</i>
</p>
<ul><li> integer: <b>-2<sup>63</sup></b> ... <b>2<sup>63</sup></b>, <b>EVAL_INT</b>(-9223372036854775807);</li>
<li> real: <b>3.4*10<sup>308</sup></b>, <b>EVAL_REAL</b>(-1.79E308);</li>
<li> Boolean: <b>false</b>, <b>true</b>, <b>EVAL_BOOL</b>(2);</li>
<li> string: a sequence of character-bytes (0...255) of any length, limited by the capacity of the memory and DB storage; <b>EVAL_STR</b>("&lt;EVAL&gt;").</li></ul>
<p><i>Built-in constants:</i> <b>pi</b> = 3.14159265..., <b>e</b> = 2.71828182..., <b>EVAL_BOOL</b>(2), <b>EVAL_INT</b>(-9223372036854775807), <b>null</b>,<b>EVAL</b>,<b>EVAL_REAL</b>(-1.79E308), <b>EVAL_STR</b>("&lt;EVAL&gt;")<br />
<i>Global attributes of the DAQ parameter (starting from the subsystem "DAQ", as follows <b>{Type of DAQ module}.{Controller}.{Parameter}.{Attribute}</b>).</i><br />
<i>The functions and parameters of <a href="../User_API.html" title="Special:MyLanguage/Documents/User API">the object model of OpenSCADA</a>.</i>
</p><p><a class="image" href="http://oscada.org/wiki/File:At.png"><img alt="At.png" height="22" src="../files/At.png" width="22" /></a> The <b>EVAL</b> (Error VALue) variants and <b>null</b> are processed specially in conversion one to one depending on used the base type, that is you are free in use only <b>null</b> or <b>EVAL</b> for any cases.
</p>
<h3><span class="mw-headline" id="Operations_of_the_language"><span class="mw-headline-number">1.2</span> Operations of the language</span></h3>
<p>The operations supported by the language are presented in the table below. Priority of the operations is reduced from top to bottom. Operations with the same priority are in the same color group.
</p>
<table bgcolor="#FFFFF0" border="1" cellspacing="0">
<tr align="center" bgcolor="#83D8FF"><td><b>Symbol</b></td><td><b>Description</b></td></tr>
<tr bgcolor="#FFFFC0"><td>()</td><td>Call of function.</td></tr>
<tr><td>{}</td><td>Program blocks.</td></tr>
<tr><td>++</td><td>Increment (post and pre).</td></tr>
<tr><td>--</td><td>Decrement (post and pre).</td></tr>
<tr bgcolor="#FFFFC0"><td>-</td><td>Unary minus.</td></tr>
<tr bgcolor="#FFFFC0"><td>!</td><td>Logical negation.</td></tr>
<tr bgcolor="#FFFFC0"><td>~</td><td>Bitwise negation.</td></tr>
<tr><td>*</td><td>Multiplication.</td></tr>
<tr><td>/</td><td>Division.</td></tr>
<tr><td>%</td><td>Remainder of integer division.</td></tr>
<tr bgcolor="#FFFFC0"><td>+</td><td>Addition</td></tr>
<tr bgcolor="#FFFFC0"><td>-</td><td>Subtraction</td></tr>
<tr><td>&lt;&lt;</td><td>Bitwise shift left</td></tr>
<tr><td>&gt;&gt;</td><td>Bitwise shift right</td></tr>
<tr bgcolor="#FFFFC0"><td>&gt;</td><td>Greater</td></tr>
<tr bgcolor="#FFFFC0"><td>&gt;=</td><td>Greater than or equal to</td></tr>
<tr bgcolor="#FFFFC0"><td>&lt;</td><td>Less</td></tr>
<tr bgcolor="#FFFFC0"><td>&lt;=</td><td>Less than or equal to</td></tr>
<tr bgcolor="#FFFFC0"><td>==</td><td>Equals</td></tr>
<tr bgcolor="#FFFFC0"><td>!=</td><td>Unequal</td></tr>
<tr><td>|</td><td>Bitwise "OR"</td></tr>
<tr><td>&amp;</td><td>Bitwise "AND"</td></tr>
<tr><td>^</td><td>Bitwise "Exclusive OR"</td></tr>
<tr bgcolor="#FFFFC0"><td>&amp;&amp;</td><td>Boolean "AND"</td></tr>
<tr bgcolor="#FFFFC0"><td>||</td><td>Boolean "OR"</td></tr>
<tr><td>?:</td><td>Conditional operation "i=(i&lt;0)?0:i;"</td></tr>
<tr bgcolor="#FFFFC0"><td>=</td><td>Assignment.</td></tr>
<tr bgcolor="#FFFFC0"><td>+=</td><td>Assignment with addition.</td></tr>
<tr bgcolor="#FFFFC0"><td>-=</td><td>Assignment with subtraction.</td></tr>
<tr bgcolor="#FFFFC0"><td>*=</td><td>Assignment with multiplication.</td></tr>
<tr bgcolor="#FFFFC0"><td>/=</td><td>Assignment with division.</td></tr>
</table>
<h3><span class="mw-headline" id="Embedded_functions_of_the_language"><span class="mw-headline-number">1.3</span> Embedded functions of the language</span></h3>
<p>The virtual machine of the language provides the following set of built-in functions general-purpose:
</p>
<ul><li> <i>double max(double x, double x1)</i> — maximum value of <i>x</i> and <i>x1</i>;</li>
<li> <i>double min(double x, double x1)</i> — minimum value of <i>x</i> and <i>x1</i>;</li>
<li> <i>string typeof(ElTp vl)</i> — type of the value <i>vl</i>;</li>
<li> <i>string tr(string base)</i> — translation to the <i>base</i> message.</li></ul>
<p>To provide high speed work in mathematical calculations, the module provides built-in mathematical functions that are called at the level of the commands of the virtual machine:
</p>
<ul><li> <i>double sin(double x)</i> — sine <i>x</i>;</li>
<li> <i>double cos(double x)</i> — cosine <i>x</i>;</li>
<li> <i>double tan(double x)</i> — tangent <i>x</i>;</li>
<li> <i>double sinh(double x)</i> — hyperbolic sine of <i>x</i>;</li>
<li> <i>double cosh(double x)</i> — hyperbolic cosine of <i>x</i>;</li>
<li> <i>double tanh(double x)</i> — hyperbolic tangent of <i>x</i>;</li>
<li> <i>double asin(double x)</i> — arcsine of <i>x</i>;</li>
<li> <i>double acos(double x)</i> — arc cosine of <i>x</i>;</li>
<li> <i>double atan(double x)</i> — arctangent of <i>x</i>;</li>
<li> <i>double rand(double x)</i> — random number from 0 to <i>x</i>;</li>
<li> <i>double lg(double x)</i> — decimal logarithm of <i>x</i>;</li>
<li> <i>double ln(double x)</i> — natural logarithm of <i>x</i>;</li>
<li> <i>double exp(double x)</i> — exponent of <i>x</i>;</li>
<li> <i>double pow(double x, double x1)</i> — erection of x to the power <i>x1</i>;</li>
<li> <i>double sqrt(double x)</i> — the square root of <i>x</i>;</li>
<li> <i>double abs(double x)</i> — absolute value of <i>x</i>;</li>
<li> <i>double sign(double x)</i> — sign of <i>x</i>;</li>
<li> <i>double ceil(double x)</i> — rounding the number <i>x</i> to a greater integer;</li>
<li> <i>double floor(double x)</i> — rounding the number <i>x</i> to a smaller integer.</li></ul>
<h3><span class="mw-headline" id="Operators_of_the_language"><span class="mw-headline-number">1.4</span> Operators of the language</span></h3>
<p>The total list of the operators of the language:
</p>
<ul><li> <i>var</i> — operator of initialization of a variable; specifying a variable without assigning a value sets it to <b>null</b>-<b>EVAL</b>, which allows for one-time initialization of complex data types, such as an object, through the direct comparing and checking by <i>isEVal()</i>;</li>
<li> <i>if</i> — operator "IF" of the condition;</li>
<li> <i>else</i> — operator "ELSE" of the condition;</li>
<li> <i>while</i> — definition of the "WHILE" loop;</li>
<li> <i>for</i> — definition of the "FOR" loop;</li>
<li> <i>in</i> — separator of the "FOR" cycle for object's properties scan;</li>
<li> <i>break</i> — interruption of the cycle;</li>
<li> <i>continue</i> — continue the cycle from the beginning;</li>
<li> <i>function</i> — definition of the internal function;</li>
<li> <i>using</i> — allows you to set the visibility space of the external functions of the often used libraries (<b>using Special.FLibSYS;</b>) for the next access only by the name of the function, has no effect for object access;</li>
<li> <i>return</i> — interrupt function and return the result that is copied to an attribute marked as return one (<b>return 123;</b>); in the middle of the internal function it is completed with a definite result;</li>
<li> <i>new</i> — creating an object, implemented for: the generic object "Object", massif "Array" and regular expressions "RegExp".</li>
<li> <i>delete</i> — delete/free of an object or its properties, while: internal variables are set in <b>null</b>-<b>EVAL</b>, external ones are replaced by an empty object, and the properties of the object are cleared.</li></ul>
<h4><span class="mw-headline" id="Conditional_operators"><span class="mw-headline-number">1.4.1</span> Conditional operators</span></h4>
<p>The language supports two types of conditions. First — this is the operation of condition for use within the expression, second — a global, based on the conditional operators.
</p><p>The condition inside an expression is based on the operations '?' and ':'. As an example we'll write the following practical expression:
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="nx">st_open</span> <span class="o">=</span> <span class="p">(</span><span class="nx">pos</span> <span class="o">&gt;=</span> <span class="mi">100</span><span class="p">)</span> <span class="o">?</span> <span class="kc">true</span> <span class="o">:</span> <span class="kc">false</span><span class="p">;</span>
</pre></div>
<p>Which reads as — if the variable <i>pos</i> greater than or equal to <b>100</b>, the variable <i>st_open</i> is set to <b>true</b>, otherwise — to <b>false</b>.
</p><p>The global condition is based on the conditional operators "if" and "else". As an example, we can show the same expression, but recorded in another way:
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="k">if</span><span class="p">(</span><span class="nx">pos</span> <span class="o">&gt;</span> <span class="mi">100</span><span class="p">)</span> <span class="nx">st_open</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span> <span class="k">else</span> <span class="nx">st_open</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
</pre></div>
<h4><span class="mw-headline" id="Loops"><span class="mw-headline-number">1.4.2</span> Loops</span></h4>
<p>Two types of the loops are supported: <b>while</b>, <b>for</b> and <b>for-in</b>. The syntax of the loops corresponds to the programming languages: C++, Java and JavaScript.
</p><p>Loop <b>while</b> is written generally as follows: <b>while({condition}) {body of the loop};</b><br />
Loop <b>for</b> is written as follows: <b>for({pre-initialization};{condition};{post-calculation}) {body of the loop};</b><br />
Loop <b>for-in</b> is written as follows: <b>for({variable} in {object}) {body of the loop};</b><br />
Where:
</p>
<dl><dd><i>{condition}</i> — expression, determining the condition;</dd>
<dd><i>{body of the loop}</i> — the body of the loop of multiple execution;</dd>
<dd><i>{pre-initialization}</i> — expression of pre-initialization of variables of the loop;</dd>
<dd><i>{post-calculation}</i> — expression of modification of parameters of the loop after next iteration;</dd>
<dd><i>{variable}</i> — variable, which will contain object's properties name at scan;</dd>
<dd><i>{object}</i> — object for which the properties are scanned.</dd></dl>
<h4><span class="mw-headline" id="Internal_functions"><span class="mw-headline-number">1.4.3</span> Internal functions</span></h4>
<p>The language supports definition and call of internal functions. To determine the internal function, the keyword "function" is used and in general, the definition has a syntax: <b>function {fName} ({var1}, {var2}, ... {varN}) { {the function body} }</b>. Defining an internal function inside another is not allowed but it is allowed to call a previously defined one.
</p><p>Calling an internal function is done in a typical way as a procedure <b>{fName}({var1}, {var2}, ... {varN});</b> or as a function <b>{vRez} = {fName}({var1}, {var2}, ... {varN});</b>. The call of internal functions is valid only after their declaration is higher!
</p><p>All defined variables into the main body inaccessible into the internal function and can be pass in as two way arguments of the internal function call or as the main function arguments. 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 as two way arguments, return of the internal function call or the main function arguments. The internal function variables are registered for saving/restoring their context after second and more entry to the function, so they completely support the recursive calls!
</p><p>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.
</p><p>An example of the internal function declaration and using in typical way shown next:
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="kd">function</span> <span class="nx">sum</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span> <span class="nx">b</span><span class="p">,</span> <span class="nx">c</span><span class="p">,</span> <span class="nx">d</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">a</span> <span class="o">+</span> <span class="p">((</span><span class="nx">b</span><span class="o">==</span><span class="kc">null</span><span class="p">)</span><span class="o">?</span><span class="mi">0</span><span class="o">:</span><span class="nx">b</span><span class="p">)</span> <span class="o">+</span> <span class="p">((</span><span class="nx">c</span><span class="o">==</span><span class="kc">null</span><span class="p">)</span><span class="o">?</span><span class="mi">0</span><span class="o">:</span><span class="nx">c</span><span class="p">)</span> <span class="o">+</span> <span class="p">((</span><span class="nx">d</span><span class="o">==</span><span class="kc">null</span><span class="p">)</span><span class="o">?</span><span class="mi">0</span><span class="o">:</span><span class="nx">d</span><span class="p">);</span> <span class="p">}</span>
<span class="nx">rez</span> <span class="o">=</span> <span class="nx">sum</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
</pre></div>
<h4><span class="mw-headline" id="Special_characters_of_the_string_variables"><span class="mw-headline-number">1.4.4</span> Special characters of the string variables</span></h4>
<p>The language supports the following special characters of the string variables:
</p>
<dl><dd>"\n" — line feed;</dd>
<dd>"\t" — tabulation symbol;</dd>
<dd>"\b" — culling;</dd>
<dd>"\f" — page feed;</dd>
<dd>"\r" — carriage return;</dd>
<dd>"\\" — the character itself '\'.</dd>
<dd>"\041" — the '!' character, written in an octal number;</dd>
<dd>"\x21" — the '!' character, written in a hex number.</dd></dl>
<p><br />
</p>
<h3><span class="mw-headline" id="Object"><span class="mw-headline-number">1.5</span> Object</span></h3>
<p>JavaLikeCalc provides support of the data type "Object". The data type "Object" is an associated container of properties and functions. The properties can support data of fourth basic types and other objects. Access to object properties can be done through the record of property names to the object <i>obj.prop</i>, through a dot, and also through the inclusion of the property name in square brackets <i>obj["prop"]</i>. It is obvious that the first mechanism is static, while the second lets you to specify the name of the property through a variable. The name of the property through the dot must not start with a digit and contain operations symbols; otherwise, for the first digit, the <a href="../User_API.html" title="Special:MyLanguage/Documents/User API">object prefix</a> should be used — <b>SYS.BD.SQLite.db_1s</b>, or write in square brackets — <b>SYS.BD.SQLite["1+s"]</b>, for operations symbols in the name. Object's properties removing you can perform by the operator "delete". Reading of an undefined property will return <b>null</b>-<b>EVAL</b>. Creating an object is carried by the keyword <i>new</i>: <b>varO = new Object()</b>. 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 the count is set to zero then the object is removed physically.
</p><p>Different components of OpenSCADA can define the basic object with special properties and functions. The standard extension of the object is an array "Array", which is created by the command <b>varO = new Array(prm1,prm2,prm3,...,prmN)</b>. 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 <i>arr[1]</i> 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 the object properties. For more details about the properties and functions of the array can be read <a href="../User_API.html#Array" title="Special:MyLanguage/Documents/User API">here</a>.
</p><p>The object of regular expression "RegExp" is created by command <b>varO = new RegExp(pat, flg)</b>, where <i>pat</i> — pattern of the regular expression, and <i>flg</i> — 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 <a href="../User_API.html#RegExp" title="Special:MyLanguage/Documents/User API">here</a>.
</p><p>For random access to the function arguments 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 the function and allows you to access to a value of the argument by its <b>number</b> or <b>ID</b>. Consider the enumeration of the arguments on the cycle:
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="nx">args</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Array</span><span class="p">();</span>
<span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span>
  <span class="nx">args</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="nx">arguments</span><span class="p">[</span><span class="nx">i</span><span class="p">];</span>
</pre></div>
<p>The basic types have the partial properties of the object. Properties and functions of the basic types are listed below: 
</p>
<ul><li> NULL type, functions:
<ul><li> <i>bool isEVal();</i> — returns "true".</li></ul></li></ul>
<ul><li> Logical type, functions:
<ul><li> <i>bool isEVal(); bool isNaN( );</i> — checks the value to <b>null</b>-<b>EVAL</b>.</li>
<li> <i>string toString();</i> — performs the value as the string "true" or "false".</li></ul></li></ul>
<dl><dd><ul><li> <i>real toReal();</i> — reads this Boolean as a real number.</li>
<li> <i>int toInt();</i> — reads this Boolean as an integer number.</li></ul></dd></dl>
<ul><li> Integer and real number:</li></ul>
<dl><dd><dl><dt> <i>Properties:</i></dt></dl>
<ul><li> <i>MAX_VALUE</i> — maximum value; </li>
<li> <i>MIN_VALUE</i> — minimum value;</li>
<li> <i>NaN</i> —  error value.</li></ul>
<dl><dt> <i>Functions:</i></dt></dl>
<ul><li> <i>bool isEVal(); bool isNaN( );</i> — checks the value to <b>null</b>-<b>EVAL</b>, and NaN for Real.</li>
<li> <i>string toExponential( int numbs = -1 );</i> — returns the string of the number, formatted in the exponential notation, and with the number of significant digits <i>numbs</i>. If <i>numbs</i> is missing the number of digits will have as much as needed.</li>
<li> <i>string toFixed( int numbs = 0, int len = 0, bool sign = false );</i> — returns the string of the number, formatted in the notation of fixed-point, and with the number of significant digits after the decimal point <i>numbs</i>, for minimum length <i>len</i> and compulsion to the presence of a <i>sign</i>. If <i>numbs</i> is missing, the number of digits after the decimal point is equal to zero.</li>
<li> <i>string toPrecision( int prec = -1 );</i> — returns the string of the number, formatted with the number of significant digits <i>prec</i>.</li>
<li> <i>string toString( int base = 10, int len = -1, bool sign = false );</i> — returns the string of the number of the integer type, formatted with the following representation <i>base</i> (2-36), for minimum length <i>len</i> and compulsion to the presence of a <i>sign</i>.</li>
<li> <i>real toReal();</i> — reads this integer-real as a real number.</li>
<li> <i>int toInt();</i> — reads this integer-real as an integer number.</li></ul></dd></dl>
<ul><li> String: </li></ul>
<dl><dd><dl><dt> <i>Properties:</i></dt></dl>
<ul><li> <i>int length</i> — string length. </li></ul>
<dl><dt> <i>Functions:</i></dt></dl>
<ul><li> <i>bool isEVal();</i> — checks value to <b>null</b>-<b>EVAL</b>.</li>
<li> <i>bool isNaN( bool whole = true );</i> — checks the string to Not A Number and in whole for <i>whole</i>. </li>
<li> <i>string charAt( int symb, string type = "" );</i> — extracts from the string the symbol <i>symb</i> for the <i>type</i>. These types of the symbol are supported: ""-ASCII and raw one byte code, UTF-8, UTF-16, UTF-32. In the case of UTF-8, the symbol position <i>symb</i> is changed to the next symbol position due to length of this symbols type is variable one.</li>
<li> <i>int charCodeAt( int symb, string type = "" );</i> — extracts from the string the symbol code <i>symb</i> for the <i>type</i>. These types of the symbol are supported: ""-ASCII and raw one byte code, UTF-8, UTF-16, UTF-16LE, UTF-16BE, UTF-32, UTF-32LE, UTF-32BE. In the case of UTF-8, the symbol position <i>symb</i> is changed to the next symbol position due to length of this symbols type is variable one.</li>
<li> <i>string concat( string val1, string val2, ... );</i> — returns a new string formed by joining the values <i>val1</i> etc. to the original one.</li>
<li> <i>int indexOf( string substr, int start = 0 );</i> — returns the position of the required string <i>substr</i> in the original row from the position <i>start</i>. If the initial position is not specified then the search starts from the beginning. If the search string is not found then "-1" is returned.</li>
<li> <i>int lastIndexOf( string substr, int start = {end} );</i> — returns the position of the search string <i>substr</i> in the original one beginning from the position of <i>start</i> when searching from the end. If the initial position is not specified then the search begins from the end. If the search string is not found then "-1" is returned.</li>
<li> <i>int search( string pat, string flg = "" );</i> — searches into the string by the pattern <i>pat</i> and pattern's flags <i>flg</i>. Returns found substring position or "-1" for else.</li></ul></dd></dl>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 30pt"><pre><span class="kd">var</span> <span class="nx">rez</span> <span class="o">=</span> <span class="s2">"Java123Script"</span><span class="p">.</span><span class="nx">search</span><span class="p">(</span><span class="s2">"script"</span><span class="p">,</span><span class="s2">"i"</span><span class="p">);</span>  <span class="c1">// rez = 7</span>
</pre></div>
<dl><dd><ul><li> <i>int search( RegExp pat );</i> — searches into the string by the "RegExp" pattern <i>pat</i>. Returns found substring position or "-1" for else.</li></ul></dd></dl>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 30pt"><pre><span class="kd">var</span> <span class="nx">rez</span> <span class="o">=</span> <span class="s2">"Java123Script"</span><span class="p">.</span><span class="nx">search</span><span class="p">(</span><span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"script"</span><span class="p">,</span><span class="s2">"i"</span><span class="p">));</span>  <span class="c1">// rez = 7</span>
</pre></div>
<dl><dd><ul><li> <i>Array match( string pat, string flg = "" );</i> — calls match for the string by the pattern <i>pat</i> and flags <i>flg</i>. Returns matched substring (0) and subexpressions (&gt;0) array. Sets "index" attribute of the array to the substring position. Sets the "input" attribute to the source string. Sets the "err" attribute to the operation error code.</li></ul></dd></dl>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 30pt"><pre><span class="kd">var</span> <span class="nx">rez</span> <span class="o">=</span> <span class="s2">"1 plus 2 plus 3"</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="s2">"\\d+"</span><span class="p">,</span><span class="s2">"g"</span><span class="p">);</span>  <span class="c1">// rez = [1], [2], [3]</span>
</pre></div>
<dl><dd><ul><li> <i>Array match( TRegExp pat );</i> — calls match for the string and "RegExp" pattern <i>pat</i>. Returns matched substring (0) and subexpressions (&gt;0) array. Sets the "index" attribute of the array to substring position. Sets the "input" attribute to the source string. Sets the "err" attribute to the operation error code.</li></ul></dd></dl>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 30pt"><pre><span class="kd">var</span> <span class="nx">rez</span> <span class="o">=</span> <span class="s2">"1 plus 2 plus 3"</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"\\d+"</span><span class="p">,</span><span class="s2">"g"</span><span class="p">));</span>  <span class="c1">// rez = [1], [2], [3]</span>
</pre></div>
<dl><dd><ul><li> <i>string slice( int beg, int end ); string substring( int beg, int end );</i> — returns the string extracted from the original one starting from the <i>beg</i> position and ending before the <i>end</i> (not included), numbering from zero. If the begin or end is negative, then the count is conducted from the end of the line. If the end is not specified, then the end is the end of the line. For example, the construction <b>substring(-2)</b> return two last symbols of the string.</li>
<li> <i>Array split( string sep, int limit = 0 );</i> — returns the array of strings separated by <i>sep</i> with the <i>limit</i> of the number of elements (0 for no limit).</li>
<li> <i>Array split( RegExp pat, int limit = 0 );</i> — returns the array of strings separated by the RegExp pattern <i>pat</i> with the <i>limit</i> of the number of elements (0 for no limit).</li></ul></dd></dl>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 30pt"><pre><span class="nx">rez</span> <span class="o">=</span> <span class="s2">"1,2, 3 , 4 ,5"</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"\\s*,\\s*"</span><span class="p">));</span>  <span class="c1">// rez = [1], [2], [3], [4], [5]</span>
</pre></div>
<dl><dd><ul><li> <i>string insert( int pos, string substr );</i> — inserts the substring <i>substr</i> into this string's position <i>pos</i>.</li>
<li> <i>string replace( int pos, int n, string str );</i> — replaces substring into the position <i>pos</i> and length <i>n</i> to the string <i>str</i>.</li></ul></dd></dl>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 30pt"><pre><span class="nx">rez</span> <span class="o">=</span> <span class="s2">"Javascript"</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="s2">"67"</span><span class="p">);</span>  <span class="c1">// rez = "Java67ipt"</span>
</pre></div>
<dl><dd><ul><li> <i>string replace( string substr, string str );</i> — replaces all the substrings <i>substr</i> to the string <i>str</i>.</li></ul></dd></dl>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 30pt"><pre><span class="nx">rez</span> <span class="o">=</span> <span class="s2">"123 321"</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s2">"3"</span><span class="p">,</span><span class="s2">"55"</span><span class="p">);</span>  <span class="c1">// rez = "1255 5521"</span>
</pre></div>
<dl><dd><ul><li> <i>string replace( RegExp pat, string str );</i> — replaces substrings by the pattern <i>pat</i> to the string <i>str</i>.</li></ul></dd></dl>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 30pt"><pre><span class="nx">rez</span> <span class="o">=</span> <span class="s2">"value = \"123\""</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">"\"([^\"]*)\""</span><span class="p">,</span><span class="s2">"g"</span><span class="p">),</span><span class="s2">"``$1''"</span><span class="p">));</span>  <span class="c1">// rez = "value = ``123''"</span>
</pre></div>
<dl><dd><ul><li> <i>real toReal();</i> — converts this string to a real number.</li>
<li> <i>int toInt( int base = 0 );</i> — converts this string to an integer number in accordance with <i>base</i> (from 2 to 36). If the base is 0, then the prefix will be considered a prefix for determining the base (123-decimal; 0123-octal; 0x123-hex).</li>
<li> <i>string {parse,parseEnd}( int pos, string sep = ".", int off = {0,{length}}, bool mergeSepSymb = false );</i> — gets a token with the number <i>pos</i> from the string when separated by <i>sep</i> and from the offset <i>off</i> (stopping on the next token begin, end for <i>parseEnd</i>). <i>mergeSepSymb</i> specifies of allowing of merging of the group of identical symbols to one separator. Result offset is returned back to <i>off</i>. <i>parseEnd()</i> does the same but from the end.</li>
<li> <i>string parseLine( int pos, int off = 0 );</i> — gets a line with the number <i>pos</i> from the string and from the offset <i>off</i>. Result offset is returned back to <i>off</i> (stopping on the next token begin).</li>
<li> <i>string parsePath( int pos, int offCmptbl = 0, int off = 0 );</i> — gets a path token with the number <i>pos</i> from the string and from the offset <i>off</i> (stopping on the next token begin) or <i>offCmtbl</i> (stopping on next symbol of the current token end — for compatibility). Result offset is returned back to <i>off</i> or <i>offCmptbl</i>.</li>
<li> <i>string parsePathEnd( int pos, int off = {length} );</i> — gets a path token with the number <i>pos</i> from the string end and from the offset <i>off</i> (stopping on the next token end). Result offset is returned back to <i>off</i>.</li>
<li> <i>string path2sep( string sep = "." );</i> — converts path into this string to separated by <i>sep</i> string.</li>
<li> <i>string trim( string cfg = " \n\t\r" );</i> — trims the string at the begin and the end for the symbols <i>cfg</i>.</li></ul></dd></dl>
<p><br />
For access to <a href="../User_API.html" title="Special:MyLanguage/Documents/User API">the system objects(nodes) of OpenSCADA</a> 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 output transport is carried out as follows: <b>SYS.Transport.Sockets.out_testModBus.messIO(Special.FLibSYS.strEnc2Bin("15 01 00 00 00 06 01 03 00 00 00 05"));</b>.
</p>
<h3><span class="mw-headline" id="Examples_of_programs_on_this_language"><span class="mw-headline-number">1.6</span> <span id="Examples" title="#Examples">Examples of programs on this language</span></span></h3>
<p>Here are some examples of programs on the Java-like language:
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="c1">//Model of the course of the executive machinery of ball valve</span>
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="p">(</span><span class="nx">st_close</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">com</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="p">(</span><span class="nx">st_open</span> <span class="o">&amp;&amp;</span> <span class="nx">com</span><span class="p">))</span>
<span class="p">{</span>
  <span class="nx">tmp_up</span> <span class="o">=</span> <span class="p">(</span><span class="nx">pos</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&amp;&amp;</span><span class="nx">pos</span><span class="o">&lt;</span><span class="mi">100</span><span class="p">)</span> <span class="o">?</span> <span class="mi">0</span> <span class="o">:</span> <span class="p">(</span><span class="nx">tmp_up</span><span class="o">&gt;</span><span class="mi">0</span><span class="o">&amp;&amp;</span><span class="nx">lst_com</span><span class="o">==</span><span class="nx">com</span><span class="p">)</span> <span class="o">?</span> <span class="nx">tmp_up</span><span class="o">-</span><span class="mi">1</span><span class="o">/</span><span class="nx">frq</span> <span class="o">:</span> <span class="nx">t_up</span><span class="p">;</span>
  <span class="nx">pos</span> <span class="o">+=</span> <span class="p">(</span><span class="nx">tmp_up</span><span class="o">&gt;</span><span class="mi">0</span><span class="p">)</span> <span class="o">?</span> <span class="mi">0</span> <span class="o">:</span> <span class="p">(</span><span class="mi">100</span><span class="o">*</span><span class="p">(</span><span class="nx">com</span><span class="o">?</span><span class="mi">1</span><span class="o">:-</span><span class="mi">1</span><span class="p">))</span><span class="o">/</span><span class="p">(</span><span class="nx">t_full</span><span class="o">*</span><span class="nx">frq</span><span class="p">);</span>
  <span class="nx">pos</span> <span class="o">=</span> <span class="p">(</span><span class="nx">pos</span><span class="o">&gt;</span><span class="mi">100</span><span class="p">)</span> <span class="o">?</span> <span class="mi">100</span> <span class="o">:</span> <span class="p">(</span><span class="nx">pos</span><span class="o">&lt;</span><span class="mi">0</span><span class="p">)</span> <span class="o">?</span> <span class="mi">0</span> <span class="o">:</span> <span class="nx">pos</span><span class="p">;</span>
  <span class="nx">st_open</span> <span class="o">=</span> <span class="p">(</span><span class="nx">pos</span><span class="o">&gt;=</span><span class="mi">100</span><span class="p">)</span> <span class="o">?</span> <span class="kc">true</span> <span class="o">:</span> <span class="kc">false</span><span class="p">;</span>
  <span class="nx">st_close</span> <span class="o">=</span> <span class="p">(</span><span class="nx">pos</span><span class="o">&lt;=</span><span class="mi">0</span><span class="p">)</span> <span class="o">?</span> <span class="kc">true</span> <span class="o">:</span> <span class="kc">false</span><span class="p">;</span>
  <span class="nx">lst_com</span> <span class="o">=</span> <span class="nx">com</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="c1">//Valve model</span>
<span class="nx">Qr</span> <span class="o">=</span> <span class="nx">Q0</span> <span class="o">+</span> <span class="nx">Q0</span><span class="o">*</span><span class="nx">Kpr</span><span class="o">*</span><span class="p">(</span><span class="nx">Pi</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mf">0.01</span><span class="p">;</span>
<span class="nx">Sr</span> <span class="o">=</span> <span class="p">(</span><span class="nx">S_kl1</span><span class="o">*</span><span class="nx">l_kl1</span><span class="o">+</span><span class="nx">S_kl2</span><span class="o">*</span><span class="nx">l_kl2</span><span class="p">)</span><span class="o">/</span><span class="mi">100</span><span class="p">;</span>
<span class="nx">Ftmp</span> <span class="o">=</span> <span class="p">(</span><span class="nx">Pi</span><span class="o">&gt;</span><span class="mi">2</span><span class="o">*</span><span class="nx">Po</span><span class="p">)</span> <span class="o">?</span> <span class="nx">Pi</span><span class="o">*</span><span class="nx">pow</span><span class="p">(</span><span class="nx">Q0</span><span class="o">*</span><span class="mf">0.75</span><span class="o">/</span><span class="nx">Ti</span><span class="p">,</span><span class="mf">0.5</span><span class="p">)</span> <span class="o">:</span> <span class="p">(</span><span class="nx">Po</span><span class="o">&gt;</span><span class="mi">2</span><span class="o">*</span><span class="nx">Pi</span><span class="p">)</span> <span class="o">?</span> <span class="nx">Po</span><span class="o">*</span><span class="nx">pow</span><span class="p">(</span><span class="nx">Q0</span><span class="o">*</span><span class="mf">0.75</span><span class="o">/</span><span class="nx">To</span><span class="p">,</span><span class="mf">0.5</span><span class="p">)</span> <span class="o">:</span> <span class="nx">pow</span><span class="p">(</span><span class="nx">abs</span><span class="p">(</span><span class="nx">Q0</span><span class="o">*</span><span class="p">(</span><span class="nx">pow</span><span class="p">(</span><span class="nx">Pi</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="o">-</span><span class="nx">pow</span><span class="p">(</span><span class="nx">Po</span><span class="p">,</span><span class="mi">2</span><span class="p">))</span><span class="o">/</span><span class="nx">Ti</span><span class="p">),</span><span class="mf">0.5</span><span class="p">);</span>
<span class="nx">Fi</span> <span class="o">-=</span> <span class="p">(</span><span class="nx">Fi</span><span class="o">-</span><span class="mi">7260</span><span class="o">*</span><span class="nx">Sr</span><span class="o">*</span><span class="nx">sign</span><span class="p">(</span><span class="nx">Pi</span><span class="o">-</span><span class="nx">Po</span><span class="p">)</span><span class="o">*</span><span class="nx">Ftmp</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mf">0.01</span><span class="o">*</span><span class="nx">lo</span><span class="o">*</span><span class="nx">frq</span><span class="p">);</span>
<span class="nx">Po</span> <span class="o">+=</span> <span class="mf">0.27</span><span class="o">*</span><span class="p">(</span><span class="nx">Fi</span><span class="o">-</span><span class="nx">Fo</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="nx">So</span><span class="o">*</span><span class="nx">lo</span><span class="o">*</span><span class="nx">Q0</span><span class="o">*</span><span class="nx">frq</span><span class="p">);</span>
<span class="nx">Po</span> <span class="o">=</span> <span class="p">(</span><span class="nx">Po</span><span class="o">&lt;</span><span class="mi">0</span><span class="p">)</span> <span class="o">?</span> <span class="mi">0</span> <span class="o">:</span> <span class="p">(</span><span class="nx">Po</span><span class="o">&gt;</span><span class="mi">100</span><span class="p">)</span> <span class="o">?</span> <span class="mi">100</span> <span class="o">:</span> <span class="nx">Po</span><span class="p">;</span>
<span class="nx">To</span> <span class="o">+=</span> <span class="p">(</span><span class="nx">abs</span><span class="p">(</span><span class="nx">Fi</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="nx">Ti</span><span class="o">*</span><span class="nx">pow</span><span class="p">(</span><span class="nx">Po</span><span class="o">/</span><span class="nx">Pi</span><span class="p">,</span><span class="mf">0.02</span><span class="p">)</span><span class="o">-</span><span class="nx">To</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="nx">Fwind</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="nx">Twind</span><span class="o">-</span><span class="nx">To</span><span class="p">)</span><span class="o">/</span><span class="nx">Riz</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="nx">Ct</span><span class="o">*</span><span class="nx">So</span><span class="o">*</span><span class="nx">lo</span><span class="o">*</span><span class="nx">Qr</span><span class="o">*</span><span class="nx">frq</span><span class="p">);</span>
</pre></div>
<h2><span class="mw-headline" id="Controller_object_and_its_configuration"><span class="mw-headline-number">2</span> <span id="Controller" title="#Controller">Controller object and its configuration</span></span></h2>
<p>The controller object of the module, to provide immediate calculations, connects with the functions of libraries, built with his help, or with <a href="../DAQ.html#LogicLev" title="Special:MyLanguage/Documents/DAQ">the data acquisition template</a>. In the case of a data acquisition template, the possibility of external linking with other parameters and attributes of the subsystem "Data Collection" is added. In order to provide calculated data in OpenSCADA, parameters can be created in the controller object. Example of the configuration tab of the controller object of the given type shown in Figure 2.
</p>
<div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:776px;"><a class="image" href="http://oscada.org/wiki/File:JavaLikeCalc_cntr.png"><img class="thumbimage" height="691" src="../files/JavaLikeCalc_cntr.png" width="774" /></a>  <div class="thumbcaption">Fig.2. Configuration tab of the controller object.</div></div></div></div>
<p>From this tab you can set:
</p>
<ul><li> State of the controller object, as follows: status, "Enabled", "Running" and the storage name containing the configuration.</li>
<li> Identifier, name and description of the controller.</li>
<li> The state "Enabled" and "Running", in which the controller object must be translated at start up.</li>
<li> Address of the computational function or <a href="../Program_manual.html#DAQTmpl" title="Special:MyLanguage/Documents/Program manual">the data acquisition template</a>.</li>
<li> Policy of scheduling, priority of the data acquisition task and number of iterations in one cycle of calculation task.</li></ul>
<p>Tab "Calculation" of the controller object (Fig. 3) contains parameters and a text of the program, are directly performed by the controller. Also, for monitoring of the execution, the time of calculating of the program is shown. The module provides processing a number of special options available in the controller program:
</p>
<ul><li> <i>f_frq</i> — calculation frequency of the controller program, read-only.</li>
<li> <i>f_start</i> — first calculation of the controller program — starting, read-only.</li>
<li> <i>f_stop</i> — last calculation of the controller program — stopping, read-only.</li>
<li> <i>this</i> — the controller object.</li></ul>
<div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:838px;"><a class="image" href="http://oscada.org/wiki/File:JavaLikeCalc_cntr_calc.png"><img class="thumbimage" height="661" src="../files/JavaLikeCalc_cntr_calc.png" width="836" /></a>  <div class="thumbcaption">Fig.3. Tab "Calculation" of the controller object.</div></div></div></div>
<h2><span class="mw-headline" id="Parameter_of_the_controller_object_and_its_configuration"><span class="mw-headline-number">3</span> Parameter of the controller object and its configuration</span></h2>
<p>The module provides only one the "Standard (std)" type of the parameters with the parameters table name "JavaLikePrm_{CntrId}".
</p><p>Parameter of the controller object of the module performs the function of providing the access to the results of computation of the controller to OpenSCADA by attributes if the parameters. From the specific fields, the configuration tab of the parameter of the controller object contains only the field for listing the parameters of the computational function that must be reflected.
</p>
<h2><span class="mw-headline" id="Libraries_of_functions_of_the_module"><span class="mw-headline-number">4</span> <span id="FuncsLibs" title="#FuncsLibs">Libraries of functions of the module</span></span></h2>
<p>The module provides a mechanism to create libraries of user's functions on the Java-like language. Example of the configuration tab of the library is shown in Figure 4. The tab contains the basic fields: accessing, address of the DB table (with tracking the availability of the data in different storages and providing the sequentially removing duplicates), date and time of modification, identifier, name and description.
</p>
<dl><dd> <a class="image" href="http://oscada.org/wiki/File:At.png"><img alt="At.png" height="22" src="../files/At.png" width="22" /></a> The object still supports of specifying the spare storage addresses with tables before you rename the table in the standard form "<b>flb_{ObjID}</b>".</dd></dl>
<div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:761px;"><a class="image" href="http://oscada.org/wiki/File:JavaLikeCalc_lib.png"><img class="thumbimage" height="509" src="../files/JavaLikeCalc_lib.png" width="759" /></a>  <div class="thumbcaption">Fig.4. Tab of the configuration of the library.</div></div></div></div>
<h2><span class="mw-headline" id="User_functions_of_the_module"><span class="mw-headline-number">5</span> User functions of the module</span></h2>
<p>Function, as well as the library, contains the basic configuration tab, the tab of the formation of the program and the parameters of the function (Fig. 1), as well as the performance tab of the created function.
</p>
<h2><span class="mw-headline" id="User_programming_API"><span class="mw-headline-number">6</span> User programming API</span></h2>
<p>Some objects of the module provides functions for user's programming.
</p>
<div class="floatright"><a class="image" href="http://oscada.org/wiki/File:Oscada_UserOM_JavaLikeCalc.png" title="User object model of the module JavaLikeCalc."><img alt="User object model of the module JavaLikeCalc." height="214" src="../files/Oscada_UserOM_JavaLikeCalc.png" width="223" /></a></div>
<p><b>The object "Functions library" (SYS.DAQ.JavaLikeCalc["lib_Lfunc"])</b>
</p>
<ul><li> <i>ElTp {funcID}(ElTp prm1, ...)</i> — calls the function "funcID" of the library "Lfunc" with the parameters <i>prm{N}</i>. Returns result of the called function. The prefix "lib_" before the library identifier is required!</li></ul>
<p><b>The object "User function" ( SYS.DAQ.JavaLikeCalc["lib_Lfunc"]["func"] )</b>
</p>
<ul><li> <i>ElTp call(ElTp prm1, ...)</i> — calls the function "func" of the library "Lfunc" with the parameters <i>prm{N}</i>. Returns result of the called function. The prefix "lib_" before the library identifier is required!</li></ul>
<p><br />
</p>
<h2><span class="mw-headline" id="Service_commands-functions_of_the_Control_Interface"><span class="mw-headline-number">7</span> Service commands-functions of the Control Interface</span></h2>
<p>Service functions are an interface for accessing OpenSCADA from external systems through the <a href="../API.html#CntrNode" title="Special:MyLanguage/Documents/API">Control Interface</a>. This mechanism is the basis of all exchange within OpenSCADA, implemented through weak links and <a href="../Modules/SelfSystem.html" title="Special:MyLanguage/Modules/SelfSystem">OpenSCADA's own exchange protocol</a>.
</p><p><br />
<b><u>Getting for values of the function IO of the controller object</u></b><br />
REQ: <i>&lt;get path="/DAQ/JavaLikeCalc/<b>{CNTR}</b>/%2fserv%2ffncAttr" /&gt;</i>
</p>
<ul><li> <i>CNTR</i> — controller object.</li></ul>
<p>RESP: <i>&lt;get path="/DAQ/JavaLikeCalc/{CNTR}/%2fserv%2ffncAttr" rez="<b>0</b>"&gt;<b>{IOs}</b>&lt;/get&gt;</i>
</p>
<ul><li> <i>IOs</i> — IOs of the function execution context in the tags "a": <i>&lt;a id="<b>{ID}</b>"&gt;<b>{value}</b>&lt;/a&gt;</i>
<ul><li> <i>ID</i> — identifier of the IO;</li>
<li> <i>value</i> — value of the IO.</li></ul></li></ul>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 10pt"><pre><span class="nt">&lt;get</span> <span class="na">path=</span><span class="s">"/DAQ/JavaLikeCalc/testCalc/%2fserv%2ffncAttr"</span> <span class="na">rez=</span><span class="s">"0"</span> <span class="na">user=</span><span class="s">"roman"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"f_frq"</span><span class="nt">&gt;</span>0.1<span class="nt">&lt;/a&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"f_start"</span><span class="nt">&gt;</span>0<span class="nt">&lt;/a&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"f_stop"</span><span class="nt">&gt;</span>0<span class="nt">&lt;/a&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"this"</span><span class="nt">&gt;</span><span class="ni">&amp;lt;</span>TCntrNodeObj path="/sub_DAQ/mod_JavaLikeCalc/cntr_testCalc/"/<span class="ni">&amp;gt;</span><span class="nt">&lt;/a&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"offset"</span><span class="nt">&gt;</span>100<span class="nt">&lt;/a&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"out"</span><span class="nt">&gt;</span>50<span class="nt">&lt;/a&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"test"</span><span class="nt">&gt;</span>1<span class="nt">&lt;/a&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"rez"</span> <span class="nt">/&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"inFarg"</span><span class="nt">&gt;</span>3<span class="nt">&lt;/a&gt;</span>
<span class="nt">&lt;/get&gt;</span>
</pre></div>
<p><b><u>Setting for values of the function IO of the controller object</u></b><br />
REQ[<b>root-DAQ</b>]: <i>&lt;set path="/DAQ/JavaLikeCalc/<b>{CNTR}</b>/%2fserv%2ffncAttr"&gt;<b>{IOs}</b>&lt;/set&gt;</i>
</p>
<ul><li> <i>CNTR</i> — controller object;</li>
<li> <i>IOs</i> — IOs of the function execution context in the tags "a": <i>&lt;a id="<b>{ID}</b>"&gt;<b>{value}</b>&lt;/a&gt;</i>
<ul><li> <i>ID</i> — identifier of the IO;</li>
<li> <i>value</i> — value of the IO.</li></ul></li></ul>
<div class="mw-highlight mw-content-ltr" dir="ltr" style="margin-left: 10pt"><pre><span class="nt">&lt;set</span> <span class="na">path=</span><span class="s">"/DAQ/JavaLikeCalc/testCalc/%2fserv%2ffncAttr"</span><span class="nt">&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"out"</span><span class="nt">&gt;</span>50<span class="nt">&lt;/a&gt;</span>
  <span class="nt">&lt;a</span> <span class="na">id=</span><span class="s">"test"</span><span class="nt">&gt;</span>1<span class="nt">&lt;/a&gt;</span>
<span class="nt">&lt;/set&gt;</span>
</pre></div>
<p><br />
</p>
<h2><span class="mw-headline" id="Productivity"><span class="mw-headline-number">8</span> <span id="Productivity" title="#Productivity">Productivity</span></span></h2>
<p>Source text of the procedures on the language is compiled into a bytecode, which is then computed by the virtual machine. The bytecode 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 directly by the CPU. That is, the productivity of the bytecode execution approximately low by ten to the hardware productivity due to the overhead of the virtual machine commands, the distribution of multithreaded data access, the transparent casting of types and the lack of strict typing, as well as the dynamic nature of the language and the presence of complex types "String" and "Object ".
</p><p><b>28.01.2006:</b><br />
<i>Description:</i> Initial estimation of the productivity of the OpenSCADA virtual machine in example of the expression <b>y=x1+x2</b>, where all the variables are global and in the float-point type.
</p>
<table class="wikitable">

<tr>
<th> Stage </th>
<th> Action </th>
<th> K7_1G-0, us
</th></tr>
<tr>
<td> 1 </td>
<td> The registers list initialization </td>
<td> 2.3
</td></tr>
<tr>
<td> 2 </td>
<td> Entry to the function exec() </td>
<td> 3
</td></tr>
<tr>
<td> 3 </td>
<td> The commands coming </td>
<td> 4.4
</td></tr>
<tr>
<td> 4 </td>
<td> Reading </td>
<td> 9
</td></tr>
<tr>
<td> 5 </td>
<td> Full time </td>
<td> 10.2
</td></tr></table>
<p><b>17.07.2013:</b><br />
<i>Description:</i> Justification of the current performance evaluation and optimization. The measurements were made by sampling the minimum time from five calls to 1000 executions of the formula <b>a -= b*(a-c)</b> and its abbreviations in each call. All the variables are global and in the float-point type.
</p>
<table class="wikitable">

<tr>
<th> Formula </th>
<th> Time on AMDGeode-500 (the operation time), us </th>
<th> Notes
</th></tr>
<tr>
<td> a -= b*(a-c) </td>
<td> 4.52 (0.74) </td>
<td>
</td></tr>
<tr>
<td> a -= b*c </td>
<td> 3.78 (0.72) </td>
<td>
</td></tr>
<tr>
<td> a -= b </td>
<td> 3.06 (0.56)
<dl><dd>=&gt; full call: 3.06 (0.49): getValR() = 0.49/2 = 0.245</dd>
<dd>=&gt; only write const = 2.57 (0.17)</dd>
<dd>=&gt; pass.code = 2.4</dd></dl>
</td>
<td>
</td></tr>
<tr>
<td> a = b </td>
<td> 2.5 (1.21)
<dl><dd>!&gt; using the unified TVariant function setVal() and getVal() = 7.6 (2.7 write only) =&gt; fix to 5.0 for prevent default setting to the string EVAL.</dd>
<dd>=&gt; full call: 2.5 (0.33)</dd>
<dd>=&gt; only write const: 2.17 (0.47)</dd>
<dd>=&gt; only check for type: 1.7 (0.3)</dd>
<dd>=&gt; pass code: 1.4 (0.11)</dd></dl>
</td>
<td> Writing to the function IO is longer then reading from the local register for other context call and additional checking for NAN and real modification.
</td></tr>
<tr>
<td> Empty </td>
<td> 1.29 </td>
<td> the infrastructure and measurement method utilization time.
</td></tr></table>
<p><b>24.04.2016:</b><br />
<i>Reason:</i> Estimate performance of accessing to the low level IO lines on Raspberry Pi GPIO in different ways of the JavaLikeCalc language of OpenSCADA.<br />
<i>Conditions:</i> <a class="external" href="http://oscada.org/wiki/Special:MyLanguage/Using/Raspberry_Pi" title="Special:MyLanguage/Using/Raspberry Pi">Raspberry Pi 3</a>, GPIO40, <a href="../Modules/GPIO.html" title="Special:MyLanguage/Modules/GPIO">DAQ.GPIO</a> (based on the library <a class="external text" href="http://www.airspayce.com/mikem/bcm2835" rel="nofollow noreferrer noopener" target="_blank">bcm2835</a>)
</p>
<table class="wikitable">

<tr>
<th> Operation </th>
<th> Result, us
</th></tr>
<tr>
<td colspan="2"> <i>Sleep. Lag on sleep in 1ms measuring, which mostly limited by the realtime reaction about 100us.</i>
</td></tr>
<tr>
<td> <b>SYS.sleep();</b> </td>
<td> +110
</td></tr>
<tr>
<td> <b>Special.FLibSYS.fnc_tmSleep();</b> </td>
<td> +70
</td></tr>
<tr>
<td colspan="2"> <i>Sleep. Lag on sleep in 100us measuring, which performs in the measuring cycle.</i>
</td></tr>
<tr>
<td> <b>SYS.sleep();</b> </td>
<td> +17
</td></tr>
<tr>
<td> <b>Special.FLibSYS.fnc_tmSleep();</b> </td>
<td> +2
</td></tr>
<tr>
<td colspan="2"> <i>Get a level of the GPIO pin</i>
</td></tr>
<tr>
<td> From an attribute <b>res = GPIO.io.pi.gpio17;</b> </td>
<td> 5.4
</td></tr>
<tr>
<td> By the static accessing function <b>res = DAQ.GPIO.io.pi.fnc_get(17);</b> </td>
<td> 1.6
</td></tr>
<tr>
<td> By the static accessing function with the link preparation <b>function get = "DAQ.GPIO.io.pi.fnc_get"; for(i = 0; i &lt; 10000; i++) res = get(17);</b> </td>
<td> 1.7
</td></tr>
<tr>
<td> By the dynamic accessing function <b>res = SYS.DAQ.GPIO.io.pi.fnc_get.call(17);</b> </td>
<td> 80
</td></tr>
<tr>
<td> By the dynamic accessing function with the end object preparation <b>tO = SYS.DAQ.GPIO.io.pi.fnc_get; for(i = 0; i &lt; 1000; i++) res = tO.call(17);</b> </td>
<td> 14.3
</td></tr>
<tr>
<td colspan="2"> <i>Put a level to the GPIO pin</i>
</td></tr>
<tr>
<td> To an attribute <b>GPIO.io.pi.gpio18 = true;</b> </td>
<td> 2.1
</td></tr>
<tr>
<td> By the static accessing function <b>DAQ.GPIO.io.pi.fnc_put(18, true);</b> </td>
<td> 1.4
</td></tr>
<tr>
<td> By the static accessing function with the link preparation <b>function put = "DAQ.GPIO.io.pi.fnc_put"; for(i = 0; i &lt; 10000; i++) put(17, false);</b> </td>
<td> 1.5
</td></tr>
<tr>
<td> By the dynamic accessing function <b>SYS.DAQ.GPIO.io.pi.fnc_put.call(18, true);</b> </td>
<td> 79
</td></tr>
<tr>
<td> By the dynamic accessing function with the end object preparation <b>tO = SYS.DAQ.GPIO.io.pi.fnc_put; for(i = 0; i &lt; 1000; i++) tO.call(18, true);</b> </td>
<td> 14.3
</td></tr></table>
<h2><span class="mw-headline" id="Links"><span class="mw-headline-number">9</span> Links</span></h2>
<ul><li> <a class="external" href="http://oscada.org/wiki/File:Oscada_UserOM_JavaLikeCalc.odg" title="File:Oscada UserOM JavaLikeCalc.odg">Diagram: User object model of the module JavaLikeCalc.</a></li></ul>






</div><table style="border-top: dotted 2px #999999; margin-top: 20pt; color: gray;" width="100%"><tr><td style="text-align: left;" width="40%"><a href="http://oscada.org/wiki/Modules/JavaLikeCalc/en">Modules/JavaLikeCalc/en</a> - <a href="http://oscada.org/en/main/about-the-project/licenses/">GFDL</a></td><td style="text-align: center;">April 2025</td><td style="text-align: right;" width="40%">OpenSCADA 1+r3018</td></tr></table></body>
</html>