Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ typings/
.vscode

dev*
.idea

package-lock.json
18 changes: 8 additions & 10 deletions connection_pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

var util = require("util");

var pool = {};

module.exports = {
Expand All @@ -46,7 +44,7 @@ module.exports = {
options.autoConnect == "undefined" ? true : options.autoConnect;
options.preventAutoReconnect = false;
options.logLevel = options.logLevel || "WARN";
util.log(`[mcprotocol] adding new connection to pool ~ ${id}`);
node.debug(`[mcprotocol] adding new connection to pool ~ ${id}`);

var mcp = new mcprotocol();

Expand Down Expand Up @@ -97,10 +95,10 @@ module.exports = {
disconnect: function() {
this._instances -= 1;
if (this._instances <= 0) {
util.log(`[mcprotocol] closing connection ~ ${id}`);
node.debug(`[mcprotocol] closing connection ~ ${id}`);
mcp.dropConnection();
mcp = null;
util.log(`[mcprotocol] deleting connection from pool ~ ${id}`);
node.debug(`[mcprotocol] deleting connection from pool ~ ${id}`);
delete pool[id];
}
},
Expand All @@ -119,12 +117,12 @@ module.exports = {

mcp.on("error", function(e) {
if (mcp) {
util.log(`[mcprotocol] error ~ ${id}: ${e}`);
node.error(`[mcprotocol] error ~ ${id}: ${e}`);
connecting = false;
if (options.autoConnect) {
setTimeout(function() {
if (options.autoConnect && !options.preventAutoReconnect) {
util.log(
node.error(
`[mcprotocol] autoConnect call from error handler ~ ${id}`
);
obj.connect();
Expand All @@ -135,17 +133,17 @@ module.exports = {
});
mcp.on("open", function() {
if (mcp) {
util.log(`[mcprotocol] connected ~ ${id}`);
node.debug(`[mcprotocol] connected ~ ${id}`);
connecting = false;
}
});
mcp.on("close", function(err) {
util.log(`[mcprotocol] connection closed ~ ${id}`);
node.debug(`[mcprotocol] connection closed ~ ${id}`);
connecting = false;
if (options.autoConnect) {
setTimeout(function() {
if (options.autoConnect && !options.preventAutoReconnect) {
util.log(
node.debug(
`[mcprotocol] autoConnect call from close handler ~ ${id}`
);
obj.connect();
Expand Down
2 changes: 1 addition & 1 deletion nodes/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SOFTWARE.

module.exports = function(RED) {
var connection_pool = require("../connection_pool.js");
var util = require("util");

function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-mcprotocol",
"version": "1.2.0",
"version": "1.3.0",
"description": "Mode-red nodes to Read from & Write to MITSUBISHI PLC over Ethernet using MC Protocol",
"repository": {
"type": "git",
Expand Down