Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-red-contrib-modbus

Package Overview
Dependencies
Maintainers
2
Versions
197
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-modbus - npm Package Compare versions

Comparing version 5.26.0 to 5.27.0

docs/gen/module-NodeRedModbusFlexFc.html

2

modbus/core/modbus-client-core.js

@@ -1,2 +0,2 @@

"use strict";require("source-map-support").install();var de=de||{biancoroyal:{modbus:{core:{client:{}}}}};de.biancoroyal.modbus.core.client.internalDebug=de.biancoroyal.modbus.core.client.internalDebug||require("debug")("contribModbus:core:client"),de.biancoroyal.modbus.core.client.internalDebugFSM=de.biancoroyal.modbus.core.client.internalDebugFSM||require("debug")("contribModbus:core:client:fsm"),de.biancoroyal.modbus.core.client.modbusSerialDebug=de.biancoroyal.modbus.core.client.modbusSerialDebug||require("debug")("modbus-serial"),de.biancoroyal.modbus.core.client.XStateFSM=de.biancoroyal.modbus.core.client.XStateFSM||require("@xstate/fsm"),de.biancoroyal.modbus.core.client.stateLogEnabled=de.biancoroyal.modbus.core.client.stateLogEnabled||!1,de.biancoroyal.modbus.core.client.networkErrors=["ESOCKETTIMEDOUT","ETIMEDOUT","ECONNRESET","ENETRESET","ECONNABORTED","ECONNREFUSED","ENETUNREACH","ENOTCONN","ESHUTDOWN","EHOSTDOWN","ENETDOWN","EWOULDBLOCK","EAGAIN","EHOSTUNREACH"],de.biancoroyal.modbus.core.client.createStateMachineService=function(){return this.stateLogEnabled=!1,this.XStateFSM.createMachine({id:"modbus",initial:"new",states:{new:{on:{INIT:"init",BREAK:"broken",STOP:"stopped"}},broken:{on:{INIT:"init",STOP:"stopped",FAILURE:"failed",ACTIVATE:"activated",RECONNECT:"reconnecting"}},reconnecting:{on:{INIT:"init",STOP:"stopped"}},init:{on:{OPENSERIAL:"opened",CONNECT:"connected",BREAK:"broken",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},opened:{on:{CONNECT:"connected",BREAK:"broken",FAILURE:"failed",CLOSE:"closed",STOP:"stopped",SWITCH:"switch"}},connected:{on:{CLOSE:"closed",ACTIVATE:"activated",QUEUE:"queueing",BREAK:"broken",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},activated:{on:{READ:"reading",WRITE:"writing",QUEUE:"queueing",BREAK:"broken",CLOSE:"closed",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},queueing:{on:{ACTIVATE:"activated",SEND:"sending",READ:"reading",WRITE:"writing",EMPTY:"empty",BREAK:"broken",CLOSE:"closed",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},empty:{on:{QUEUE:"queueing",BREAK:"broken",FAILURE:"failed",CLOSE:"closed",STOP:"stopped",SWITCH:"switch"}},sending:{on:{ACTIVATE:"activated",READ:"reading",WRITE:"writing",BREAK:"broken",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},reading:{on:{ACTIVATE:"activated",BREAK:"broken",FAILURE:"failed",STOP:"stopped"}},writing:{on:{ACTIVATE:"activated",BREAK:"broken",FAILURE:"failed",STOP:"stopped"}},closed:{on:{FAILURE:"failed",BREAK:"broken",CONNECT:"connected",RECONNECT:"reconnecting",INIT:"init",STOP:"stopped",SWITCH:"switch"}},failed:{on:{CLOSE:"closed",BREAK:"broken",STOP:"stopped",SWITCH:"switch"}},switch:{on:{CLOSE:"closed",BREAK:"broken",STOP:"stopped"}},stopped:{on:{NEW:"new",STOP:"stopped"}}}})},de.biancoroyal.modbus.core.client.getActualUnitId=function(e,n){return n.payload&&Number.isInteger(n.payload.unitid)?parseInt(n.payload.unitid):Number.isInteger(n.queueUnitId)?parseInt(n.queueUnitId):parseInt(e.unit_id)||0},de.biancoroyal.modbus.core.client.startStateService=function(e){return this.XStateFSM.interpret(e).start()},de.biancoroyal.modbus.core.client.checkUnitId=function(e,n){return"tcp"===n?0<=e&&e<=255:0<=e&&e<=247},de.biancoroyal.modbus.core.client.getLogFunction=function(e){return e.internalDebugLog||de.biancoroyal.modbus.core.client.internalDebug},de.biancoroyal.modbus.core.client.activateSendingOnSuccess=function(e,n,t,a,o){e.activateSending(o).then(function(){n(a,o)}).catch(function(e){t(e,o)}).finally(function(){e.stateService.send("ACTIVATE")})},de.biancoroyal.modbus.core.client.activateSendingOnFailure=function(e,n,t,a){e.activateSending(a).then(function(){n(t,a)}).catch(function(e){n(e,a)}).finally(function(){e.stateService.send("ACTIVATE")})},de.biancoroyal.modbus.core.client.readModbusByFunctionCodeOne=function(n,t,a,o){var i=de.biancoroyal.modbus.core.client;n.client.readCoils(parseInt(t.payload.address),parseInt(t.payload.quantity)).then(function(e){i.activateSendingOnSuccess(n,a,o,e,t)}).catch(function(e){i.activateSendingOnFailure(n,o,new Error(e.message),t),n.modbusErrorHandling(e)})},de.biancoroyal.modbus.core.client.readModbusByFunctionCodeTwo=function(n,t,a,o){var i=de.biancoroyal.modbus.core.client;n.client.readDiscreteInputs(parseInt(t.payload.address),parseInt(t.payload.quantity)).then(function(e){i.activateSendingOnSuccess(n,a,o,e,t)}).catch(function(e){i.activateSendingOnFailure(n,o,new Error(e.message),t),n.modbusErrorHandling(e)})},de.biancoroyal.modbus.core.client.readModbusByFunctionCodeThree=function(n,t,a,o){var i=de.biancoroyal.modbus.core.client;n.client.readHoldingRegisters(parseInt(t.payload.address),parseInt(t.payload.quantity)).then(function(e){i.activateSendingOnSuccess(n,a,o,e,t)}).catch(function(e){i.activateSendingOnFailure(n,o,new Error(e.message),t),n.modbusErrorHandling(e)})},de.biancoroyal.modbus.core.client.readModbusByFunctionCodeFour=function(n,t,a,o){var i=de.biancoroyal.modbus.core.client;n.client.readInputRegisters(parseInt(t.payload.address),parseInt(t.payload.quantity)).then(function(e){i.activateSendingOnSuccess(n,a,o,e,t)}).catch(function(e){i.activateSendingOnFailure(n,o,new Error(e.message),t),n.modbusErrorHandling(e)})},de.biancoroyal.modbus.core.client.readModbusByFunctionCode=function(e,n,t,a){var o=de.biancoroyal.modbus.core.client,i=de.biancoroyal.modbus.core.client.getLogFunction(e);switch(parseInt(n.payload.fc)){case 1:o.readModbusByFunctionCodeOne(e,n,t,a);break;case 2:o.readModbusByFunctionCodeTwo(e,n,t,a);break;case 3:o.readModbusByFunctionCodeThree(e,n,t,a);break;case 4:o.readModbusByFunctionCodeFour(e,n,t,a);break;default:o.activateSendingOnFailure(e,a,new Error("Function Code Unknown"),n),i("Function Code Unknown %s",n.payload.fc)}},de.biancoroyal.modbus.core.client.readModbus=function(n,t,e,a){var o=de.biancoroyal.modbus.core.client,i=de.biancoroyal.modbus.core.client.getLogFunction(n),r=1;if(n.client){if(n.client._port&&n.client._port._client&&!n.client._port._client.readable){if(!n.connectClient())return void o.activateSendingOnFailure(n,a,new Error("Modbus-Read Error from client connecting"),t);r=500}setTimeout(function(){n.bufferCommands?n.queueLog(JSON.stringify({info:"read msg via Modbus",message:t.payload,queueUnitId:t.queueUnitId,timeout:n.client.getTimeout(),state:n.actualServiceState.value})):"tcp"!==n.clienttype&&n.stateService.send("READ"),n.setUnitIdFromPayload(t),n.client.setTimeout(n.clientTimeout);try{o.readModbusByFunctionCode(n,t,e,a)}catch(e){o.activateSendingOnFailure(n,a,e,t),i(e.message),n.modbusErrorHandling(e)}},r)}else i("Client Not Ready As Object On Reading Modbus")},de.biancoroyal.modbus.core.client.writeModbusByFunctionCodeFive=function(t,a,o,i){var r=de.biancoroyal.modbus.core.client;a.payload.value?a.payload.value=!0:a.payload.value=!1,t.client.writeCoil(parseInt(a.payload.address),a.payload.value).then(function(e){r.activateSendingOnSuccess(t,o,i,e,a)}).catch(function(e){var n;0===t.client.getID()?(n={address:parseInt(a.payload.address),value:parseInt(a.payload.value)},r.activateSendingOnSuccess(t,o,i,n,a)):(r.activateSendingOnFailure(t,i,e,a),t.modbusErrorHandling(e))})},de.biancoroyal.modbus.core.client.writeModbusByFunctionCodeFifteen=function(t,a,o,i){var r=de.biancoroyal.modbus.core.client;parseInt(a.payload.value.length)!==parseInt(a.payload.quantity)?r.activateSendingOnFailure(t,i,new Error("Quantity should be less or equal to coil payload array length: "+a.payload.value.length+" Addr: "+a.payload.address+" Q: "+a.payload.quantity),a):t.client.writeCoils(parseInt(a.payload.address),a.payload.value).then(function(e){r.activateSendingOnSuccess(t,o,i,e,a)}).catch(function(e){var n;0===t.client.getID()?(n={address:parseInt(a.payload.address),value:parseInt(a.payload.value)},r.activateSendingOnSuccess(t,o,i,n,a)):(r.activateSendingOnFailure(t,i,e,a),t.modbusErrorHandling(e))})},de.biancoroyal.modbus.core.client.writeModbusByFunctionCodeSix=function(t,a,o,i){var r=de.biancoroyal.modbus.core.client;t.client.writeRegister(parseInt(a.payload.address),parseInt(a.payload.value)).then(function(e){r.activateSendingOnSuccess(t,o,i,e,a)}).catch(function(e){var n;0===t.client.getID()?(n={address:parseInt(a.payload.address),value:parseInt(a.payload.value)},r.activateSendingOnSuccess(t,o,i,n,a)):(r.activateSendingOnFailure(t,i,e,a),t.modbusErrorHandling(e))})},de.biancoroyal.modbus.core.client.writeModbusByFunctionCodeSixteen=function(t,a,o,i){var r=de.biancoroyal.modbus.core.client;parseInt(a.payload.value.length)!==parseInt(a.payload.quantity)?r.activateSendingOnFailure(t,i,new Error("Quantity should be less or equal to register payload array length: "+a.payload.value.length+" Addr: "+a.payload.address+" Q: "+a.payload.quantity),a):t.client.writeRegisters(parseInt(a.payload.address),a.payload.value).then(function(e){r.activateSendingOnSuccess(t,o,i,e,a)}).catch(function(e){var n;0===t.client.getID()?(n={address:parseInt(a.payload.address),value:parseInt(a.payload.value)},r.activateSendingOnSuccess(t,o,i,n,a)):(r.activateSendingOnFailure(t,i,e,a),t.modbusErrorHandling(e))})},de.biancoroyal.modbus.core.client.writeModbus=function(n,t,e,a){var o=de.biancoroyal.modbus.core.client,i=de.biancoroyal.modbus.core.client.getLogFunction(n),r=1;if(n.client){if(n.client._port&&n.client._port._client&&!n.client._port._client.writable){if(!n.connectClient())return void o.activateSendingOnFailure(n,a,new Error("Modbus-Read Error from client connecting"),t);r=500}setTimeout(function(){n.bufferCommands?n.queueLog(JSON.stringify({info:"write msg",message:t.payload,queueUnitId:t.queueUnitId,timeout:n.client.getTimeout(),state:n.actualServiceState.value})):"tcp"!==n.clienttype&&n.stateService.send("WRITE"),n.setUnitIdFromPayload(t),n.client.setTimeout(n.clientTimeout);try{switch(parseInt(t.payload.fc)){case 15:o.writeModbusByFunctionCodeFifteen(n,t,e,a);break;case 5:o.writeModbusByFunctionCodeFive(n,t,e,a);break;case 16:o.writeModbusByFunctionCodeSixteen(n,t,e,a);break;case 6:o.writeModbusByFunctionCodeSix(n,t,e,a);break;default:o.activateSendingOnFailure(n,a,new Error("Function Code Unknown"),t),i("Function Code Unknown %s",t.payload.fc)}}catch(e){o.activateSendingOnFailure(n,a,e,t),i(e.message),n.modbusErrorHandling(e)}},r)}else i("Client Not Ready As Object On Writing Modbus")},de.biancoroyal.modbus.core.client.setNewTCPNodeSettings=function(e,n){e.clienttype="tcp",e.tcpHost=n.payload.tcpHost||e.tcpHost,e.tcpPort=n.payload.tcpPort||e.tcpPort,e.tcpType=n.payload.tcpType||e.tcpType},de.biancoroyal.modbus.core.client.setNewSerialNodeSettings=function(e,n){n.payload.serialPort&&(e.serialPort=n.payload.serialPort||e.serialPort),n.payload.serialBaudrate&&(e.serialBaudrate=parseInt(n.payload.serialBaudrate)||e.serialBaudrate),e.clienttype="serial",e.serialDatabits=n.payload.serialDatabits||e.serialDatabits,e.serialStopbits=n.payload.serialStopbits||e.serialStopbits,e.serialParity=n.payload.serialParity||e.serialParity,e.serialType=n.payload.serialType||e.serialType,n.payload.serialAsciiResponseStartDelimiter&&"string"==typeof n.payload.serialAsciiResponseStartDelimiter?e.serialAsciiResponseStartDelimiter=parseInt(n.payload.serialAsciiResponseStartDelimiter,16):e.serialAsciiResponseStartDelimiter=n.payload.serialAsciiResponseStartDelimiter||e.serialAsciiResponseStartDelimiter,n.payload.serialConnectionDelay&&(e.serialConnectionDelay=parseInt(n.payload.serialConnectionDelay)||e.serialConnectionDelay)},de.biancoroyal.modbus.core.client.setNewNodeOptionalSettings=function(e,n){var t=de.biancoroyal.modbus.core.client.getLogFunction(e);try{var a=parseInt(n.payload.unitId);e.checkUnitId(a,e.clienttype)||(a=e.unit_id),e.unit_id=a}catch(e){t(e.message)}n.payload.commandDelay&&(e.commandDelay=parseInt(n.payload.commandDelay)||e.commandDelay),n.payload.clientTimeout&&(e.clientTimeout=parseInt(n.payload.clientTimeout)||e.clientTimeout),n.payload.reconnectTimeout&&(e.reconnectTimeout=parseInt(n.payload.reconnectTimeout)||e.reconnectTimeout)},de.biancoroyal.modbus.core.client.setNewNodeSettings=function(e,n){var t=de.biancoroyal.modbus.core.client.getLogFunction(e),a=de.biancoroyal.modbus.core.client;if(!n)return t("New Connection message invalid."),!1;switch(n.payload.connectorType.toUpperCase()){case"TCP":a.setNewTCPNodeSettings(e,n),t("New Connection TCP Settings "+e.tcpHost+" "+e.tcpPort+" "+e.tcpType);break;case"SERIAL":a.setNewSerialNodeSettings(e,n),t("New Connection Serial Settings "+e.serialPort+" "+e.serialBaudrate+" "+e.serialType);break;default:t("Unknown Dynamic Reconnect Type "+n.payload.connectorType)}return a.setNewNodeOptionalSettings(e,n),!0},de.biancoroyal.modbus.core.client.messageAllowedStates=["activated","queueing","sending","empty","connected"],module.exports=de.biancoroyal.modbus.core.client;
"use strict";require("source-map-support").install();var de=de||{biancoroyal:{modbus:{core:{client:{}}}}};de.biancoroyal.modbus.core.client.internalDebug=de.biancoroyal.modbus.core.client.internalDebug||require("debug")("contribModbus:core:client"),de.biancoroyal.modbus.core.client.internalDebugFSM=de.biancoroyal.modbus.core.client.internalDebugFSM||require("debug")("contribModbus:core:client:fsm"),de.biancoroyal.modbus.core.client.modbusSerialDebug=de.biancoroyal.modbus.core.client.modbusSerialDebug||require("debug")("modbus-serial"),de.biancoroyal.modbus.core.client.XStateFSM=de.biancoroyal.modbus.core.client.XStateFSM||require("@xstate/fsm"),de.biancoroyal.modbus.core.client.stateLogEnabled=de.biancoroyal.modbus.core.client.stateLogEnabled||!1,de.biancoroyal.modbus.core.client.networkErrors=["ESOCKETTIMEDOUT","ETIMEDOUT","ECONNRESET","ENETRESET","ECONNABORTED","ECONNREFUSED","ENETUNREACH","ENOTCONN","ESHUTDOWN","EHOSTDOWN","ENETDOWN","EWOULDBLOCK","EAGAIN","EHOSTUNREACH"],de.biancoroyal.modbus.core.client.createStateMachineService=function(){return this.stateLogEnabled=!1,this.XStateFSM.createMachine({id:"modbus",initial:"new",states:{new:{on:{INIT:"init",BREAK:"broken",STOP:"stopped"}},broken:{on:{INIT:"init",STOP:"stopped",FAILURE:"failed",ACTIVATE:"activated",RECONNECT:"reconnecting"}},reconnecting:{on:{INIT:"init",STOP:"stopped"}},init:{on:{OPENSERIAL:"opened",CONNECT:"connected",BREAK:"broken",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},opened:{on:{CONNECT:"connected",BREAK:"broken",FAILURE:"failed",CLOSE:"closed",STOP:"stopped",SWITCH:"switch"}},connected:{on:{CLOSE:"closed",ACTIVATE:"activated",QUEUE:"queueing",BREAK:"broken",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},activated:{on:{READ:"reading",WRITE:"writing",QUEUE:"queueing",BREAK:"broken",CLOSE:"closed",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},queueing:{on:{ACTIVATE:"activated",SEND:"sending",READ:"reading",WRITE:"writing",EMPTY:"empty",BREAK:"broken",CLOSE:"closed",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},empty:{on:{QUEUE:"queueing",BREAK:"broken",FAILURE:"failed",CLOSE:"closed",STOP:"stopped",SWITCH:"switch"}},sending:{on:{ACTIVATE:"activated",READ:"reading",WRITE:"writing",BREAK:"broken",FAILURE:"failed",STOP:"stopped",SWITCH:"switch"}},reading:{on:{ACTIVATE:"activated",BREAK:"broken",FAILURE:"failed",STOP:"stopped"}},writing:{on:{ACTIVATE:"activated",BREAK:"broken",FAILURE:"failed",STOP:"stopped"}},closed:{on:{FAILURE:"failed",BREAK:"broken",CONNECT:"connected",RECONNECT:"reconnecting",INIT:"init",STOP:"stopped",SWITCH:"switch"}},failed:{on:{CLOSE:"closed",BREAK:"broken",STOP:"stopped",SWITCH:"switch"}},switch:{on:{CLOSE:"closed",BREAK:"broken",STOP:"stopped"}},stopped:{on:{NEW:"new",STOP:"stopped"}}}})},de.biancoroyal.modbus.core.client.getActualUnitId=function(e,n){return n.payload&&Number.isInteger(n.payload.unitid)?parseInt(n.payload.unitid):Number.isInteger(n.queueUnitId)?parseInt(n.queueUnitId):parseInt(e.unit_id)||0},de.biancoroyal.modbus.core.client.startStateService=function(e){return this.XStateFSM.interpret(e).start()},de.biancoroyal.modbus.core.client.checkUnitId=function(e,n){return"tcp"===n?0<=e&&e<=255:0<=e&&e<=247},de.biancoroyal.modbus.core.client.getLogFunction=function(e){return e.internalDebugLog||de.biancoroyal.modbus.core.client.internalDebug},de.biancoroyal.modbus.core.client.activateSendingOnSuccess=function(e,n,t,a,o){e.activateSending(o).then(function(){n(a,o)}).catch(function(e){t(e,o)}).finally(function(){e.stateService.send("ACTIVATE")})},de.biancoroyal.modbus.core.client.activateSendingOnFailure=function(e,n,t,a){e.activateSending(a).then(function(){n(t,a)}).catch(function(e){n(e,a)}).finally(function(){e.stateService.send("ACTIVATE")})},de.biancoroyal.modbus.core.client.readModbusByFunctionCodeOne=function(n,t,a,o){var i=de.biancoroyal.modbus.core.client;n.client.readCoils(parseInt(t.payload.address),parseInt(t.payload.quantity)).then(function(e){i.activateSendingOnSuccess(n,a,o,e,t)}).catch(function(e){i.activateSendingOnFailure(n,o,new Error(e.message),t),n.modbusErrorHandling(e)})},de.biancoroyal.modbus.core.client.readModbusByFunctionCodeTwo=function(n,t,a,o){var i=de.biancoroyal.modbus.core.client;n.client.readDiscreteInputs(parseInt(t.payload.address),parseInt(t.payload.quantity)).then(function(e){i.activateSendingOnSuccess(n,a,o,e,t)}).catch(function(e){i.activateSendingOnFailure(n,o,new Error(e.message),t),n.modbusErrorHandling(e)})},de.biancoroyal.modbus.core.client.readModbusByFunctionCodeThree=function(n,t,a,o){var i=de.biancoroyal.modbus.core.client;n.client.readHoldingRegisters(parseInt(t.payload.address),parseInt(t.payload.quantity)).then(function(e){i.activateSendingOnSuccess(n,a,o,e,t)}).catch(function(e){i.activateSendingOnFailure(n,o,new Error(e.message),t),n.modbusErrorHandling(e)})},de.biancoroyal.modbus.core.client.readModbusByFunctionCodeFour=function(n,t,a,o){var i=de.biancoroyal.modbus.core.client;n.client.readInputRegisters(parseInt(t.payload.address),parseInt(t.payload.quantity)).then(function(e){i.activateSendingOnSuccess(n,a,o,e,t)}).catch(function(e){i.activateSendingOnFailure(n,o,new Error(e.message),t),n.modbusErrorHandling(e)})},de.biancoroyal.modbus.core.client.sendCustomFunctionCode=function(n,t,a,o){var i=de.biancoroyal.modbus.core.client;n.client.sendCustomFc(t.payload.unitid,t.payload.fc,t.payload.requestCard,t.payload.responseCard).then(function(e){i.activateSendingOnSuccess(n,a,o,e,t)}).catch(function(e){i.activateSendingOnFailure(n,o,new Error(e.message),t),n.modbusErrorHandling(e)})},de.biancoroyal.modbus.core.client.readModbusByFunctionCode=function(e,n,t,a){var o=de.biancoroyal.modbus.core.client,i=de.biancoroyal.modbus.core.client.getLogFunction(e);switch(parseInt(n.payload.fc)){case 1:o.readModbusByFunctionCodeOne(e,n,t,a);break;case 2:o.readModbusByFunctionCodeTwo(e,n,t,a);break;case 3:o.readModbusByFunctionCodeThree(e,n,t,a);break;case 4:o.readModbusByFunctionCodeFour(e,n,t,a);break;default:o.activateSendingOnFailure(e,a,new Error("Function Code Unknown"),n),i("Function Code Unknown %s",n.payload.fc)}},de.biancoroyal.modbus.core.client.customModbusMessage=function(n,t,e,a){var o=de.biancoroyal.modbus.core.client,i=de.biancoroyal.modbus.core.client.getLogFunction(n),c=1;if(n.client){if(n.client._port&&n.client._port._client&&!n.client._port._client.readable){if(!n.connectClient())return void o.activateSendingOnFailure(n,a,new Error("Modbus-Read Error from client connecting"),t);c=500}setTimeout(function(){n.bufferCommands?n.queueLog(JSON.stringify({info:"read msg via Modbus",message:t.payload,queueUnitId:t.queueUnitId,timeout:n.client.getTimeout(),state:n.actualServiceState.value})):"tcp"!==n.clienttype&&n.stateService.send("READ"),n.setUnitIdFromPayload(t),n.client.setTimeout(n.clientTimeout);try{o.sendCustomFunctionCode(n,t,e,a)}catch(e){o.activateSendingOnFailure(n,a,e,t),i(e.message),n.modbusErrorHandling(e)}},c)}else i("Client Not Ready As Object On Reading Modbus")},de.biancoroyal.modbus.core.client.readModbus=function(n,t,e,a){var o=de.biancoroyal.modbus.core.client,i=de.biancoroyal.modbus.core.client.getLogFunction(n),c=1;if(n.client){if(n.client._port&&n.client._port._client&&!n.client._port._client.readable){if(!n.connectClient())return void o.activateSendingOnFailure(n,a,new Error("Modbus-Read Error from client connecting"),t);c=500}setTimeout(function(){n.bufferCommands?n.queueLog(JSON.stringify({info:"read msg via Modbus",message:t.payload,queueUnitId:t.queueUnitId,timeout:n.client.getTimeout(),state:n.actualServiceState.value})):"tcp"!==n.clienttype&&n.stateService.send("READ"),n.setUnitIdFromPayload(t),n.client.setTimeout(n.clientTimeout);try{o.readModbusByFunctionCode(n,t,e,a)}catch(e){o.activateSendingOnFailure(n,a,e,t),i(e.message),n.modbusErrorHandling(e)}},c)}else i("Client Not Ready As Object On Reading Modbus")},de.biancoroyal.modbus.core.client.writeModbusByFunctionCodeFive=function(t,a,o,i){var c=de.biancoroyal.modbus.core.client;a.payload.value?a.payload.value=!0:a.payload.value=!1,t.client.writeCoil(parseInt(a.payload.address),a.payload.value).then(function(e){c.activateSendingOnSuccess(t,o,i,e,a)}).catch(function(e){var n;0===t.client.getID()?(n={address:parseInt(a.payload.address),value:parseInt(a.payload.value)},c.activateSendingOnSuccess(t,o,i,n,a)):(c.activateSendingOnFailure(t,i,e,a),t.modbusErrorHandling(e))})},de.biancoroyal.modbus.core.client.writeModbusByFunctionCodeFifteen=function(t,a,o,i){var c=de.biancoroyal.modbus.core.client;parseInt(a.payload.value.length)!==parseInt(a.payload.quantity)?c.activateSendingOnFailure(t,i,new Error("Quantity should be less or equal to coil payload array length: "+a.payload.value.length+" Addr: "+a.payload.address+" Q: "+a.payload.quantity),a):t.client.writeCoils(parseInt(a.payload.address),a.payload.value).then(function(e){c.activateSendingOnSuccess(t,o,i,e,a)}).catch(function(e){var n;0===t.client.getID()?(n={address:parseInt(a.payload.address),value:parseInt(a.payload.value)},c.activateSendingOnSuccess(t,o,i,n,a)):(c.activateSendingOnFailure(t,i,e,a),t.modbusErrorHandling(e))})},de.biancoroyal.modbus.core.client.writeModbusByFunctionCodeSix=function(t,a,o,i){var c=de.biancoroyal.modbus.core.client;t.client.writeRegister(parseInt(a.payload.address),parseInt(a.payload.value)).then(function(e){c.activateSendingOnSuccess(t,o,i,e,a)}).catch(function(e){var n;0===t.client.getID()?(n={address:parseInt(a.payload.address),value:parseInt(a.payload.value)},c.activateSendingOnSuccess(t,o,i,n,a)):(c.activateSendingOnFailure(t,i,e,a),t.modbusErrorHandling(e))})},de.biancoroyal.modbus.core.client.writeModbusByFunctionCodeSixteen=function(t,a,o,i){var c=de.biancoroyal.modbus.core.client;parseInt(a.payload.value.length)!==parseInt(a.payload.quantity)?c.activateSendingOnFailure(t,i,new Error("Quantity should be less or equal to register payload array length: "+a.payload.value.length+" Addr: "+a.payload.address+" Q: "+a.payload.quantity),a):t.client.writeRegisters(parseInt(a.payload.address),a.payload.value).then(function(e){c.activateSendingOnSuccess(t,o,i,e,a)}).catch(function(e){var n;0===t.client.getID()?(n={address:parseInt(a.payload.address),value:parseInt(a.payload.value)},c.activateSendingOnSuccess(t,o,i,n,a)):(c.activateSendingOnFailure(t,i,e,a),t.modbusErrorHandling(e))})},de.biancoroyal.modbus.core.client.writeModbus=function(n,t,e,a){var o=de.biancoroyal.modbus.core.client,i=de.biancoroyal.modbus.core.client.getLogFunction(n),c=1;if(n.client){if(n.client._port&&n.client._port._client&&!n.client._port._client.writable){if(!n.connectClient())return void o.activateSendingOnFailure(n,a,new Error("Modbus-Read Error from client connecting"),t);c=500}setTimeout(function(){n.bufferCommands?n.queueLog(JSON.stringify({info:"write msg",message:t.payload,queueUnitId:t.queueUnitId,timeout:n.client.getTimeout(),state:n.actualServiceState.value})):"tcp"!==n.clienttype&&n.stateService.send("WRITE"),n.setUnitIdFromPayload(t),n.client.setTimeout(n.clientTimeout);try{switch(parseInt(t.payload.fc)){case 15:o.writeModbusByFunctionCodeFifteen(n,t,e,a);break;case 5:o.writeModbusByFunctionCodeFive(n,t,e,a);break;case 16:o.writeModbusByFunctionCodeSixteen(n,t,e,a);break;case 6:o.writeModbusByFunctionCodeSix(n,t,e,a);break;default:o.activateSendingOnFailure(n,a,new Error("Function Code Unknown"),t),i("Function Code Unknown %s",t.payload.fc)}}catch(e){o.activateSendingOnFailure(n,a,e,t),i(e.message),n.modbusErrorHandling(e)}},c)}else i("Client Not Ready As Object On Writing Modbus")},de.biancoroyal.modbus.core.client.setNewTCPNodeSettings=function(e,n){e.clienttype="tcp",e.tcpHost=n.payload.tcpHost||e.tcpHost,e.tcpPort=n.payload.tcpPort||e.tcpPort,e.tcpType=n.payload.tcpType||e.tcpType},de.biancoroyal.modbus.core.client.setNewSerialNodeSettings=function(e,n){n.payload.serialPort&&(e.serialPort=n.payload.serialPort||e.serialPort),n.payload.serialBaudrate&&(e.serialBaudrate=parseInt(n.payload.serialBaudrate)||e.serialBaudrate),e.clienttype="serial",e.serialDatabits=n.payload.serialDatabits||e.serialDatabits,e.serialStopbits=n.payload.serialStopbits||e.serialStopbits,e.serialParity=n.payload.serialParity||e.serialParity,e.serialType=n.payload.serialType||e.serialType,n.payload.serialAsciiResponseStartDelimiter&&"string"==typeof n.payload.serialAsciiResponseStartDelimiter?e.serialAsciiResponseStartDelimiter=parseInt(n.payload.serialAsciiResponseStartDelimiter,16):e.serialAsciiResponseStartDelimiter=n.payload.serialAsciiResponseStartDelimiter||e.serialAsciiResponseStartDelimiter,n.payload.serialConnectionDelay&&(e.serialConnectionDelay=parseInt(n.payload.serialConnectionDelay)||e.serialConnectionDelay)},de.biancoroyal.modbus.core.client.setNewNodeOptionalSettings=function(e,n){var t=de.biancoroyal.modbus.core.client.getLogFunction(e);try{var a=parseInt(n.payload.unitId);e.checkUnitId(a,e.clienttype)||(a=e.unit_id),e.unit_id=a}catch(e){t(e.message)}n.payload.commandDelay&&(e.commandDelay=parseInt(n.payload.commandDelay)||e.commandDelay),n.payload.clientTimeout&&(e.clientTimeout=parseInt(n.payload.clientTimeout)||e.clientTimeout),n.payload.reconnectTimeout&&(e.reconnectTimeout=parseInt(n.payload.reconnectTimeout)||e.reconnectTimeout)},de.biancoroyal.modbus.core.client.setNewNodeSettings=function(e,n){var t=de.biancoroyal.modbus.core.client.getLogFunction(e),a=de.biancoroyal.modbus.core.client;if(!n)return t("New Connection message invalid."),!1;switch(n.payload.connectorType.toUpperCase()){case"TCP":a.setNewTCPNodeSettings(e,n),t("New Connection TCP Settings "+e.tcpHost+" "+e.tcpPort+" "+e.tcpType);break;case"SERIAL":a.setNewSerialNodeSettings(e,n),t("New Connection Serial Settings "+e.serialPort+" "+e.serialBaudrate+" "+e.serialType);break;default:t("Unknown Dynamic Reconnect Type "+n.payload.connectorType)}return a.setNewNodeOptionalSettings(e,n),!0},de.biancoroyal.modbus.core.client.messageAllowedStates=["activated","queueing","sending","empty","connected"],module.exports=de.biancoroyal.modbus.core.client;
//# sourceMappingURL=../maps/core/modbus-client-core.js.map

@@ -1,2 +0,2 @@

"use strict";module.exports=function(a){require("source-map-support").install();var c=require("./modbus-basics"),u=require("./core/modbus-client-core"),l=require("./core/modbus-queue-core"),d=require("debug")("contribModbus:config:client"),m=require("underscore");a.nodes.registerType("modbus-client",function(e){a.nodes.createNode(this,e);var t=require("modbus-serial"),n=500,i=" Get More About It By Logging",r=(this.clienttype=e.clienttype,void 0===e.parallelUnitIdsAllowed?this.bufferCommands=!0:this.bufferCommands=e.bufferCommands,this.queueLogEnabled=e.queueLogEnabled,this.stateLogEnabled=e.stateLogEnabled,this.failureLogEnabled=e.failureLogEnabled,this.tcpHost=e.tcpHost,this.tcpPort=parseInt(e.tcpPort)||502,this.tcpType=e.tcpType,this.serialPort=e.serialPort,this.serialBaudrate=e.serialBaudrate,this.serialDatabits=e.serialDatabits,this.serialStopbits=e.serialStopbits,this.serialParity=e.serialParity,this.serialType=e.serialType,this.serialConnectionDelay=parseInt(e.serialConnectionDelay)||n,this.serialAsciiResponseStartDelimiter=e.serialAsciiResponseStartDelimiter||"0x3A",this.unit_id=parseInt(e.unit_id),this.commandDelay=parseInt(e.commandDelay)||1,this.clientTimeout=parseInt(e.clientTimeout)||1e3,this.reconnectTimeout=parseInt(e.reconnectTimeout)||2e3,this.reconnectOnTimeout=e.reconnectOnTimeout,void 0===e.parallelUnitIdsAllowed?this.parallelUnitIdsAllowed=!0:this.parallelUnitIdsAllowed=e.parallelUnitIdsAllowed,this.showErrors=e.showErrors,this.showWarnings=e.showWarnings,this.showLogs=e.showLogs,this);function o(e){a.settings.verbose&&r.showWarnings&&(r.updateServerinfo(),r.warn("Client -> "+e+" "+r.serverInfo))}function s(e){a.settings.verbose&&r.showLogs&&u.internalDebug("Client -> "+e+" "+r.serverInfo)}r.isFirstInitOfConnection=!0,r.closingModbus=!1,r.client=null,r.bufferCommandList=new Map,r.sendingAllowed=new Map,r.unitSendingAllowed=[],r.messageAllowedStates=u.messageAllowedStates,r.serverInfo="",r.stateMachine=null,r.stateService=null,r.stateMachine=u.createStateMachineService(),r.actualServiceState=r.stateMachine.initialState,r.actualServiceStateBefore=r.actualServiceState,r.stateService=u.startStateService(r.stateMachine),r.reconnectTimeoutId=0,r.serialSendingAllowed=!1,r.internalDebugLog=d,l.queueSerialLockCommand(r),r.setDefaultUnitId=function(){"tcp"===this.clienttype?r.unit_id=0:r.unit_id=1},r.setUnitIdFromPayload=function(e){var t=u.getActualUnitId(r,e);u.checkUnitId(t,r.clienttype)||r.setDefaultUnitId(),r.client.setID(t),e.unitId=t},!Number.isNaN(r.unit_id)&&u.checkUnitId(r.unit_id,r.clienttype)||r.setDefaultUnitId(),r.updateServerinfo=function(){"tcp"===r.clienttype?r.serverInfo=" TCP@"+r.tcpHost+":"+r.tcpPort:r.serverInfo=" Serial@"+r.serialPort+":"+r.serialBaudrate+"bit/s",r.serverInfo+=" default Unit-Id: "+r.unit_id},r.errorProtocolMsg=function(e,t){r.showErrors&&c.logMsgError(r,e,t)},r.queueLog=function(e){r.bufferCommands&&r.queueLogEnabled&&s(e)},r.stateService.subscribe(function(e){var t;if(r.actualServiceStateBefore=r.actualServiceState,r.actualServiceState=e,t=e.value,r.stateLogEnabled&&s(t),e.value&&void 0!==r.actualServiceState.value&&r.actualServiceStateBefore.value!==r.actualServiceState.value){if(e.matches("init")){o("fsm init state after "+r.actualServiceStateBefore.value),r.updateServerinfo(),l.initQueue(r),r.reconnectTimeoutId=0;try{r.isFirstInitOfConnection?(r.isFirstInitOfConnection=!1,o("first fsm init in 500 ms"),setTimeout(r.connectClient,n)):(o("fsm init in "+r.reconnectTimeout+" ms"),setTimeout(r.connectClient,r.reconnectTimeout))}catch(e){r.error(e,{payload:"client connection error "+i})}r.emit("mbinit")}e.matches("connected")&&(o("fsm connected after state "+r.actualServiceStateBefore.value+i),l.queueSerialUnlockCommand(r),r.emit("mbconnected")),e.matches("activated")&&(r.emit("mbactive"),r.bufferCommands)&&!l.checkQueuesAreEmpty(r)&&r.stateService.send("QUEUE"),e.matches("queueing")&&("tcp"===r.clienttype?r.stateService.send("SEND"):r.serialSendingAllowed&&(l.queueSerialLockCommand(r),r.stateService.send("SEND"))),e.matches("sending")&&(setTimeout(function(){l.dequeueCommand(r)},r.commandDelay),r.emit("mbqueue")),e.matches("opened")&&(l.queueSerialUnlockCommand(r),r.emit("mbopen")),e.matches("switch")&&(r.emit("mbswitch"),r.stateService.send("CLOSE")),e.matches("closed")&&(r.emit("mbclosed"),r.stateService.send("RECONNECT")),e.matches("stopped")&&(o("stopped state without reconnecting"),r.emit("mbclosed")),e.matches("failed")&&(o("fsm failed state after "+r.actualServiceStateBefore.value+i),r.emit("mberror","Modbus Failure On State "+r.actualServiceStateBefore.value+i),r.stateService.send("BREAK")),e.matches("broken")&&(o("fsm broken state after "+r.actualServiceStateBefore.value+i),r.emit("mbbroken","Modbus Broken On State "+r.actualServiceStateBefore.value+i),r.reconnectOnTimeout?r.stateService.send("RECONNECT"):r.stateService.send("ACTIVATE")),e.matches("reconnecting")&&(o("fsm reconnect state after "+r.actualServiceStateBefore.value+i),l.queueSerialLockCommand(r),r.emit("mbreconnecting"),r.reconnectTimeout<=0&&(r.reconnectTimeout=2e3),setTimeout(function(){r.reconnectTimeoutId=0,r.stateService.send("INIT")},r.reconnectTimeout))}}),r.connectClient=function(){try{if(r.client)try{r.client.close(function(){s("connection closed")}),s("connection close sent")}catch(e){s(e.message)}if(r.client=null,r.client=new t,r.client.on("error",function(e){r.modbusErrorHandling(e),c.setNodeStatusTo("error",r)}),r.clientTimeout||(r.clientTimeout=1e3),r.reconnectTimeout||(r.reconnectTimeout=2e3),"tcp"===r.clienttype){if(!u.checkUnitId(r.unit_id,r.clienttype))return r.error(new Error("wrong unit-id (0..255)"),{payload:r.unit_id}),r.stateService.send("FAILURE"),!1;try{switch(r.tcpType){case"C701":s("C701 port UDP bridge"),r.client.connectC701(r.tcpHost,{port:r.tcpPort,autoOpen:!0}).then(r.setTCPConnectionOptions).then(r.setTCPConnected).catch(function(e){return r.modbusTcpErrorHandling(e),!1});break;case"TELNET":s("Telnet port"),r.client.connectTelnet(r.tcpHost,{port:r.tcpPort,autoOpen:!0}).then(r.setTCPConnectionOptions).catch(function(e){return r.modbusTcpErrorHandling(e),!1});break;case"TCP-RTU-BUFFERED":s("TCP RTU buffered port"),r.client.connectTcpRTUBuffered(r.tcpHost,{port:r.tcpPort,autoOpen:!0}).then(r.setTCPConnectionOptions).catch(function(e){return r.modbusTcpErrorHandling(e),!1});break;default:s("TCP port"),r.client.connectTCP(r.tcpHost,{port:r.tcpPort,autoOpen:!0}).then(r.setTCPConnectionOptions).catch(function(e){return r.modbusTcpErrorHandling(e),!1})}}catch(e){return r.modbusTcpErrorHandling(e),!1}}else{if(!u.checkUnitId(r.unit_id,r.clienttype))return r.error(new Error("wrong unit-id serial (0..247)"),{payload:r.unit_id}),r.stateService.send("FAILURE"),!1;if(r.serialConnectionDelay||(r.serialConnectionDelay=n),!r.serialPort)return r.error(new Error("wrong serial port"),{payload:r.serialPort}),r.stateService.send("FAILURE"),!1;var e={baudRate:parseInt(r.serialBaudrate),dataBits:parseInt(r.serialDatabits),stopBits:parseInt(r.serialStopbits),parity:r.serialParity,autoOpen:!1};try{switch(r.serialType){case"ASCII":s("ASCII port serial"),r.serialAsciiResponseStartDelimiter&&"string"==typeof r.serialAsciiResponseStartDelimiter?e.startOfSlaveFrameChar=parseInt(r.serialAsciiResponseStartDelimiter,16):e.startOfSlaveFrameChar=r.serialAsciiResponseStartDelimiter,s("Using response delimiter: 0x"+e.startOfSlaveFrameChar.toString(16)),r.client.connectAsciiSerial(r.serialPort,e).then(r.setSerialConnectionOptions).catch(function(e){return r.modbusSerialErrorHandling(e),!1});break;case"RTU":s("RTU port serial"),r.client.connectRTU(r.serialPort,e).then(r.setSerialConnectionOptions).catch(function(e){return r.modbusSerialErrorHandling(e),!1});break;default:s("RTU buffered port serial"),r.client.connectRTUBuffered(r.serialPort,e).then(r.setSerialConnectionOptions).catch(function(e){return r.modbusSerialErrorHandling(e),!1})}}catch(e){return r.modbusSerialErrorHandling(e),!1}}}catch(e){return r.modbusErrorHandling(e),!1}return!0},r.setTCPConnectionOptions=function(){r.client.setID(r.unit_id),r.client.setTimeout(r.clientTimeout),r.stateService.send("CONNECT")},r.setTCPConnected=function(){u.modbusSerialDebug("modbus tcp connected on "+r.tcpHost)},r.setSerialConnectionOptions=function(){r.stateService.send("OPENSERIAL"),setTimeout(r.openSerialClient,parseInt(r.serialConnectionDelay))},r.modbusErrorHandling=function(e){l.queueSerialUnlockCommand(r),e.message?u.modbusSerialDebug("modbusErrorHandling:"+e.message):u.modbusSerialDebug("modbusErrorHandling:"+JSON.stringify(e)),e.errno&&u.networkErrors.includes(e.errno)&&r.stateService.send("FAILURE")},r.modbusTcpErrorHandling=function(e){l.queueSerialUnlockCommand(r),r.showErrors&&r.error(e),r.failureLogEnabled&&(e.message?u.modbusSerialDebug("modbusTcpErrorHandling:"+e.message):u.modbusSerialDebug("modbusTcpErrorHandling:"+JSON.stringify(e))),(e.errno&&u.networkErrors.includes(e.errno)||e.code&&u.networkErrors.includes(e.code))&&r.stateService.send("BREAK")},r.modbusSerialErrorHandling=function(e){l.queueSerialUnlockCommand(r),r.showErrors&&r.error(e),r.failureLogEnabled&&(e.message?u.modbusSerialDebug("modbusSerialErrorHandling:"+e.message):u.modbusSerialDebug("modbusSerialErrorHandling:"+JSON.stringify(e))),r.stateService.send("BREAK")},r.openSerialClient=function(){"opened"===r.actualServiceState.value?(s("time to open Unit "+r.unit_id),u.modbusSerialDebug("modbus connection opened"),r.client.setID(r.unit_id),r.client.setTimeout(parseInt(r.clientTimeout)),r.client._port.on("close",r.onModbusClose),r.stateService.send("CONNECT")):(s("wrong state on connect serial "+r.actualServiceState.value),u.modbusSerialDebug("modbus connection not opened state is %s",r.actualServiceState.value),r.stateService.send("BREAK"))},r.onModbusClose=function(){l.queueSerialUnlockCommand(r),o("Modbus closed port"),u.modbusSerialDebug("modbus closed port"),r.stateService.send("CLOSE")},r.on("readModbus",function(t,e,n){var i=r.actualServiceState;r.isInactive()?n(new Error("Client Not Ready To Read At State "+i.value),t):r.bufferCommands?l.pushToQueueByUnitId(r,u.readModbus,t,e,n).then(function(){r.queueLog(JSON.stringify({info:"queued read msg",message:t.payload,state:i.value,queueLength:r.bufferCommandList.get(t.queueUnitId).length}))}).catch(function(e){n(e,t)}).finally(function(){r.stateService.send("QUEUE")}):u.readModbus(r,t,e,n)}),r.on("writeModbus",function(t,e,n){var i=r.actualServiceState;r.isInactive()?n(new Error("Client Not Ready To Write At State "+i.value),t):r.bufferCommands?l.pushToQueueByUnitId(r,u.writeModbus,t,e,n).then(function(){r.queueLog(JSON.stringify({info:"queued write msg",message:t.payload,state:i.value,queueLength:r.bufferCommandList.get(t.queueUnitId).length}))}).catch(function(e){n(e,t)}).finally(function(){r.stateService.send("QUEUE")}):u.writeModbus(r,t,e,n)}),r.activateSending=function(n){return r.sendingAllowed.set(n.queueUnitId,!0),l.queueSerialUnlockCommand(r),new Promise(function(e,t){try{r.bufferCommands&&(r.queueLog(JSON.stringify({info:"queue response activate sending",queueLength:r.bufferCommandList.length,sendingAllowed:r.sendingAllowed.get(n.queueUnitId),serialSendingAllowed:r.serialSendingAllowed,queueUnitId:n.queueUnitId})),l.checkQueuesAreEmpty(r))&&r.stateService.send("EMPTY"),e()}catch(e){t(e)}})},s("initialized"),r.setMaxListeners(0),r.on("reconnect",function(){r.stateService.send("CLOSE")}),r.on("dynamicReconnect",function(e,t,n){if(c.invalidPayloadIn(e))throw new Error("Message Or Payload Not Valid");u.internalDebug("Dynamic Reconnect Parameters "+JSON.stringify(e.payload)),u.setNewNodeSettings(r,e)?t(e):n(new Error("Message Or Payload Not Valid"),e),u.internalDebug("Dynamic Reconnect Starts on actual state "+r.actualServiceState.value),r.stateService.send("SWITCH")}),r.on("close",function(t){var n=r.name||r.id;r.closingModbus=!0,s("stop fsm on close "+n),r.stateService.send("STOP"),s("close node "+n),r.internalDebugLog("close node "+n),r.removeAllListeners(),r.client?r.client.isOpen?r.client.close(function(e){s(e?"Connection closed with error "+n:"Connection closed well "+n),t()}):(s("connection was closed "+n),t()):(s("Connection closed simple "+n),t())}),r.registeredNodeList={},r.registerForModbus=function(e){r.registeredNodeList[e]=e,1===Object.keys(r.registeredNodeList).length&&(r.closingModbus=!1,r.stateService.send("NEW"),r.stateService.send("INIT")),r.emit("mbregister",e)},r.setStoppedState=function(e,t){r.stateService.send("STOP"),r.emit("mbderegister",e),t()},r.closeConnectionWithoutRegisteredNodes=function(e,t){0===Object.keys(r.registeredNodeList).length&&(r.closingModbus=!0,r.client)&&"stopped"!==r.actualServiceState.value&&r.client.isOpen?r.client.close(function(){r.setStoppedState(e,t)}):r.setStoppedState(e,t)},r.deregisterForModbus=function(t,n){try{delete r.registeredNodeList[t],r.closingModbus?(n(),r.emit("mbderegister",t)):r.closeConnectionWithoutRegisteredNodes(t,n)}catch(e){o(e.message+" on de-register node "+t),r.error(e),n()}},r.isInactive=function(){return m.isUndefined(r.actualServiceState)||-1===r.messageAllowedStates.indexOf(r.actualServiceState.value)},r.isActive=function(){return!r.isInactive()},r.isReadyToSend=function(e){return!!e.actualServiceState.matches("queueing")||(o("Client not ready to send"),!1)}}),a.httpAdmin.get("/modbus/serial/ports",a.auth.needsPermission("serial.read"),function(e,t){require("serialport").SerialPort.list().then(function(e){t.json(e)}).catch(function(e){t.json([e.message]),u.internalDebug(e.message)})})};
"use strict";module.exports=function(a){require("source-map-support").install();var c=require("./modbus-basics"),u=require("./core/modbus-client-core"),l=require("./core/modbus-queue-core"),d=require("debug")("contribModbus:config:client"),m=require("underscore");a.nodes.registerType("modbus-client",function(e){a.nodes.createNode(this,e);var t=require("@plus4nodered/modbus-serial"),n=500,i=" Get More About It By Logging",r=(this.clienttype=e.clienttype,void 0===e.parallelUnitIdsAllowed?this.bufferCommands=!0:this.bufferCommands=e.bufferCommands,this.queueLogEnabled=e.queueLogEnabled,this.stateLogEnabled=e.stateLogEnabled,this.failureLogEnabled=e.failureLogEnabled,this.tcpHost=e.tcpHost,this.tcpPort=parseInt(e.tcpPort)||502,this.tcpType=e.tcpType,this.serialPort=e.serialPort,this.serialBaudrate=e.serialBaudrate,this.serialDatabits=e.serialDatabits,this.serialStopbits=e.serialStopbits,this.serialParity=e.serialParity,this.serialType=e.serialType,this.serialConnectionDelay=parseInt(e.serialConnectionDelay)||n,this.serialAsciiResponseStartDelimiter=e.serialAsciiResponseStartDelimiter||"0x3A",this.unit_id=parseInt(e.unit_id),this.commandDelay=parseInt(e.commandDelay)||1,this.clientTimeout=parseInt(e.clientTimeout)||1e3,this.reconnectTimeout=parseInt(e.reconnectTimeout)||2e3,this.reconnectOnTimeout=e.reconnectOnTimeout,void 0===e.parallelUnitIdsAllowed?this.parallelUnitIdsAllowed=!0:this.parallelUnitIdsAllowed=e.parallelUnitIdsAllowed,this.showErrors=e.showErrors,this.showWarnings=e.showWarnings,this.showLogs=e.showLogs,this);function o(e){a.settings.verbose&&r.showWarnings&&(r.updateServerinfo(),r.warn("Client -> "+e+" "+r.serverInfo))}function s(e){a.settings.verbose&&r.showLogs&&u.internalDebug("Client -> "+e+" "+r.serverInfo)}r.isFirstInitOfConnection=!0,r.closingModbus=!1,r.client=null,r.bufferCommandList=new Map,r.sendingAllowed=new Map,r.unitSendingAllowed=[],r.messageAllowedStates=u.messageAllowedStates,r.serverInfo="",r.stateMachine=null,r.stateService=null,r.stateMachine=u.createStateMachineService(),r.actualServiceState=r.stateMachine.initialState,r.actualServiceStateBefore=r.actualServiceState,r.stateService=u.startStateService(r.stateMachine),r.reconnectTimeoutId=0,r.serialSendingAllowed=!1,r.internalDebugLog=d,l.queueSerialLockCommand(r),r.setDefaultUnitId=function(){"tcp"===this.clienttype?r.unit_id=0:r.unit_id=1},r.setUnitIdFromPayload=function(e){var t=u.getActualUnitId(r,e);u.checkUnitId(t,r.clienttype)||r.setDefaultUnitId(),r.client.setID(t),e.unitId=t},!Number.isNaN(r.unit_id)&&u.checkUnitId(r.unit_id,r.clienttype)||r.setDefaultUnitId(),r.updateServerinfo=function(){"tcp"===r.clienttype?r.serverInfo=" TCP@"+r.tcpHost+":"+r.tcpPort:r.serverInfo=" Serial@"+r.serialPort+":"+r.serialBaudrate+"bit/s",r.serverInfo+=" default Unit-Id: "+r.unit_id},r.errorProtocolMsg=function(e,t){r.showErrors&&c.logMsgError(r,e,t)},r.queueLog=function(e){r.bufferCommands&&r.queueLogEnabled&&s(e)},r.stateService.subscribe(function(e){var t;if(r.actualServiceStateBefore=r.actualServiceState,r.actualServiceState=e,t=e.value,r.stateLogEnabled&&s(t),e.value&&void 0!==r.actualServiceState.value&&r.actualServiceStateBefore.value!==r.actualServiceState.value){if(e.matches("init")){o("fsm init state after "+r.actualServiceStateBefore.value),r.updateServerinfo(),l.initQueue(r),r.reconnectTimeoutId=0;try{r.isFirstInitOfConnection?(r.isFirstInitOfConnection=!1,o("first fsm init in 500 ms"),setTimeout(r.connectClient,n)):(o("fsm init in "+r.reconnectTimeout+" ms"),setTimeout(r.connectClient,r.reconnectTimeout))}catch(e){r.error(e,{payload:"client connection error "+i})}r.emit("mbinit")}e.matches("connected")&&(o("fsm connected after state "+r.actualServiceStateBefore.value+i),l.queueSerialUnlockCommand(r),r.emit("mbconnected")),e.matches("activated")&&(r.emit("mbactive"),r.bufferCommands)&&!l.checkQueuesAreEmpty(r)&&r.stateService.send("QUEUE"),e.matches("queueing")&&("tcp"===r.clienttype?r.stateService.send("SEND"):r.serialSendingAllowed&&(l.queueSerialLockCommand(r),r.stateService.send("SEND"))),e.matches("sending")&&(setTimeout(function(){l.dequeueCommand(r)},r.commandDelay),r.emit("mbqueue")),e.matches("opened")&&(l.queueSerialUnlockCommand(r),r.emit("mbopen")),e.matches("switch")&&(r.emit("mbswitch"),r.stateService.send("CLOSE")),e.matches("closed")&&(r.emit("mbclosed"),r.stateService.send("RECONNECT")),e.matches("stopped")&&(o("stopped state without reconnecting"),r.emit("mbclosed")),e.matches("failed")&&(o("fsm failed state after "+r.actualServiceStateBefore.value+i),r.emit("mberror","Modbus Failure On State "+r.actualServiceStateBefore.value+i),r.stateService.send("BREAK")),e.matches("broken")&&(o("fsm broken state after "+r.actualServiceStateBefore.value+i),r.emit("mbbroken","Modbus Broken On State "+r.actualServiceStateBefore.value+i),r.reconnectOnTimeout?r.stateService.send("RECONNECT"):r.stateService.send("ACTIVATE")),e.matches("reconnecting")&&(o("fsm reconnect state after "+r.actualServiceStateBefore.value+i),l.queueSerialLockCommand(r),r.emit("mbreconnecting"),r.reconnectTimeout<=0&&(r.reconnectTimeout=2e3),setTimeout(function(){r.reconnectTimeoutId=0,r.stateService.send("INIT")},r.reconnectTimeout))}}),r.connectClient=function(){try{if(r.client)try{r.client.close(function(){s("connection closed")}),s("connection close sent")}catch(e){s(e.message)}if(r.client=null,r.client=new t,r.client.on("error",function(e){r.modbusErrorHandling(e),c.setNodeStatusTo("error",r)}),r.clientTimeout||(r.clientTimeout=1e3),r.reconnectTimeout||(r.reconnectTimeout=2e3),"tcp"===r.clienttype){if(!u.checkUnitId(r.unit_id,r.clienttype))return r.error(new Error("wrong unit-id (0..255)"),{payload:r.unit_id}),r.stateService.send("FAILURE"),!1;try{switch(r.tcpType){case"C701":s("C701 port UDP bridge"),r.client.connectC701(r.tcpHost,{port:r.tcpPort,autoOpen:!0}).then(r.setTCPConnectionOptions).then(r.setTCPConnected).catch(function(e){return r.modbusTcpErrorHandling(e),!1});break;case"TELNET":s("Telnet port"),r.client.connectTelnet(r.tcpHost,{port:r.tcpPort,autoOpen:!0}).then(r.setTCPConnectionOptions).catch(function(e){return r.modbusTcpErrorHandling(e),!1});break;case"TCP-RTU-BUFFERED":s("TCP RTU buffered port"),r.client.connectTcpRTUBuffered(r.tcpHost,{port:r.tcpPort,autoOpen:!0}).then(r.setTCPConnectionOptions).catch(function(e){return r.modbusTcpErrorHandling(e),!1});break;default:s("TCP port"),r.client.connectTCP(r.tcpHost,{port:r.tcpPort,autoOpen:!0}).then(r.setTCPConnectionOptions).catch(function(e){return r.modbusTcpErrorHandling(e),!1})}}catch(e){return r.modbusTcpErrorHandling(e),!1}}else{if(!u.checkUnitId(r.unit_id,r.clienttype))return r.error(new Error("wrong unit-id serial (0..247)"),{payload:r.unit_id}),r.stateService.send("FAILURE"),!1;if(r.serialConnectionDelay||(r.serialConnectionDelay=n),!r.serialPort)return r.error(new Error("wrong serial port"),{payload:r.serialPort}),r.stateService.send("FAILURE"),!1;var e={baudRate:parseInt(r.serialBaudrate),dataBits:parseInt(r.serialDatabits),stopBits:parseInt(r.serialStopbits),parity:r.serialParity,autoOpen:!1};try{switch(r.serialType){case"ASCII":s("ASCII port serial"),r.serialAsciiResponseStartDelimiter&&"string"==typeof r.serialAsciiResponseStartDelimiter?e.startOfSlaveFrameChar=parseInt(r.serialAsciiResponseStartDelimiter,16):e.startOfSlaveFrameChar=r.serialAsciiResponseStartDelimiter,s("Using response delimiter: 0x"+e.startOfSlaveFrameChar.toString(16)),r.client.connectAsciiSerial(r.serialPort,e).then(r.setSerialConnectionOptions).catch(function(e){return r.modbusSerialErrorHandling(e),!1});break;case"RTU":s("RTU port serial"),r.client.connectRTU(r.serialPort,e).then(r.setSerialConnectionOptions).catch(function(e){return r.modbusSerialErrorHandling(e),!1});break;default:s("RTU buffered port serial"),r.client.connectRTUBuffered(r.serialPort,e).then(r.setSerialConnectionOptions).catch(function(e){return r.modbusSerialErrorHandling(e),!1})}}catch(e){return r.modbusSerialErrorHandling(e),!1}}}catch(e){return r.modbusErrorHandling(e),!1}return!0},r.setTCPConnectionOptions=function(){r.client.setID(r.unit_id),r.client.setTimeout(r.clientTimeout),r.stateService.send("CONNECT")},r.setTCPConnected=function(){u.modbusSerialDebug("modbus tcp connected on "+r.tcpHost)},r.setSerialConnectionOptions=function(){r.stateService.send("OPENSERIAL"),setTimeout(r.openSerialClient,parseInt(r.serialConnectionDelay))},r.modbusErrorHandling=function(e){l.queueSerialUnlockCommand(r),e.message?u.modbusSerialDebug("modbusErrorHandling:"+e.message):u.modbusSerialDebug("modbusErrorHandling:"+JSON.stringify(e)),e.errno&&u.networkErrors.includes(e.errno)&&r.stateService.send("FAILURE")},r.modbusTcpErrorHandling=function(e){l.queueSerialUnlockCommand(r),r.showErrors&&r.error(e),r.failureLogEnabled&&(e.message?u.modbusSerialDebug("modbusTcpErrorHandling:"+e.message):u.modbusSerialDebug("modbusTcpErrorHandling:"+JSON.stringify(e))),(e.errno&&u.networkErrors.includes(e.errno)||e.code&&u.networkErrors.includes(e.code))&&r.stateService.send("BREAK")},r.modbusSerialErrorHandling=function(e){l.queueSerialUnlockCommand(r),r.showErrors&&r.error(e),r.failureLogEnabled&&(e.message?u.modbusSerialDebug("modbusSerialErrorHandling:"+e.message):u.modbusSerialDebug("modbusSerialErrorHandling:"+JSON.stringify(e))),r.stateService.send("BREAK")},r.openSerialClient=function(){"opened"===r.actualServiceState.value?(s("time to open Unit "+r.unit_id),u.modbusSerialDebug("modbus connection opened"),r.client.setID(r.unit_id),r.client.setTimeout(parseInt(r.clientTimeout)),r.client._port.on("close",r.onModbusClose),r.stateService.send("CONNECT")):(s("wrong state on connect serial "+r.actualServiceState.value),u.modbusSerialDebug("modbus connection not opened state is %s",r.actualServiceState.value),r.stateService.send("BREAK"))},r.onModbusClose=function(){l.queueSerialUnlockCommand(r),o("Modbus closed port"),u.modbusSerialDebug("modbus closed port"),r.stateService.send("CLOSE")},r.on("customModbusMessage",function(e,t,n){u.customModbusMessage(r,e,t,n)}),r.on("readModbus",function(t,e,n){var i=r.actualServiceState;r.isInactive()?n(new Error("Client Not Ready To Read At State "+i.value),t):r.bufferCommands?l.pushToQueueByUnitId(r,u.readModbus,t,e,n).then(function(){r.queueLog(JSON.stringify({info:"queued read msg",message:t.payload,state:i.value,queueLength:r.bufferCommandList.get(t.queueUnitId).length}))}).catch(function(e){n(e,t)}).finally(function(){r.stateService.send("QUEUE")}):u.readModbus(r,t,e,n)}),r.on("writeModbus",function(t,e,n){var i=r.actualServiceState;r.isInactive()?n(new Error("Client Not Ready To Write At State "+i.value),t):r.bufferCommands?l.pushToQueueByUnitId(r,u.writeModbus,t,e,n).then(function(){r.queueLog(JSON.stringify({info:"queued write msg",message:t.payload,state:i.value,queueLength:r.bufferCommandList.get(t.queueUnitId).length}))}).catch(function(e){n(e,t)}).finally(function(){r.stateService.send("QUEUE")}):u.writeModbus(r,t,e,n)}),r.activateSending=function(n){return r.sendingAllowed.set(n.queueUnitId,!0),l.queueSerialUnlockCommand(r),new Promise(function(e,t){try{r.bufferCommands&&(r.queueLog(JSON.stringify({info:"queue response activate sending",queueLength:r.bufferCommandList.length,sendingAllowed:r.sendingAllowed.get(n.queueUnitId),serialSendingAllowed:r.serialSendingAllowed,queueUnitId:n.queueUnitId})),l.checkQueuesAreEmpty(r))&&r.stateService.send("EMPTY"),e()}catch(e){t(e)}})},s("initialized"),r.setMaxListeners(0),r.on("reconnect",function(){r.stateService.send("CLOSE")}),r.on("dynamicReconnect",function(e,t,n){if(c.invalidPayloadIn(e))throw new Error("Message Or Payload Not Valid");u.internalDebug("Dynamic Reconnect Parameters "+JSON.stringify(e.payload)),u.setNewNodeSettings(r,e)?t(e):n(new Error("Message Or Payload Not Valid"),e),u.internalDebug("Dynamic Reconnect Starts on actual state "+r.actualServiceState.value),r.stateService.send("SWITCH")}),r.on("close",function(t){var n=r.name||r.id;r.closingModbus=!0,s("stop fsm on close "+n),r.stateService.send("STOP"),s("close node "+n),r.internalDebugLog("close node "+n),r.removeAllListeners(),r.client?r.client.isOpen?r.client.close(function(e){s(e?"Connection closed with error "+n:"Connection closed well "+n),t()}):(s("connection was closed "+n),t()):(s("Connection closed simple "+n),t())}),r.registeredNodeList={},r.registerForModbus=function(e){r.registeredNodeList[e]=e,1===Object.keys(r.registeredNodeList).length&&(r.closingModbus=!1,r.stateService.send("NEW"),r.stateService.send("INIT")),r.emit("mbregister",e)},r.setStoppedState=function(e,t){r.stateService.send("STOP"),r.emit("mbderegister",e),t()},r.closeConnectionWithoutRegisteredNodes=function(e,t){0===Object.keys(r.registeredNodeList).length&&(r.closingModbus=!0,r.client)&&"stopped"!==r.actualServiceState.value&&r.client.isOpen?r.client.close(function(){r.setStoppedState(e,t)}):r.setStoppedState(e,t)},r.deregisterForModbus=function(t,n){try{delete r.registeredNodeList[t],r.closingModbus?(n(),r.emit("mbderegister",t)):r.closeConnectionWithoutRegisteredNodes(t,n)}catch(e){o(e.message+" on de-register node "+t),r.error(e),n()}},r.isInactive=function(){return m.isUndefined(r.actualServiceState)||-1===r.messageAllowedStates.indexOf(r.actualServiceState.value)},r.isActive=function(){return!r.isInactive()},r.isReadyToSend=function(e){return!!e.actualServiceState.matches("queueing")||(o("Client not ready to send"),!1)}}),a.httpAdmin.get("/modbus/serial/ports",a.auth.needsPermission("serial.read"),function(e,t){require("serialport").SerialPort.list().then(function(e){t.json(e)}).catch(function(e){t.json([e.message]),u.internalDebug(e.message)})})};
//# sourceMappingURL=maps/modbus-client.js.map

@@ -1,2 +0,2 @@

"use strict";module.exports=function(i){require("source-map-support").install();var n=require("modbus-serial"),u=require("./core/modbus-server-core"),d=require("./modbus-basics"),c=require("debug")("contribModbus:flex:server");try{i.nodes.registerType("modbus-flex-server",function(e){i.nodes.createNode(this,e);var r=(s=require("vm2")).VM,s=s.VMScript,t=(this.name=e.name,this.logEnabled=e.logEnabled,this.serverAddress=e.serverAddress||"0.0.0.0",this.serverPort=parseInt(e.serverPort),this.responseDelay=parseInt(e.responseDelay),this.delayUnit=e.delayUnit,this.unitId=parseInt(e.unitId)||1,this.minAddress=parseInt(e.minAddress)||0,this.splitAddress=parseInt(e.splitAddress)||1e4,this.showErrors=e.showErrors,this.funcGetCoil=new s(e.funcGetCoil).compile(),this.funcGetDiscreteInput=new s(e.funcGetDiscreteInput).compile(),this.funcGetInputRegister=new s(e.funcGetInputRegister).compile(),this.funcGetHoldingRegister=new s(e.funcGetHoldingRegister).compile(),this.funcSetCoil=new s(e.funcSetCoil).compile(),this.funcSetRegister=new s(e.funcSetRegister).compile(),this.internalDebugLog=c,this.verboseLogging=i.settings.verbose,this);function o(e){return[{type:"holding",message:e,payload:t.registers.slice(t.splitAddress*u.bufferFactor)},{type:"coils",message:e,payload:t.coils.slice(0,t.splitAddress*u.bufferFactor)},{type:"input",message:e,payload:t.registers.slice(0,t.splitAddress*u.bufferFactor)},{type:"discrete",message:e,payload:t.coils.slice(t.splitAddress*u.bufferFactor)},{payload:"request",type:"message",message:e}]}t.bufferFactor=u.bufferFactor,t.coilsBufferSize=parseInt(e.coilsBufferSize*u.bufferFactor),t.registersBufferSize=parseInt(e.registersBufferSize*u.bufferFactor),t.coils=Buffer.alloc(t.coilsBufferSize,0),t.registers=Buffer.alloc(t.registersBufferSize,0),t.modbusServer=null,d.setNodeStatusTo("initialized",t),t.vector={},(s=new r({sandbox:{node:t}})).run("node.vector.getCoil = "+e.funcGetCoil),s.run("node.vector.getDiscreteInput = "+e.funcGetDiscreteInput),s.run("node.vector.getInputRegister = "+e.funcGetInputRegister),s.run("node.vector.getHoldingRegister = "+e.funcGetHoldingRegister),s.run("node.vector.setCoil = "+e.funcSetCoil),s.run("node.vector.setRegister = "+e.funcSetRegister),t.startServer=function(){try{if(null===t.modbusServer){try{t.modbusServer=new n.ServerTCP(t.vector,{host:t.serverAddress,port:t.serverPort,debug:t.logEnabled,unitID:t.unitId})}catch(e){t.error(e,{payload:"server net error -> for port 502 on unix, you have to be a super user"})}t.modbusServer.on("socketError",function(e){c(e.message),t.showErrors&&t.warn(e),d.setNodeStatusTo("error",t),t.modbusServer.close(function(){t.startServer()})}),t.modbusServer.on("error",function(e){c("Modbus Flex Server error"),t.showErrors&&t.error(e),d.setNodeStatusTo("error",t)}),t.modbusServer._server.on("connection",function(e){c("Modbus Flex Server client connection"),e&&c("Modbus Flex Server client to "+JSON.stringify(e.address())+" from "+e.remoteAddress+" "+e.remotePort),d.setNodeStatusTo("active",t)}),t.modbusServer._server.on("error",function(e){c("Modbus Flex Server client error"),t.showErrors&&t.error(e),d.setNodeStatusTo("error",t)})}t.showStatusActivities||d.setNodeDefaultStatus(t)}catch(e){c(e.message),t.showErrors&&t.warn(e),d.setNodeStatusTo("error",t)}null!=t.modbusServer?(c("Modbus Flex Server listening on modbus://"+t.serverAddress+":"+t.serverPort),d.setNodeStatusTo("initialized",t)):(c("Modbus Flex Server isn't ready"),d.setNodeStatusTo("error",t))},t.startServer(),t.on("input",function(e){u.isValidMemoryMessage(e)?(u.writeToFlexServerMemory(t,e),1!==e.payload.disableMsgOutput&&t.send(o(e))):(t.showErrors&&t.error("Is Not A Valid Memory Write Message To Server",e),u.isValidMessage(e)&&!e.payload.disableMsgOutput&&t.send(o(e)))}),t.on("close",function(){d.setNodeStatusTo("closed",t),t.modbusServer._server&&t.modbusServer._server.close(),t.modbusServer&&t.modbusServer.close(),t.modbusServer=null})})}catch(e){c(e.message)}};
"use strict";module.exports=function(i){require("source-map-support").install();var n=require("@plus4nodered/modbus-serial"),u=require("./core/modbus-server-core"),d=require("./modbus-basics"),c=require("debug")("contribModbus:flex:server");try{i.nodes.registerType("modbus-flex-server",function(e){i.nodes.createNode(this,e);var r=(s=require("vm2")).VM,s=s.VMScript,t=(this.name=e.name,this.logEnabled=e.logEnabled,this.serverAddress=e.serverAddress||"0.0.0.0",this.serverPort=parseInt(e.serverPort),this.responseDelay=parseInt(e.responseDelay),this.delayUnit=e.delayUnit,this.unitId=parseInt(e.unitId)||1,this.minAddress=parseInt(e.minAddress)||0,this.splitAddress=parseInt(e.splitAddress)||1e4,this.showErrors=e.showErrors,this.funcGetCoil=new s(e.funcGetCoil).compile(),this.funcGetDiscreteInput=new s(e.funcGetDiscreteInput).compile(),this.funcGetInputRegister=new s(e.funcGetInputRegister).compile(),this.funcGetHoldingRegister=new s(e.funcGetHoldingRegister).compile(),this.funcSetCoil=new s(e.funcSetCoil).compile(),this.funcSetRegister=new s(e.funcSetRegister).compile(),this.internalDebugLog=c,this.verboseLogging=i.settings.verbose,this);function o(e){return[{type:"holding",message:e,payload:t.registers.slice(t.splitAddress*u.bufferFactor)},{type:"coils",message:e,payload:t.coils.slice(0,t.splitAddress*u.bufferFactor)},{type:"input",message:e,payload:t.registers.slice(0,t.splitAddress*u.bufferFactor)},{type:"discrete",message:e,payload:t.coils.slice(t.splitAddress*u.bufferFactor)},{payload:"request",type:"message",message:e}]}t.bufferFactor=u.bufferFactor,t.coilsBufferSize=parseInt(e.coilsBufferSize*u.bufferFactor),t.registersBufferSize=parseInt(e.registersBufferSize*u.bufferFactor),t.coils=Buffer.alloc(t.coilsBufferSize,0),t.registers=Buffer.alloc(t.registersBufferSize,0),t.modbusServer=null,d.setNodeStatusTo("initialized",t),t.vector={},(s=new r({sandbox:{node:t}})).run("node.vector.getCoil = "+e.funcGetCoil),s.run("node.vector.getDiscreteInput = "+e.funcGetDiscreteInput),s.run("node.vector.getInputRegister = "+e.funcGetInputRegister),s.run("node.vector.getHoldingRegister = "+e.funcGetHoldingRegister),s.run("node.vector.setCoil = "+e.funcSetCoil),s.run("node.vector.setRegister = "+e.funcSetRegister),t.startServer=function(){try{if(null===t.modbusServer){try{t.modbusServer=new n.ServerTCP(t.vector,{host:t.serverAddress,port:t.serverPort,debug:t.logEnabled,unitID:t.unitId})}catch(e){t.error(e,{payload:"server net error -> for port 502 on unix, you have to be a super user"})}t.modbusServer.on("socketError",function(e){c(e.message),t.showErrors&&t.warn(e),d.setNodeStatusTo("error",t),t.modbusServer.close(function(){t.startServer()})}),t.modbusServer.on("error",function(e){c("Modbus Flex Server error"),t.showErrors&&t.error(e),d.setNodeStatusTo("error",t)}),t.modbusServer._server.on("connection",function(e){c("Modbus Flex Server client connection"),e&&c("Modbus Flex Server client to "+JSON.stringify(e.address())+" from "+e.remoteAddress+" "+e.remotePort),d.setNodeStatusTo("active",t)}),t.modbusServer._server.on("error",function(e){c("Modbus Flex Server client error"),t.showErrors&&t.error(e),d.setNodeStatusTo("error",t)})}t.showStatusActivities||d.setNodeDefaultStatus(t)}catch(e){c(e.message),t.showErrors&&t.warn(e),d.setNodeStatusTo("error",t)}null!=t.modbusServer?(c("Modbus Flex Server listening on modbus://"+t.serverAddress+":"+t.serverPort),d.setNodeStatusTo("initialized",t)):(c("Modbus Flex Server isn't ready"),d.setNodeStatusTo("error",t))},t.startServer(),t.on("input",function(e){u.isValidMemoryMessage(e)?(u.writeToFlexServerMemory(t,e),1!==e.payload.disableMsgOutput&&t.send(o(e))):(t.showErrors&&t.error("Is Not A Valid Memory Write Message To Server",e),u.isValidMessage(e)&&!e.payload.disableMsgOutput&&t.send(o(e)))}),t.on("close",function(){d.setNodeStatusTo("closed",t),t.modbusServer._server&&t.modbusServer._server.close(),t.modbusServer&&t.modbusServer.close(),t.modbusServer=null})})}catch(e){c(e.message)}};
//# sourceMappingURL=maps/modbus-flex-server.js.map
{
"name": "node-red-contrib-modbus",
"version": "5.26.0",
"version": "5.27.0",
"private": false,
"description": "The all in one Modbus TCP and Serial contribution package for Node-RED.",
"dependencies": {
"@xstate/fsm": "~2.0.0",
"@xstate/fsm": "~2.1.0",
"bson": "~4.7.2",

@@ -12,6 +12,6 @@ "debug": "~4.3.4",

"line-by-line": "~0.1.6",
"modbus-serial": "~8.0.10",
"@plus4nodered/modbus-serial": "8.1.0",
"source-map-support": "~0.5.21",
"underscore": "~1.13.6",
"vm2": "~3.9.15"
"vm2": "~3.9.19"
},

@@ -52,3 +52,4 @@ "optionalDependencies": {

"Modbus-Response-Filter": "modbus/modbus-response-filter.js",
"Modbus-Flex-Sequencer": "modbus/modbus-flex-sequencer.js"
"Modbus-Flex-Sequencer": "modbus/modbus-flex-sequencer.js",
"Modbus-Flex-Fc": "modbus/modbus-flex-fc.js"
}

@@ -63,3 +64,5 @@ },

"modbus",
"supporter.js"
"supporter.js",
"extras/argumentMaps/defaults",
"extras/argumentMaps/ArgumentMaps.md"
],

@@ -91,3 +94,4 @@ "bugs": {

"dev-link": "npm i && npm run build && npm link",
"dev-unlink": "npm unlink node-red-contrib-modbus -g"
"dev-unlink": "npm unlink node-red-contrib-modbus -g",
"dev-link-local": "npm run build && npm link"
},

@@ -94,0 +98,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc