diff --git a/ports/telnetport.js b/ports/telnetport.js index 4018f0f..a0ba018 100644 --- a/ports/telnetport.js +++ b/ports/telnetport.js @@ -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.")); }); diff --git a/test/ports/tcpport.test.js b/test/ports/tcpport.test.js index d10fe21..bc0f88b 100644 --- a/test/ports/tcpport.test.js +++ b/test/ports/tcpport.test.js @@ -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() { diff --git a/test/ports/tcpportrtubuffered.test.js b/test/ports/tcpportrtubuffered.test.js index 8a90be0..86f5aef 100644 --- a/test/ports/tcpportrtubuffered.test.js +++ b/test/ports/tcpportrtubuffered.test.js @@ -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() { @@ -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() { diff --git a/test/ports/telnetport.test.js b/test/ports/telnetport.test.js index ae48fc9..14e018e 100644 --- a/test/ports/telnetport.test.js +++ b/test/ports/telnetport.test.js @@ -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() { @@ -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() {