node-red-contrib-modbus
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -38,3 +38,3 @@ /** | ||
log("loading modbustcpmaster.js for node-red"); | ||
var modbus = require('modbustcpmaster'); | ||
var modbus = require('jsmodbus'); | ||
@@ -48,6 +48,7 @@ /** | ||
function ModbusTCPControllerNode(config) { | ||
log("new ModbusTCPControllerNode, config: %j", config); | ||
//log("new ModbusTCPControllerNode, config: %j", config); | ||
RED.nodes.createNode(this, config); | ||
this.host = config.host; | ||
this.port = config.port; | ||
this.coils = config.coils || []; | ||
this.modbusconn = null; | ||
@@ -64,3 +65,2 @@ var node = this; | ||
if (handler && (typeof handler === 'function')){ | ||
log(handler); | ||
handler(node.modbusconn); | ||
@@ -80,2 +80,3 @@ } | ||
node.modbusconn.connect(); | ||
if (handler && (typeof handler === 'function')) | ||
@@ -101,3 +102,3 @@ handler(node.modbusconn); | ||
function ModbusTCPOut(config) { | ||
log('new ModbusTCP-OUT, config: %j', config); | ||
//log('new ModbusTCP-OUT, config: %j', config); | ||
RED.nodes.createNode(this, config); | ||
@@ -142,3 +143,3 @@ this.name = config.name; | ||
function ModbusTCPIn(config) { | ||
log('new ModbusTCP-IN, config: %j', config); | ||
//log('new ModbusTCP-IN, config: %j', config); | ||
RED.nodes.createNode(this, config); | ||
@@ -148,8 +149,6 @@ this.name = config.name; | ||
this.adr = config.adr; | ||
this.connection = null; | ||
var node = this; | ||
var modbusTCPController = RED.nodes.getNode(config.controller); | ||
/* ===== Node-Red events ===== */ | ||
this.on("close", function () { | ||
}); | ||
/* ===== modbustcp events ===== */ | ||
@@ -159,3 +158,4 @@ // initialize incoming modbustcp event socket | ||
modbusTCPController.initializeModbusTCPConnection(function(connection){ | ||
connection.on('Data.' + node.dataType + '.' + node.adr, function(val){ | ||
node.receiveEvent = function(val){ | ||
log('modbustcp event: Data.' + node.dataType + '.' + node.adr + '=' + val); | ||
@@ -166,5 +166,29 @@ node.send({ | ||
}); | ||
}); | ||
} | ||
node.connection = connection; | ||
node.connection.on('Data.' + node.dataType + '.' + node.adr, node.receiveEvent); | ||
switch (node.dataType){ | ||
case "Coil": | ||
node.connection.addPollingCoils(+node.adr); | ||
break; | ||
case "Input": | ||
node.connection.addPollingInputs(+node.adr); | ||
break; | ||
case "HoldingRegister": | ||
node.connection.addPollingHoldingRegisters(+node.adr); | ||
break; | ||
case "InputRegister": | ||
node.connection.addPollingInputRegisters(+node.adr); | ||
break; | ||
} | ||
}); | ||
/* ===== Node-Red events ===== */ | ||
this.on("close", function () { | ||
if (node.connection && node.receiveEvent) | ||
node.connection.off('Data.' + node.dataType + '.' + node.adr, node.receiveEvent); | ||
}); | ||
} | ||
@@ -171,0 +195,0 @@ |
{ | ||
"name": "node-red-contrib-modbus", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "A Node-RED node to communicate MODBUS TCP. Uses node jsmodbus library.", | ||
@@ -5,0 +5,0 @@ "repository": { |
37540
558