This module is the Appcelerator Titanium implementation of IEC 60870-5-104 communication standard. It is an alternative solution of NeoSCADA.104 Thanks to Stefan Feuerhahn from Fraunhofer Institute for Solar Energy Systems for the Java implementation.
The module is work on progress and not ready for production.
First we need a connection to the server:
var IEC60870 = require("de.appwerft.j60870");
var conn = IEC60870.createClientConnection({
address : "192.168.0.3",
port : 2404,
commonAddressFieldLength : INT, // length of the Common Address (CA) field of the ASDU
cotFieldLength : INT, // length of the Cause Of Transmission (COT) field of the ASDU
ioaFieldLength : INT, // length of the Information Object Address (IOA) field of the ASDU
maxIdleTime : INT, // maximum time in ms that the connection may be idle before sending a test frame
maxTimeNoAckReceived : INT, // maximum time in ms that no acknowledgement has been received (for I-Frames or Test-Frames) before actively closing the connection.
maxTimeNoAckSent : INT,
maxUnconfirmedIPdusReceived : INT
});
Alternatively to constructor parameters you can provide a json file in you folder Ressources. In this case you can simple connect by
var conn = IEC60870.createClientConnection();
conn.connect(require("onConnectHandler"),onErrorHandler);
The default path of configuration file j60870.json
you can overwrite in your tiapp.xml with parameter J60870_PATH
. In this case you can only connect one server.
After creation of a connection you can connect:
Inside of onConnectHandler.js
the work will done. The payload is an array of informationObjects. Every informationObject is an array of different informationElements.
module.exports = function(_connection) {
var Connection = _ connection;
/*
A set of Information Elements or a sequence of information element sets.
The type of information elements in the set and their order depend
on the ASDU's TypeId and is the same for all information objects within one ASDU.
If the sequence bit is set in the ASDU then the ASDU contains a single Information Object
containing a sequence of information element sets. If the sequence bit is not set the ASDU
contains a sequence of information objects each containing only single information elements sets.
*/
/* In Titanium implementation a JSONArray is using: */
var infoObject = IEC60870.createInformationObject({
address : 234, // IOA
elems : IEC60870.createElements([["AFQ",3, 18],["BCR", 31, 17, true,true, false]]])
});
var ASdu = IEC60870.createASdu({
typeId : "C_BO_NA_1",
COT : "ACTIVATION",
isSequenceOfElements : true,
test : false,
negativeConfirm : false
originatorAddress : 123, // the address of the originating controlling station so that responses can be routed back to it
commonAddress : 23, //the address of the target station or the broadcast address.
informationObjects : [infoObject]
});
Connection.startDataTransfer(ASdu);
Connection.addEventListener("onASduReceived",function(asdu){
console.log(asd);
});
};
var IEC60870 = require("de.appwerft.j60870");
var conn = IEC60870.Server.createConnection({
address : "192.168.0.3",
port : 2404,
commonAddressFieldLength : INT, // length of the Common Address (CA) field of the ASDU
cotFieldLength : INT, // length of the Cause Of Transmission (COT) field of the ASDU
ioaFieldLength : INT, // length of the Information Object Address (IOA) field of the ASDU
maxIdleTime : INT, // maximum time in ms that the connection may be idle before sending a test frame
maxTimeNoAckReceived : INT, // maximum time in ms that no acknowledgement has been received (for I-Frames or Test-Frames) before actively closing the connection.
maxTimeNoAckSent : INT,// maximum time in ms that no acknowledgement has been received (for I-Frames or Test-Frames) before actively closing the connection
maxUnconfirmedIPdusReceived : INT,
maxConnections : INT, // maximum number of client connections that are allowed in parallel
backLog : INT // backlog that is passed to the java.net.ServerSocket
});