plcpeople / nodepccc

Library for node.js to communicate with some Allen-Bradley programmable controllers (PLCs)
MIT License
81 stars 24 forks source link

ECONNRESET error occurs when i want to connect to plc periodically #15

Closed volsoft closed 6 years ago

volsoft commented 7 years ago

Hello plcpeople,

Thanks for this great library.

We are using your library in our Meteor project. We want to connect to PLC in every 5 seconds to check if values of tags are changed. So I've set an interval like this:

Meteor.plcTimer = setInterval(function(){ Meteor.call('readWritePLCData', tags); }, 5 * 1000);

And tags is an array contains items like : 'K1001, 'K1002' etc. Then i call 'readWritePLCData' method like this:

Meteor.methods({ 'readWritePLCData': function(tags){ ... conn.initiateConnection({port: 44818, host: 'xxx.xx.xx.xx' }, connected); function connected(err){ ... conn.readAllItems(valuesReady); ... } } }); Method is basically a copy of your sample except host ip. I use your "tagLookup" function and it converts tags above to 'B1:0/2', 'B2:0/4' etc. When i want to log values in valuesReady callback the output is fine:

{ K1317: false, K1318: false, K1402: false, K1316: false, K1315: false, K1302: false, K1405: false, K1304: false, K1306: false, K1308: false, K1310: false, K1312: false, K1314: false }

This output shows correct boolean values and it is shown every 5 seconds. There never is a "SOMETHING WENT WRONG READING VALUES!!!!" output. But after a few minutes this output shows up:

I20170216-09:16:45.455(2)? [1110077,362847744] Initiate Called - Connecting to P LC with address and parameters: I20170216-09:16:45.457(2)? [1110077,362933760] { port: 44818, host: 'xxx.xx.xx.x x' } I20170216-09:16:45.458(2)? [1110077,363096064] Connection cleanup is happening I20170216-09:16:45.459(2)? [1110077,363215872 xxx.xx.xx.xx] Attempting to connec t to host... I20170216-09:16:45.545(2)? [1110077,445200384 xxx.xx.xx.xx] TCP Connection Estab lished to xxx.xx.xx.xx on port 44818 - Will attempt EIP Connection I20170216-09:16:45.583(2)? [1110077,490686464 xxx.xx.xx.xx] We Caught a connect error ECONNRESET I20170216-09:16:45.584(2)? { [Error: read ECONNRESET] code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' } => Exited with code: 0

After that, node exists the process and Meteor restarts server and everything is fine until ECONNRESET error occurs in just a few minutes.

Our PLC is CompactLogix 5370 L1.

What may cause this problem and how to solve it?

I really appreciate your help.

gfcittolin commented 6 years ago

A very similar issue happened to plcpeople/nodeS7#29, and it looks like we have the same issue here. I'll push a PR with a fix for it