njs-modbus 1.3.3 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -545,6 +545,7 @@ function lrc(data) {
545
545
  return (~data.reduce((sum, n) => sum + n, 0) + 1) & 0xff;
546
546
  }
547
547
 
548
+ const MAX_FRAME_LENGTH = 256;
548
549
  class RtuApplicationLayer extends AbstractApplicationLayer {
549
550
  constructor(physicalLayer,
550
551
  /**
@@ -591,25 +592,28 @@ class RtuApplicationLayer extends AbstractApplicationLayer {
591
592
  }
592
593
  const handleData = (data, response) => {
593
594
  this._bufferRx = Buffer.concat([this._bufferRx, data]);
594
- if (this._waitingResponse) {
595
+ clearTimeout(this._timerThreePointFive);
596
+ const handleData = () => {
595
597
  this.framing(this._bufferRx, (error, frame) => {
596
- if (error && error.message === 'Insufficient data length') {
597
- return;
598
+ if (this._waitingResponse) {
599
+ if (error && error.message === 'Insufficient data length') {
600
+ return;
601
+ }
602
+ this._waitingResponse.callback(error, frame);
603
+ this._bufferRx = Buffer.alloc(0);
598
604
  }
599
- this._waitingResponse.callback(error, frame);
600
- this._bufferRx = Buffer.alloc(0);
601
- });
602
- }
603
- else {
604
- clearTimeout(this._timerThreePointFive);
605
- const handleData = () => {
606
- this.framing(this._bufferRx, (error, frame) => {
605
+ else {
607
606
  if (!error) {
608
607
  this.emit('framing', frame, response);
609
608
  }
610
609
  this._bufferRx = Buffer.alloc(0);
611
- });
612
- };
610
+ }
611
+ });
612
+ };
613
+ if (this._bufferRx.length >= MAX_FRAME_LENGTH) {
614
+ handleData();
615
+ }
616
+ else {
613
617
  if (threePointFiveT) {
614
618
  this._timerThreePointFive = setTimeout(handleData, threePointFiveT);
615
619
  }
package/dist/index.mjs CHANGED
@@ -543,6 +543,7 @@ function lrc(data) {
543
543
  return (~data.reduce((sum, n) => sum + n, 0) + 1) & 0xff;
544
544
  }
545
545
 
546
+ const MAX_FRAME_LENGTH = 256;
546
547
  class RtuApplicationLayer extends AbstractApplicationLayer {
547
548
  constructor(physicalLayer,
548
549
  /**
@@ -589,25 +590,28 @@ class RtuApplicationLayer extends AbstractApplicationLayer {
589
590
  }
590
591
  const handleData = (data, response) => {
591
592
  this._bufferRx = Buffer.concat([this._bufferRx, data]);
592
- if (this._waitingResponse) {
593
+ clearTimeout(this._timerThreePointFive);
594
+ const handleData = () => {
593
595
  this.framing(this._bufferRx, (error, frame) => {
594
- if (error && error.message === 'Insufficient data length') {
595
- return;
596
+ if (this._waitingResponse) {
597
+ if (error && error.message === 'Insufficient data length') {
598
+ return;
599
+ }
600
+ this._waitingResponse.callback(error, frame);
601
+ this._bufferRx = Buffer.alloc(0);
596
602
  }
597
- this._waitingResponse.callback(error, frame);
598
- this._bufferRx = Buffer.alloc(0);
599
- });
600
- }
601
- else {
602
- clearTimeout(this._timerThreePointFive);
603
- const handleData = () => {
604
- this.framing(this._bufferRx, (error, frame) => {
603
+ else {
605
604
  if (!error) {
606
605
  this.emit('framing', frame, response);
607
606
  }
608
607
  this._bufferRx = Buffer.alloc(0);
609
- });
610
- };
608
+ }
609
+ });
610
+ };
611
+ if (this._bufferRx.length >= MAX_FRAME_LENGTH) {
612
+ handleData();
613
+ }
614
+ else {
611
615
  if (threePointFiveT) {
612
616
  this._timerThreePointFive = setTimeout(handleData, threePointFiveT);
613
617
  }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "njs-modbus",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "A pure JavaScript implemetation of Modbus for NodeJS.",
5
5
  "keywords": [
6
6
  "modbus",