Skip to content

Commit

Permalink
fix: telnetport: keep connection open on timeout and do not force rec…
Browse files Browse the repository at this point in the history
…onnecting TCP (#424)
  • Loading branch information
borodiliz authored Sep 5, 2021
1 parent a0a020f commit d86b518
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ports/telnetport.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ var TelnetPort = function(ip, options) {
});

this._client.on("timeout", function() {
self.openFlag = false;
// modbus.openFlag is left in its current state as it reflects two types of timeouts,
// i.e. 'false' for "TCP connection timeout" and 'true' for "Modbus response timeout"
// (this allows to continue Modbus request re-tries without reconnecting TCP).
modbusSerialDebug("TelnetPort port: TimedOut");
handleCallback(new Error("TelnetPort Connection Timed Out."));
});
Expand Down
2 changes: 1 addition & 1 deletion test/ports/tcpport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Modbus TCP port", function() {
});
});
});
it("should be able to be destoryed after opening", function(done) {
it("should be able to be destroyed after opening", function(done) {
port.open(function() {
port.destroy(function() {
setTimeout(function() {
Expand Down
10 changes: 9 additions & 1 deletion test/ports/tcpportrtubuffered.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("Modbus TCP RTU buffered port", function() {
});
});
});
it("should be able to be destoryed after opening", function(done) {
it("should be able to be destroyed after opening", function(done) {
port.open(function() {
port.destroy(function() {
setTimeout(function() {
Expand All @@ -59,6 +59,14 @@ describe("Modbus TCP RTU buffered port", function() {
});
});
});
it("should not be closed on timeout", function(done) {
port.open(function() {
expect(port.isOpen).to.be.true;
port.emit("timeout");
expect(port.isOpen).to.be.true;
done();
});
});
});

describe("data handler", function() {
Expand Down
10 changes: 9 additions & 1 deletion test/ports/telnetport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("Modbus Telnet port", function() {
});
});
});
it("should be able to be destoryed after opening", function(done) {
it("should be able to be destroyed after opening", function(done) {
port.open(function() {
port.destroy(function() {
setTimeout(function() {
Expand All @@ -59,6 +59,14 @@ describe("Modbus Telnet port", function() {
});
});
});
it("should not be closed on timeout", function(done) {
port.open(function() {
expect(port.isOpen).to.be.true;
port.emit("timeout");
expect(port.isOpen).to.be.true;
done();
});
});
});

describe("data handler", function() {
Expand Down

0 comments on commit d86b518

Please sign in to comment.