From e4c8214ecc68fd0bca04119caa9854ab9130097f Mon Sep 17 00:00:00 2001 From: PeterChristen577 <64326586+PeterChristen577@users.noreply.github.com> Date: Sat, 25 Apr 2020 21:24:41 +0200 Subject: [PATCH 1/3] Improvement for scan_rate Using ethernet-ip in Node-RED, I did some analysis of the realtime behaviour using Wire Shark. There I have seen the real scan rate (320 ms) does not match the setup in the project (200 ms). Before the scan rate set up as the time delay between the last resonse of the PLC and the next request. In case of longer tag list (up to 30 tags), there are two tag groups exchanged. Now there is a timer used that triggers the start of the request more precise. --- src/controller/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/controller/index.js b/src/controller/index.js index a56dd7c..6fc2765 100644 --- a/src/controller/index.js +++ b/src/controller/index.js @@ -404,8 +404,11 @@ class Controller extends ENIP { async scan() { this.state.scanning = true; - while (this.state.scanning) { - await this.workers.group + const timer = setInterval(() => { + if (this.state.scanning == false) { + clearInterval(timer) + } + this.workers.group .schedule(this._readTagGroup.bind(this), [this.state.subs], { priority: 10, timestamp: new Date() @@ -418,7 +421,7 @@ class Controller extends ENIP { } }); - await this.workers.group + this.workers.group .schedule(this._writeTagGroup.bind(this), [this.state.subs], { priority: 10, timestamp: new Date() @@ -430,9 +433,7 @@ class Controller extends ENIP { throw e; } }); - - await delay(this.state.scan_rate); - } + }, this.state.scan_rate) } /** From d3855cd025d25e1a585b47860e47790f6f59b7dd Mon Sep 17 00:00:00 2001 From: PeterChristen577 <64326586+PeterChristen577@users.noreply.github.com> Date: Sat, 25 Apr 2020 21:35:50 +0200 Subject: [PATCH 2/3] Fixed coding error in line 408 not === used in comparison, comes from C coding ;) --- src/controller/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/index.js b/src/controller/index.js index 6fc2765..5756897 100644 --- a/src/controller/index.js +++ b/src/controller/index.js @@ -405,7 +405,7 @@ class Controller extends ENIP { this.state.scanning = true; const timer = setInterval(() => { - if (this.state.scanning == false) { + if (this.state.scanning === false) { clearInterval(timer) } this.workers.group From 2b9b90a536c17b36f15ccaa0bbd5250bf83ce4ab Mon Sep 17 00:00:00 2001 From: Peter Christen <64326586+PeterChristen577@users.noreply.github.com> Date: Sun, 26 Apr 2020 21:55:01 +0200 Subject: [PATCH 3/3] Interval for scan_rate removed According Alex's comment I have removed the interval. I found a better solution to make the scan_rate more precise. Now the execution time for the data exchange is measured and if any time is spare to wait, the delay is invoked. --- src/controller/index.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/controller/index.js b/src/controller/index.js index 5756897..6a470fe 100644 --- a/src/controller/index.js +++ b/src/controller/index.js @@ -404,11 +404,9 @@ class Controller extends ENIP { async scan() { this.state.scanning = true; - const timer = setInterval(() => { - if (this.state.scanning === false) { - clearInterval(timer) - } - this.workers.group + while (this.state.scanning) { + var startTime = new Date(); + await this.workers.group .schedule(this._readTagGroup.bind(this), [this.state.subs], { priority: 10, timestamp: new Date() @@ -421,7 +419,7 @@ class Controller extends ENIP { } }); - this.workers.group + await this.workers.group .schedule(this._writeTagGroup.bind(this), [this.state.subs], { priority: 10, timestamp: new Date() @@ -433,7 +431,12 @@ class Controller extends ENIP { throw e; } }); - }, this.state.scan_rate) + + var executionTime = new Date() - startTime; + if (this.state.scan_rate > executionTime) { + await delay(this.state.scan_rate - executionTime); + } + } } /**