ina2000

1.0.6 • Public • Published

Background

IoT solutions are more increasingly relevant in Automation World and together with IoT comes javascript. I wanted to create this module to provide a javascript implementation to read/write data from/to B&R PLC. INA2000 (Industrial Network Architecture) is a protocol which is a communication protocol to exchange data with B&R PLCs. This protocol is targetted for old generation PLCs but will work also with the new generation PLCs also. Also important to notice that this service is activated by default on the PLC. B&R PLCs utilize nowadays new Protocol called ANSL (Automation Network Service Line) which is a TCP based protocol compared to INA which is UDP based.

Development & contribution

I'm doing this at the moment on my own and I have only my spare time to develop this. I'm learning on the fly and I can guess that the current implementation doesn't fit into any coding guidelines. Every input, wether it's good or bad, is welcome and I try to improve this module as well as I can. From usage point of view the module is not programmed as I wanted it could be used. This comes frome the asynchronous nature of the protocol.

Install package:

npm i ina2000

Usage:

var ina2000 = require('ina2000');

ina2000.connect('127.0.0.10',11160).on('connected',
function(e){
	//console.log(e.plc);
	// notice that you can have nonexisting variables also in the array which is an input for the registerVariable-method
	// the module will check which variables are actually on the PLC - information from this will be output in the console
	// 2nd parameter for registerVariable is data request cycle for PLC
	ina2000.registerVariable(["gVar","Program:localVar","Program:localVar123123","ASDF:localVar"],1000).on('valueChanged',valueChanged);
});


// Run only 10 seconds then disconnect
setTimeout(function()
{
	ina2000.disconnect();	
},10000);
	
	
	
//this will be called when registered variable value is changed
function valueChanged(variable, value)
{
	console.log("Variable changed: (name: %s) - (value: %s)",variable.name,value);
}
	

Events

  • connected -- This is at the moment only event that is created.
  • valueChanged -- Once you have registered variables you can add a call back to catch tehse events
  • registerDone -- This is an event when variables have been registred successfully
  • plcSearchFinished -- This is an event when PLC search has been finished

Features

  • Connect to B&R PLC
  • List tasks (programs running) on the target -- This also includes that all the variables (name and type) information comes with the query
  • Read variable values from PLC | V1.0.3
  • Write variable value to PLC | V1.0.5
  • Search PLCs from broadcast address | V1.0.6

Coming feautures

  • Read Date and Time from PLC
  • Set Date and Time to PLC

Possible features (Proof of concept done / tested separately successfully)

  • Service functions -- restart PLC (cold/warm restart) -- stop PLC
  • Diagnostic functions -- Install trace function to PLC
  • Download modules -- Log files -- System configuraiton -- Trace files / profile files
  • Conversion from binary data (B6R format to some other) to usable

Examples

Get events when variable value changes

var ina2000 = require('ina2000');

ina2000.connect('127.0.0.10',11160).on('connected',
function(e){
	//console.log(e.plc);
	ina2000.registerVariable(["gVar","Program:localVar","Program:localVar123123","ASDF:localVar"]).on('valueChanged',valueChanged);
});


// Run only 10 seconds then disconnect
setTimeout(function()
{
	ina2000.disconnect();	
},20000);
	
	
	
//this will be called when registered variable value is changed
function valueChanged(variable, value)
{
	console.log("Variable changed: (name: %s) - (value: %s)",variable.name,value);
	if(value > 100)
	{
		console.log("value %d > 100",value);
		ina2000.writeValue(variable,25);
		
	}
}
	

Browse LAN to find what B&R PLCs can be found

var ina2000 = require('ina2000');

// 192.168.250.255 <-- search from 192.168.250.0/24
// 127.255.255.255 <-- search from localhost network
// parameters:
// 1st - broadcast addresss
// 2nd - port number
// 3rd - startIndex (node number)
// 4th - endIndex (node number)
ina2000.searchPLCs('192.168.250.255',11160,1,100).on('plcSearchFinished',function(e)
{
	console.log(e);
});

Simple cyclic write sample

var ina2000 = require('ina2000');
var registration;
var vars;
var counter = 0;

ina2000.connect('127.0.0.10',11160).on('connected',
function(e){
	//console.log(e.plc);
	//2nd parameter for registerVariable is update cycle to fetch data from PLC
	registration = ina2000.registerVariable(["gVar","Program:localVar","Program:localVar123123","ASDF:localVar"
	,"Program:tempSTRING"],1000);
	
	registration.on('valueChanged',valueChanged);
	registration.on('registerDone',function (e){
			vars = e.variables;
	});
});

ina2000.searchPLCs('192.168.250.255',11160,1,100).on('plcSearchFinished',function(e)
{
	console.log(e);
});


// Run only 20 seconds then disconnect
setTimeout(function()
{
	ina2000.disconnect();
	clearInterval(myCyclicExecution);
},20000);


// create cyclic execution part
var myCyclicExecution = setInterval(function()
{
	//assumption that this will succeed!
	++counter;
	if(vars.length > 0)
	{
		ina2000.writeValue(vars[1],counter); // write numeric value
		ina2000.writeValue(vars[2],"counter = " + counter); // write string value
	}
},700);	// execute every 700 ms
	
	
//this will be called when registered variable value is changed
function valueChanged(variable, value)
{
	console.log("Variable changed: (name: %s) - (value: %s)",variable.name,value);
	// write new value if value is creater than 100
	if(value > 100)
	{
		ina2000.writeValue(variable,25);	
	}
}

Test environment

If you wish to have a simulator to play around with you can download a zip file from Google drive which contains a runnable simulator executable. Simulator download link.

instructions
  • Unzip the file
  • Enter the extracted folder and execute execute the **ar000loader. After running the exe you should see an icon in your tray icons

You can also download development environment from B&R download page (4.9). Of course the development environment is not necessary to run the simulator. But is a useful tool when playing around with this and necessary if you want to change the contents of the simulator (variables and tasks running in it or to create your simulaton/real system).

Limitations / known issues

  • Single communication message is limited to ~250 bytes -- This means that if request a variable from the PLC which is say 2000 bytes long. This data has to be requested with 8 communication messages. -- I haven't tested this that well yet. But of course this can be achieved. -- Maximum amount of variables requested per packet is 30 variables. -- If the result of 30 variables values exceeds 250 bytes. It's not tested/implemented. (can be though)

  • At the moment only IEC-61131 Basic datatypes are supported in reading and writing. Compplex datatypes will be implemented if requested

Report issues / bug fixes / requests

Contanct email addresss jooanks@gmail.com and I'll take a look on the issue and try to fix it. If you wish to have certain feature implemented send an email of that too. Also if you wish to see more examples, I can try to make more of them.

Misc

I would appreciate if you drop me a message if you end up playing around with this package wether it's just for fun and testing. I'm interrested to know that if this has any use cases.

Readme

Keywords

Package Sidebar

Install

npm i ina2000

Weekly Downloads

1

Version

1.0.6

License

ISC

Unpacked Size

85.8 kB

Total Files

3

Last publish

Collaborators

  • kiiskinenj