OpenSCADA

Modules/UserProtocol

English • ‎mRussian • ‎Українська
Module Name Version License Source Languages Platforms Type Author Description
UserProtocol User protocol 1.6 GPL2 prot_UserProtocol.so en,uk,ru,de x86,x86_64,ARM Protocol Roman Savochenko
  Maxim Lysenko (2010) — the page initial translation
Provides for creating your own user protocols on internal OpenSCADA language.

The module is designed to allow the user to create own implementations of different protocols in internal OpenSCADA language, usually JavaLikeCalc, without involving low level programming.

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.

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.

The module provides the ability to create multiple implementations of different protocols in the object "User protocol" (Fig.1), and also use standard DAQ templates 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".

Fig.1. Main tab of an object of the module "User protocol".

The main tab contains the basic settings of the user protocol:

Contents

1 Input part of the protocol

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

Fig.2. Tab of the configuration and the controlling for the input requests.

Tab of the configuration and the controlling of the input requests contains:

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:

The overall scenario of the input requests processing:

As an example, let's consider the implementation of DCON request processing for some requests to a data source with the address "10":

var enCRC = true;
//SYS.messDebug("/DCON/in","REQ: "+request);
//Testing the request for completity
if(request.length < 4 || request[request.length-1] != "\r") {
  if(request.length > 10) request = "";
  return true;
}
//Checking the request for the integrity (CRC) and the address
if(enCRC) {
  CRC = 0;
  for(i = 0; i < (request.length-3); i++) CRC += request.charCodeAt(i);
  if(CRC != request.slice(request.length-3,request.length-1).toInt(16) || request.slice(1,3).toInt(16) != 10) return false;
}
//Analysis the request and the response preparing
if(request[0] == "#") answer = ">+05.123+04.153+07.234-02.356+10.000-05.133+02.345+08.234";
else if(request[0] == "@") answer = ">AB3C";
else answer = "?";
//Finishing the response
if(enCRC) {
  CRC = 0;
  for(i=0; i < answer.length; i++) CRC += answer.charCodeAt(i);
  answer += (CRC&0xFF).toString(16,2)+"\r";
}
//SYS.messDebug("/DCON/in","ANSV: "+answer[0]);
return 0;

2 Output part of the protocol

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 function of the system-wide API of the user programming of the output transport "int messIO(XMLNodeObj req, string prt );", in the parameters of which it must be specified:

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 req.attr("ProtIt").

Fig.3. Tab of a direct procedure of the output requests processing.

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.

For the direct processing procedure, and the required or optional ones to create in the template, the following exchange attributes are predetermined:

The overall scenario of the output request formation:

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.

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:

//Preparing the result request
request = io.name().slice(0,1) + io.attr("addr").toInt().toString(16,2) + io.text();
if(io.attr("CRC").toInt()) {
  CRC = 0;
  for(i = 0; i < request.length; i++) CRC += request.charCodeAt(i);
    request += (CRC&0xFF).toString(16,2) + "\r";
}
else request += "\r";
//Sending the request
resp = tr.messIO(request);
while(resp[resp.length-1] != "\r") {
  tresp = tr.messIO("");
  if(!tresp.length) break;
  resp += tresp;
}
//Analysis the response
if(io.attr("CRC").toInt()) {
  if(resp.length < 4 || resp[resp.length-1] != "\r") { io.setAttr("err","10:"+tr("Error or no response.")); return; }
  //Checking the response to the integrity (CRC)
  CRC = 0;
  for(i = 0; i < (resp.length-3); i++) CRC += resp.charCodeAt(i);
    if(CRC != resp.slice(resp.length-3,resp.length-1).toInt(16)) { io.setAttr("err","11:"+tr("CRC error.")); return; }
}
else if(resp.length < 2 || resp[resp.length-1] != "\r") { io.setAttr("err","10:"+tr("Error or no response.")); return; }
if(resp[0] != ">") { io.setAttr("err","12:"+resp[0]+":"+tr("DCON error.")); return; }
//Returning the result
io.setAttr("err","");
io.setText(resp.slice(1,resp.length-3));

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 DAQ.JavaLikeCalc:

//Preparing the first request
req = SYS.XMLNode("#").setAttr("ProtIt","DCON").setAttr("addr",10);
//Sending the request
SYS.Transport["Serial"]["out_TestDCON"].messIO(req,"UserProtocol");
if(!req.attr("err").length) SYS.messDebug("TEST REQ","RES: "+req.text());

//Preparing the second request
req = SYS.XMLNode("@").setAttr("ProtIt","DCON").setAttr("addr",10);
//Sending the request
SYS.Transport["Serial"]["out_TestDCON"].messIO(req,"UserProtocol");
if(!req.attr("err").length) SYS.messDebug("TEST REQ","RES: "+req.text());
Modules/UserProtocol/en - GFDLMay 2024OpenSCADA 0.9.7