From 90b53843602b93f5b8fd6ad368fab6a53da000b0 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 9 Feb 2018 15:09:37 +0100 Subject: [PATCH] Fixed TypeError when calling .open the second time Moved the isOpen defineProperty outside the .open method. --- index.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 86c8c5b..129fe8f 100644 --- a/index.js +++ b/index.js @@ -342,21 +342,23 @@ ModbusRTU.prototype.open = function(callback) { callback(error); } }); +}; + - /** - * Check if port is open - */ - Object.defineProperty(this, "isOpen", { - enumerable: true, - get: function() { - if (this._port) { - return this._port.isOpen; - } - - return false; +/** + * Check if port is open + */ +Object.defineProperty(ModbusRTU.prototype, "isOpen", { + enumerable: true, + get: function() { + if (this._port) { + return this._port.isOpen; } - }); -}; + + return false; + } +}); + /** * Close the serial port