<?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/UserProtocol - 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/UserProtocol</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/UserProtocol.html" title="Модули/Протокол пользователя (96% translated)">mRussian</a>&nbsp;• ‎<a class="mw-pt-progress mw-pt-progress--complete" href="../../uk/Modules/UserProtocol.html" title="Модулі/Протокол користувача (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/UserProtocol.html" title="Special:MyLanguage/Modules/UserProtocol">UserProtocol</a> </td>
<td> User protocol
</td>
<td> 1.6 </td>
<td> GPL2 </td>
<td> prot_UserProtocol.so </td>
<td> en,uk,ru,de </td>
<td> x86,x86_64,ARM
</td>
<td> Protocol </td>
<td> Roman Savochenko<br />&nbsp;&nbsp;<font size="-2"><i>Maxim Lysenko (2010) — the page initial translation</i></font> </td>
<td> Provides for creating your own user protocols on internal OpenSCADA language.
</td></tr></table>
<p>The module is designed to allow the user to create own implementations of different protocols in internal OpenSCADA language, usually <a href="../Modules/JavaLikeCalc.html" title="Special:MyLanguage/Modules/JavaLikeCalc">JavaLikeCalc</a>, without involving low level programming.
</p><p>The main purpose of the module is to simplify the task of connecting devices of data sources to OpenSCADA, that have limited distribution and/or provide access to their own data on a specific protocol that is usually fairly simple to implement in the internal language of OpenSCADA. For implementation of this the mechanism for the formation of the output request protocol is provided.
</p><p>In addition to the mechanism of the output request protocol the mechanism for input request protocol is provided, which allows OpenSCADA to process the requests for data get on specific protocols, which simply can be implemented in the internal language of OpenSCADA.
</p><p>The module provides the ability to create multiple implementations of different protocols in the object "User protocol" (Fig.1), and also use <a href="../Program_manual.html#DAQTmpl" title="Special:MyLanguage/Documents/Program manual">standard DAQ templates</a> for that. Using DAQ templates allows you to create complex protocols' libraries and call them in this module multiple times as their implementations, as well as provide the data context of the input template with their connection to the data of the subsystem "Data Acquisition".
</p>
<div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:705px;"><a class="image" href="http://oscada.org/wiki/File:UserProtocol_up_main.png"><img class="thumbimage" height="598" src="../files/UserProtocol_up_main.png" width="703" /></a>  <div class="thumbcaption">Fig.1. Main tab of an object of the module "User protocol".</div></div></div></div>
<p>The main tab contains the basic settings of the user protocol:
</p>
<ul><li> Section "State" — contains properties that characterize the state of the protocol: Status, "Enabled", the name of the database (containing the configuration and with tracking the availability of the data in different storages and providing the sequentially removing duplicates) and date of the last modification.</li>
<li> Identifier, name and description of the protocol.</li>
<li> The state "Enabled", in which the protocol must be translated at boot.</li>
<li> <a href="../Program_manual.html#DAQTmpl" title="Special:MyLanguage/Documents/Program manual">DAQ-template</a> related to the protocol. Selecting a template here turns off the mode by the direct procedures and access the following options. The DAQ-template mode can work in input, output or both of the requesting modes, related to the required attributes presence.</li>
<li> An indication of the complete translation of the procedures text and the language of the input and output procedures. Selecting a language for the input and/or output procedure will enable the appropriate part of the protocol and access the corresponding configuration tabs.</li></ul>
<div class="toc" id="toc"><div id="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Input_part_of_the_protocol"><span class="tocnumber">1</span> <span class="toctext">Input part of the protocol</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Output_part_of_the_protocol"><span class="tocnumber">2</span> <span class="toctext">Output part of the protocol</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Input_part_of_the_protocol"><span class="mw-headline-number">1</span> Input part of the protocol</span></h2>
<p>The input requests protocol is working in cooperation with the input transport and the separate object "User Protocol" is pointing in the configuration field of protocol of the transport, together with the UserProtocol module's name. Further, all transport requests will be directed to the direct procedure, or the template procedure, of the protocol request processing (Fig. 2).
</p>
<div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:863px;"><a class="image" href="http://oscada.org/wiki/File:UserProtocol_up_in.png"><img class="thumbimage" height="685" src="../files/UserProtocol_up_in.png" width="861" /></a>  <div class="thumbcaption">Fig.2. Tab of the configuration and the controlling for the input requests.</div></div></div></div>
<p>Tab of the configuration and the controlling of the input requests contains:
</p>
<ul><li> Timeout of a request waiting, in milliseconds. Used to enable the pooling mode, setting to a nonzero value. In the pooling mode, the incoming transport will call the protocol with the empty request, in the absence of a request within the specified time.</li>
<li> Table of data context for the input request procedure. Preferably, it makes sense only when working on a template and where you can control this processing, including the possibility of intruding through the data values changing.</li>
<li> The text of the direct procedure of the protocol, missed in the mode of work on the template.</li>
<li> Links to the data of the "Data Acquisition" subsystem, which are visible and available for determination in the mode of work on the template and in the state "Enabled" of the protocol object.</li></ul>
<p>For the direct processing procedure, and the required or optional ones to create in the template, the following exchange attributes with the input transport are predetermined:
</p>
<ul><li> <i><b>Input result (rez)</b></i> &lt;Boolean&gt; — processing result (false — full request; true — not full one, holding the connection); in the DAQ-template mode you must write thither directly, not by the operator "return";</li>
<li> <i><b>Input request (request)</b></i> &lt;String&gt; — full-accumulated request message, what protocol should clear about processed data;</li>
<li> <i><b>Input answer (answer)</b></i> &lt;String&gt; — answer message;</li>
<li> <i>Input sender (sender)</i> &lt;String&gt; — request sender;</li>
<li> <i>Transport (tr)</i> &lt;Object&gt; — input transport object;</li>
<li> <i>This object (this)</i> &lt;Object&gt; — pointer to this protocol's object;</li>
<li> <i>Scheduling the next service call (schedCall)</i> &lt;Integer&gt; — write here the time value in seconds for scheduling the procedure context execution in a service call; <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 service calls are performed in the periodicity 10 seconds usually, so you can schedule the calls not often than at 10 seconds.</li></ul>
<p>The overall scenario of the input requests processing:
</p>
<ul><li> Request is formed by the remote station and through the network it gets on <a href="../Program_manual.html#Communication" title="Special:MyLanguage/Documents/Program manual">the transport of OpenSCADA</a>.</li>
<li> OpenSCADA transport sends the request to this module, selected in the protocol's field, and to an object of the user protocol, in the form of the variable's "request" values — for the request sequence and "sender" — for the sender address of the request.</li>
<li> The execution of the procedure of the input request protocol is started, during which the contents of the variable "request" is analyzed and the response in the variable "answer" is formed. At the end of the procedure's execution the variable "rez" is formed, which indicates the transport to the fact of reception of full request and the formation of the correct answer (false) or to the necessity for the transport to expect for the remaining data (true) — holding the connection.</li>
<li> If the processing result is "false" and the answer is non-zero, the transport sends the response, and the protocol procedure itself must remove the processed part of the "request", because only it can determine the integrity of the package and the potential presence of it for the beginning of the next one.</li>
<li> If the result of the processing procedure is "true" then transport continues to wait for the data. When the next portion of the data is received, they are added to the "request" variable and the procedure is repeated.</li></ul>
<p>As an example, let's consider the implementation of DCON request processing for some requests to a data source with the address "10":
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="kd">var</span> <span class="nx">enCRC</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="c1">//SYS.messDebug("/DCON/in","REQ: "+request);</span>
<span class="c1">//Testing the request for completity</span>
<span class="k">if</span><span class="p">(</span><span class="nx">request</span><span class="p">.</span><span class="nx">length</span> <span class="o">&lt;</span> <span class="mi">4</span> <span class="o">||</span> <span class="nx">request</span><span class="p">[</span><span class="nx">request</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">"\r"</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">if</span><span class="p">(</span><span class="nx">request</span><span class="p">.</span><span class="nx">length</span> <span class="o">&gt;</span> <span class="mi">10</span><span class="p">)</span> <span class="nx">request</span> <span class="o">=</span> <span class="s2">""</span><span class="p">;</span>
  <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//Checking the request for the integrity (CRC) and the address</span>
<span class="k">if</span><span class="p">(</span><span class="nx">enCRC</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">CRC</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  <span class="k">for</span><span class="p">(</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="p">(</span><span class="nx">request</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">3</span><span class="p">);</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="nx">CRC</span> <span class="o">+=</span> <span class="nx">request</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">i</span><span class="p">);</span>
  <span class="k">if</span><span class="p">(</span><span class="nx">CRC</span> <span class="o">!=</span> <span class="nx">request</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">request</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span><span class="nx">request</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">).</span><span class="nx">toInt</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span> <span class="o">||</span> <span class="nx">request</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">).</span><span class="nx">toInt</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">10</span><span class="p">)</span> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//Analysis the request and the response preparing</span>
<span class="k">if</span><span class="p">(</span><span class="nx">request</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">"#"</span><span class="p">)</span> <span class="nx">answer</span> <span class="o">=</span> <span class="s2">"&gt;+05.123+04.153+07.234-02.356+10.000-05.133+02.345+08.234"</span><span class="p">;</span>
<span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">request</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">"@"</span><span class="p">)</span> <span class="nx">answer</span> <span class="o">=</span> <span class="s2">"&gt;AB3C"</span><span class="p">;</span>
<span class="k">else</span> <span class="nx">answer</span> <span class="o">=</span> <span class="s2">"?"</span><span class="p">;</span>
<span class="c1">//Finishing the response</span>
<span class="k">if</span><span class="p">(</span><span class="nx">enCRC</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">CRC</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  <span class="k">for</span><span class="p">(</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">answer</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">CRC</span> <span class="o">+=</span> <span class="nx">answer</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">i</span><span class="p">);</span>
  <span class="nx">answer</span> <span class="o">+=</span> <span class="p">(</span><span class="nx">CRC</span><span class="o">&amp;</span><span class="mh">0xFF</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span><span class="o">+</span><span class="s2">"\r"</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//SYS.messDebug("/DCON/in","ANSV: "+answer[0]);</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</pre></div>
<h2><span class="mw-headline" id="Output_part_of_the_protocol"><span class="mw-headline-number">2</span> Output part of the protocol</span></h2>
<p>The output requests protocol is working in cooperation with the output transport and with the separate object of the "User Protocol". The source of the request through the protocol may be <a href="../User_API.html#SYSTransport" title="Special:MyLanguage/Documents/User API">a function of the system-wide API of the user programming of the output transport</a> "<b>int messIO(XMLNodeObj req, string prt );</b>", in the parameters of which it must be specified:
</p>
<ul><li> <i>req</i> — request as an XML tree with the structure corresponding to the input format of the implemented protocol;</li>
<li> <i>prt</i> — name of this module — "UserProtocol".</li></ul>
<p>The request which is sent with the aforesaid way is directed to the direct procedure of the protocol's request processing (Fig. 3), or to the template procedure, with the user protocol's ID which is specified in the attribute <b>req.attr("ProtIt")</b>.
</p>
<div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:863px;"><a class="image" href="http://oscada.org/wiki/File:UserProtocol_up_out.png"><img class="thumbimage" height="685" src="../files/UserProtocol_up_out.png" width="861" /></a>  <div class="thumbcaption">Fig.3. Tab of a direct procedure of the output requests processing.</div></div></div></div>
<p>The processing procedure tab for output requests contains only text field of direct processing procedure for an internal programming language OpenSCADA, which are pointed in the previous tab. This tab is missing for the template mode.
</p><p>For the direct processing procedure, and the required or optional ones to create in the template, the following exchange attributes are predetermined:
</p>
<ul><li> <i><b>Output IO (io)</b></i> &lt;Object::XMLNode&gt; — XML node of the exchange with the client, through which the protocol gets the requests and into which it puts the result with the format implemented in the procedure;</li>
<li> <i><b>Transport (tr)</b></i> &lt;Object&gt; — the transport object, provided to call the transport function <i>string messIO( string mess, real timeOut = 1000 );</i> — <b>tr.messIO(req)</b>, is blocked during the procedure call.</li></ul>
<p>The overall scenario of the output request formation:
</p>
<ul><li> Building of the XML-tree in accordance with the structure, implemented by the protocol, and setting of the user protocol identifier in the attribute "ProtIt".</li>
<li> Sending the request to the transport through the protocol — "<b>SYS.Transport["{Modul}"]["out_{OutTransp}"].messIO(req, "UserProtocol");</b>".</li>
<li> Selection of the user protocol in accordance with <b>req.attr("ProtIt")</b> and initialization of variables of the output transport: <i>io</i> — respectively to the first argument <b>messIO()</b> and <i>tr</i> — object of the "OutTransp".</li>
<li> Calling the procedure for execution, which, after the processing the <i>io</i> structure, forms the direct request to the transport <i>tr.messIO(req);</i>, result of which is processed and put back to <i>io</i>.</li></ul>
<p>The meaning of separating the protocol part of a code into the procedure of a user protocol or template is to simplify and unify the client exchenge interface for multiple use and foresees the formation of an XML-node structure in the form of attributes of remote station addresses, addresses of read and written variables, as well as the values of the variables themselves. The entire work of direct coding of the request and decoding of the response is assigned to the user protocol procedure. If this is a one-time implementation, which in addition does not involve the implementation of the input part, it is easier to do it immediately in the original template to the data source, in the form of a built-in function.
</p><p>As an example, consider the implementation of the requests by the protocol DCON to the handler, implemented in the previous section. Let's start with the implementation of the protocol part:
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="c1">//Preparing the result request</span>
<span class="nx">request</span> <span class="o">=</span> <span class="nx">io</span><span class="p">.</span><span class="nx">name</span><span class="p">().</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nx">io</span><span class="p">.</span><span class="nx">attr</span><span class="p">(</span><span class="s2">"addr"</span><span class="p">).</span><span class="nx">toInt</span><span class="p">().</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nx">io</span><span class="p">.</span><span class="nx">text</span><span class="p">();</span>
<span class="k">if</span><span class="p">(</span><span class="nx">io</span><span class="p">.</span><span class="nx">attr</span><span class="p">(</span><span class="s2">"CRC"</span><span class="p">).</span><span class="nx">toInt</span><span class="p">())</span> <span class="p">{</span>
  <span class="nx">CRC</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  <span class="k">for</span><span class="p">(</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">request</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">CRC</span> <span class="o">+=</span> <span class="nx">request</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">i</span><span class="p">);</span>
    <span class="nx">request</span> <span class="o">+=</span> <span class="p">(</span><span class="nx">CRC</span><span class="o">&amp;</span><span class="mh">0xFF</span><span class="p">).</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="s2">"\r"</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span> <span class="nx">request</span> <span class="o">+=</span> <span class="s2">"\r"</span><span class="p">;</span>
<span class="c1">//Sending the request</span>
<span class="nx">resp</span> <span class="o">=</span> <span class="nx">tr</span><span class="p">.</span><span class="nx">messIO</span><span class="p">(</span><span class="nx">request</span><span class="p">);</span>
<span class="k">while</span><span class="p">(</span><span class="nx">resp</span><span class="p">[</span><span class="nx">resp</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">"\r"</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">tresp</span> <span class="o">=</span> <span class="nx">tr</span><span class="p">.</span><span class="nx">messIO</span><span class="p">(</span><span class="s2">""</span><span class="p">);</span>
  <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">tresp</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
  <span class="nx">resp</span> <span class="o">+=</span> <span class="nx">tresp</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//Analysis the response</span>
<span class="k">if</span><span class="p">(</span><span class="nx">io</span><span class="p">.</span><span class="nx">attr</span><span class="p">(</span><span class="s2">"CRC"</span><span class="p">).</span><span class="nx">toInt</span><span class="p">())</span> <span class="p">{</span>
  <span class="k">if</span><span class="p">(</span><span class="nx">resp</span><span class="p">.</span><span class="nx">length</span> <span class="o">&lt;</span> <span class="mi">4</span> <span class="o">||</span> <span class="nx">resp</span><span class="p">[</span><span class="nx">resp</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">"\r"</span><span class="p">)</span> <span class="p">{</span> <span class="nx">io</span><span class="p">.</span><span class="nx">setAttr</span><span class="p">(</span><span class="s2">"err"</span><span class="p">,</span><span class="s2">"10:"</span><span class="o">+</span><span class="nx">tr</span><span class="p">(</span><span class="s2">"Error or no response."</span><span class="p">));</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span>
  <span class="c1">//Checking the response to the integrity (CRC)</span>
  <span class="nx">CRC</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
  <span class="k">for</span><span class="p">(</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="p">(</span><span class="nx">resp</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">3</span><span class="p">);</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="nx">CRC</span> <span class="o">+=</span> <span class="nx">resp</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">i</span><span class="p">);</span>
    <span class="k">if</span><span class="p">(</span><span class="nx">CRC</span> <span class="o">!=</span> <span class="nx">resp</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">resp</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span><span class="nx">resp</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">).</span><span class="nx">toInt</span><span class="p">(</span><span class="mi">16</span><span class="p">))</span> <span class="p">{</span> <span class="nx">io</span><span class="p">.</span><span class="nx">setAttr</span><span class="p">(</span><span class="s2">"err"</span><span class="p">,</span><span class="s2">"11:"</span><span class="o">+</span><span class="nx">tr</span><span class="p">(</span><span class="s2">"CRC error."</span><span class="p">));</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span><span class="p">(</span><span class="nx">resp</span><span class="p">.</span><span class="nx">length</span> <span class="o">&lt;</span> <span class="mi">2</span> <span class="o">||</span> <span class="nx">resp</span><span class="p">[</span><span class="nx">resp</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">"\r"</span><span class="p">)</span> <span class="p">{</span> <span class="nx">io</span><span class="p">.</span><span class="nx">setAttr</span><span class="p">(</span><span class="s2">"err"</span><span class="p">,</span><span class="s2">"10:"</span><span class="o">+</span><span class="nx">tr</span><span class="p">(</span><span class="s2">"Error or no response."</span><span class="p">));</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span>
<span class="k">if</span><span class="p">(</span><span class="nx">resp</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">"&gt;"</span><span class="p">)</span> <span class="p">{</span> <span class="nx">io</span><span class="p">.</span><span class="nx">setAttr</span><span class="p">(</span><span class="s2">"err"</span><span class="p">,</span><span class="s2">"12:"</span><span class="o">+</span><span class="nx">resp</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="s2">":"</span><span class="o">+</span><span class="nx">tr</span><span class="p">(</span><span class="s2">"DCON error."</span><span class="p">));</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span>
<span class="c1">//Returning the result</span>
<span class="nx">io</span><span class="p">.</span><span class="nx">setAttr</span><span class="p">(</span><span class="s2">"err"</span><span class="p">,</span><span class="s2">""</span><span class="p">);</span>
<span class="nx">io</span><span class="p">.</span><span class="nx">setText</span><span class="p">(</span><span class="nx">resp</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="nx">resp</span><span class="p">.</span><span class="nx">length</span><span class="o">-</span><span class="mi">3</span><span class="p">));</span>
</pre></div>
<p>And a procedure of sending the DCON request directly, through the previous protocol procedure. This procedure should be placed in the desired task or an interim function of OpenSCADA, for example, in the procedure of the controller object <a href="../Modules/JavaLikeCalc.html#Examples" title="Special:MyLanguage/Modules/JavaLikeCalc">DAQ.JavaLikeCalc</a>:
</p>
<div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span class="c1">//Preparing the first request</span>
<span class="nx">req</span> <span class="o">=</span> <span class="nx">SYS</span><span class="p">.</span><span class="nx">XMLNode</span><span class="p">(</span><span class="s2">"#"</span><span class="p">).</span><span class="nx">setAttr</span><span class="p">(</span><span class="s2">"ProtIt"</span><span class="p">,</span><span class="s2">"DCON"</span><span class="p">).</span><span class="nx">setAttr</span><span class="p">(</span><span class="s2">"addr"</span><span class="p">,</span><span class="mi">10</span><span class="p">);</span>
<span class="c1">//Sending the request</span>
<span class="nx">SYS</span><span class="p">.</span><span class="nx">Transport</span><span class="p">[</span><span class="s2">"Serial"</span><span class="p">][</span><span class="s2">"out_TestDCON"</span><span class="p">].</span><span class="nx">messIO</span><span class="p">(</span><span class="nx">req</span><span class="p">,</span><span class="s2">"UserProtocol"</span><span class="p">);</span>
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">req</span><span class="p">.</span><span class="nx">attr</span><span class="p">(</span><span class="s2">"err"</span><span class="p">).</span><span class="nx">length</span><span class="p">)</span> <span class="nx">SYS</span><span class="p">.</span><span class="nx">messDebug</span><span class="p">(</span><span class="s2">"TEST REQ"</span><span class="p">,</span><span class="s2">"RES: "</span><span class="o">+</span><span class="nx">req</span><span class="p">.</span><span class="nx">text</span><span class="p">());</span>

<span class="c1">//Preparing the second request</span>
<span class="nx">req</span> <span class="o">=</span> <span class="nx">SYS</span><span class="p">.</span><span class="nx">XMLNode</span><span class="p">(</span><span class="s2">"@"</span><span class="p">).</span><span class="nx">setAttr</span><span class="p">(</span><span class="s2">"ProtIt"</span><span class="p">,</span><span class="s2">"DCON"</span><span class="p">).</span><span class="nx">setAttr</span><span class="p">(</span><span class="s2">"addr"</span><span class="p">,</span><span class="mi">10</span><span class="p">);</span>
<span class="c1">//Sending the request</span>
<span class="nx">SYS</span><span class="p">.</span><span class="nx">Transport</span><span class="p">[</span><span class="s2">"Serial"</span><span class="p">][</span><span class="s2">"out_TestDCON"</span><span class="p">].</span><span class="nx">messIO</span><span class="p">(</span><span class="nx">req</span><span class="p">,</span><span class="s2">"UserProtocol"</span><span class="p">);</span>
<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">req</span><span class="p">.</span><span class="nx">attr</span><span class="p">(</span><span class="s2">"err"</span><span class="p">).</span><span class="nx">length</span><span class="p">)</span> <span class="nx">SYS</span><span class="p">.</span><span class="nx">messDebug</span><span class="p">(</span><span class="s2">"TEST REQ"</span><span class="p">,</span><span class="s2">"RES: "</span><span class="o">+</span><span class="nx">req</span><span class="p">.</span><span class="nx">text</span><span class="p">());</span>
</pre></div>






</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/UserProtocol/en">Modules/UserProtocol/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>