node-red-contrib-modbus
Advanced tools
Comparing version 5.14.0 to 5.14.1
@@ -1,11 +0,10 @@ | ||
# [5.14.0](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.13.3...v5.14.0) (2021-04-10) | ||
## [5.14.1](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.15.0...v5.14.1) (2021-08-07) | ||
### Bug Fixes | ||
* **basics:** [#210](https://github.com/biancoroyal/node-red-contrib-modbus/issues/210) missing parameter node ([806f944](https://github.com/biancoroyal/node-red-contrib-modbus/commit/806f944d3acdb46750611b74497940224463acfa)) | ||
## [5.14.1](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.14.0...v5.14.1) (2021-08-07) | ||
## [5.13.2](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.13.1...v5.13.2) (2020-05-26) | ||
# [5.14.0](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.13.3...v5.14.0) (2021-04-10) | ||
@@ -15,2 +14,3 @@ | ||
* **basics:** [#210](https://github.com/biancoroyal/node-red-contrib-modbus/issues/210) missing parameter node ([806f944](https://github.com/biancoroyal/node-red-contrib-modbus/commit/806f944d3acdb46750611b74497940224463acfa)) | ||
* **msg:** modbus request data in msg object [#203](https://github.com/biancoroyal/node-red-contrib-modbus/issues/203) ([380357f](https://github.com/biancoroyal/node-red-contrib-modbus/commit/380357f825ebe0b3648b1d146bad136f1a195d89)) | ||
@@ -20,3 +20,3 @@ | ||
## [5.13.1](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.13.0...v5.13.1) (2020-05-24) | ||
## [5.13.1](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.12.0...v5.13.1) (2020-05-24) | ||
@@ -26,14 +26,6 @@ | ||
* **serial:** [#202](https://github.com/biancoroyal/node-red-contrib-modbus/issues/202) locked queue on serial error ([757f341](https://github.com/biancoroyal/node-red-contrib-modbus/commit/757f34192885e7cf157aa438e22266928d477357)) | ||
* **serial:** queue serial sequenced sending [#202](https://github.com/biancoroyal/node-red-contrib-modbus/issues/202) ([e11cb49](https://github.com/biancoroyal/node-red-contrib-modbus/commit/e11cb492037e0d91eb13f82596cbecbc87c6e24d)) | ||
# [5.13.0](https://github.com/biancoroyal/node-red-contrib-modbus/compare/v5.12.0...v5.13.0) (2020-05-21) | ||
### Bug Fixes | ||
* **serial:** [#202](https://github.com/biancoroyal/node-red-contrib-modbus/issues/202) locked queue on serial error ([757f341](https://github.com/biancoroyal/node-red-contrib-modbus/commit/757f34192885e7cf157aa438e22266928d477357)) | ||
### Features | ||
@@ -40,0 +32,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";require("source-map-support").install();var de=de||{biancoroyal:{modbus:{basics:{}}}};de.biancoroyal.modbus.basics.internalDebug=de.biancoroyal.modbus.basics.internalDebug||require("debug")("contribModbus:basics"),de.biancoroyal.modbus.basics.util=de.biancoroyal.modbus.basics.util||require("util"),de.biancoroyal.modbus.basics.statusLog=!1,de.biancoroyal.modbus.basics.get_timeUnit_name=function(e){var s="";switch(e){case"ms":s="msec.";break;case"s":s="sec.";break;case"m":s="min.";break;case"h":s="h."}return s},de.biancoroyal.modbus.basics.calc_rateByUnit=function(e,s){switch(s){case"ms":break;case"s":e=1e3*parseInt(e);break;case"m":e=6e4*parseInt(e);break;case"h":e=36e5*parseInt(e);break;default:e=1e4}return e},de.biancoroyal.modbus.basics.setNodeStatusProperties=function(e,s){var t="yellow",o="ring",a=(e=e||"waiting").value||e;switch(a){case"connecting":t="yellow",o="ring";break;case"error":t="red",o="ring";break;case"initialized":case"init":t="yellow",o="dot";break;case"not ready to read":case"not ready to write":t="yellow",o="ring";break;case"connected":case"queueing":case"queue":t="green",o="ring";break;case"timeout":t="red",o="ring";break;case"active":case"reading":case"writing":case"active reading":case"active writing":s||(a="active"),t="green",o="dot";break;case"disconnected":case"terminated":t="red",o="ring";break;case"stopped":t="red",o="dot";break;case"polling":t="green",o=s?"ring":(a="active","dot");break;default:"waiting"===a&&(t="blue",a="waiting ...")}return{fill:t,shape:o,status:a}},de.biancoroyal.modbus.basics.setNodeStatusByResponseTo=function(e,s,t){var o="red",a="dot";switch(e){case"initialized":case"queue":o="green",a="ring";break;case"active":o="green",a="dot";break;default:e&&"waiting"!==e||(o="blue",e="waiting ...")}t.status({fill:o,shape:a,text:this.util.inspect(s,!1,null)})},de.biancoroyal.modbus.basics.setNodeStatusResponse=function(e,s){s.status({fill:"green",shape:"dot",text:"active got length: "+e})},de.biancoroyal.modbus.basics.setModbusError=function(e,s,t,o){if(t)switch(t.message){case"Timed out":this.setNodeStatusTo("timeout",e);break;case"FSM Not Ready To Reconnect":this.setNodeStatusTo("not ready to reconnect",e);break;case"Port Not Open":this.setNodeStatusTo("reconnect",e),s.emit("reconnect");break;default:this.internalDebug(t.message),e.showErrors&&this.setNodeStatusTo("error "+t.message,e)}},de.biancoroyal.modbus.basics.setNodeStatusTo=function(e,s){var t;s.showStatusActivities&&(e!==s.statusText?(t=this.setNodeStatusProperties(e,s.showStatusActivities),s.statusText=e,s.status({fill:t.fill,shape:t.shape,text:t.status})):this.setNodeDefaultStatus(s))},de.biancoroyal.modbus.basics.onModbusInit=function(e){this.setNodeStatusTo("initialize",e)},de.biancoroyal.modbus.basics.onModbusConnect=function(e){this.setNodeStatusTo("connected",e)},de.biancoroyal.modbus.basics.onModbusActive=function(e){this.setNodeStatusTo("active",e)},de.biancoroyal.modbus.basics.onModbusError=function(e,s){this.setNodeStatusTo("failure",e),e.showErrors&&e.warn(s)},de.biancoroyal.modbus.basics.onModbusClose=function(e){this.setNodeStatusTo("closed",e)},de.biancoroyal.modbus.basics.onModbusQueue=function(e){this.setNodeStatusTo("queueing",e)},de.biancoroyal.modbus.basics.onModbusBroken=function(e,s){this.setNodeStatusTo("reconnecting after "+s.reconnectTimeout+" msec.",e)},de.biancoroyal.modbus.basics.setNodeDefaultStatus=function(e){e.status({fill:"green",shape:"ring",text:"active"})},de.biancoroyal.modbus.basics.initModbusClientEvents=function(s,e){var t=this;s.showStatusActivities?(e.on("mbinit",function(){t.onModbusInit(s)}),e.on("mbqueue",function(){t.onModbusQueue(s)}),e.on("mbconnected",function(){t.onModbusConnect(s)}),e.on("mbbroken",function(){t.onModbusBroken(s,e)}),e.on("mbactive",function(){t.onModbusActive(s)}),e.on("mberror",function(e){t.onModbusError(s,e)}),e.on("mbclosed",function(){t.onModbusClose(s)})):this.setNodeDefaultStatus(s)},de.biancoroyal.modbus.basics.invalidPayloadIn=function(e){return!(e&&Object.prototype.hasOwnProperty.call(e,"payload"))},de.biancoroyal.modbus.basics.sendEmptyMsgOnFail=function(e,s,t){e.emptyMsgOnFail&&(t.payload="",s&&s.message&&s.name?t.error=s:t.error=Error(s),t.error.nodeStatus=e.statusText,e.send([t,t]))},de.biancoroyal.modbus.basics.logMsgError=function(e,s,t){e.showErrors&&e.error(s,t)},de.biancoroyal.modbus.basics.buildNewMessage=function(e,s,t){return e?Object.assign(s,t):t},module.exports=de.biancoroyal.modbus.basics; | ||
"use strict";require("source-map-support").install();var de=de||{biancoroyal:{modbus:{basics:{}}}};de.biancoroyal.modbus.basics.internalDebug=de.biancoroyal.modbus.basics.internalDebug||require("debug")("contribModbus:basics"),de.biancoroyal.modbus.basics.util=de.biancoroyal.modbus.basics.util||require("util"),de.biancoroyal.modbus.basics.statusLog=!1,de.biancoroyal.modbus.basics.get_timeUnit_name=function(e){var s="";switch(e){case"ms":s="msec.";break;case"s":s="sec.";break;case"m":s="min.";break;case"h":s="h."}return s},de.biancoroyal.modbus.basics.calc_rateByUnit=function(e,s){switch(s){case"ms":break;case"s":e=1e3*parseInt(e);break;case"m":e=6e4*parseInt(e);break;case"h":e=36e5*parseInt(e);break;default:e=1e4}return e},de.biancoroyal.modbus.basics.setNodeStatusProperties=function(e,s){var t="yellow",o="ring",a=(e=e||"waiting").value||e;switch(a){case"connecting":t="yellow",o="ring";break;case"error":t="red",o="ring";break;case"initialized":case"init":t="yellow",o="dot";break;case"not ready to read":case"not ready to write":t="yellow",o="ring";break;case"connected":case"queueing":case"queue":t="green",o="ring";break;case"timeout":t="red",o="ring";break;case"active":case"reading":case"writing":case"active reading":case"active writing":s||(a="active"),t="green",o="dot";break;case"disconnected":case"terminated":t="red",o="ring";break;case"stopped":t="red",o="dot";break;case"polling":t="green",o=s?"ring":(a="active","dot");break;default:"waiting"===a&&(t="blue",a="waiting ...")}return{fill:t,shape:o,status:a}},de.biancoroyal.modbus.basics.setNodeStatusByResponseTo=function(e,s,t){var o="red",a="dot";switch(e){case"initialized":case"queue":o="green",a="ring";break;case"active":o="green",a="dot";break;default:e&&"waiting"!==e||(o="blue",e="waiting ...")}t.status({fill:o,shape:a,text:this.util.inspect(s,!1,null)})},de.biancoroyal.modbus.basics.setNodeStatusResponse=function(e,s){s.status({fill:"green",shape:"dot",text:"active got length: "+e})},de.biancoroyal.modbus.basics.setModbusError=function(e,s,t,o){if(t)switch(t.message){case"Timed out":this.setNodeStatusTo("timeout",e);break;case"FSM Not Ready To Reconnect":this.setNodeStatusTo("not ready to reconnect",e);break;case"Port Not Open":this.setNodeStatusTo("reconnect",e),s.emit("reconnect");break;default:this.internalDebug(t.message),e.showErrors&&this.setNodeStatusTo("error "+t.message,e)}},de.biancoroyal.modbus.basics.setNodeStatusTo=function(e,s){var t;s.showStatusActivities&&(e!==s.statusText?(t=this.setNodeStatusProperties(e,s.showStatusActivities),s.statusText=e,s.status({fill:t.fill,shape:t.shape,text:t.status})):this.setNodeDefaultStatus(s))},de.biancoroyal.modbus.basics.onModbusInit=function(e){this.setNodeStatusTo("initialize",e)},de.biancoroyal.modbus.basics.onModbusConnect=function(e){this.setNodeStatusTo("connected",e)},de.biancoroyal.modbus.basics.onModbusActive=function(e){this.setNodeStatusTo("active",e)},de.biancoroyal.modbus.basics.onModbusError=function(e,s){this.setNodeStatusTo("failure",e),e.showErrors&&e.warn(s)},de.biancoroyal.modbus.basics.onModbusClose=function(e){this.setNodeStatusTo("closed",e)},de.biancoroyal.modbus.basics.onModbusQueue=function(e){this.setNodeStatusTo("queueing",e)},de.biancoroyal.modbus.basics.onModbusBroken=function(e,s){this.setNodeStatusTo("reconnecting after "+s.reconnectTimeout+" msec.",e)},de.biancoroyal.modbus.basics.setNodeDefaultStatus=function(e){e.status({fill:"green",shape:"ring",text:"active"})},de.biancoroyal.modbus.basics.initModbusClientEvents=function(s,e){var t=this;s.showStatusActivities?(e.on("mbinit",function(){t.onModbusInit(s)}),e.on("mbqueue",function(){t.onModbusQueue(s)}),e.on("mbconnected",function(){t.onModbusConnect(s)}),e.on("mbbroken",function(){t.onModbusBroken(s,e)}),e.on("mbactive",function(){t.onModbusActive(s)}),e.on("mberror",function(e){t.onModbusError(s,e)}),e.on("mbclosed",function(){t.onModbusClose(s)})):this.setNodeDefaultStatus(s)},de.biancoroyal.modbus.basics.invalidPayloadIn=function(e){return!(e&&Object.prototype.hasOwnProperty.call(e,"payload"))},de.biancoroyal.modbus.basics.invalidSequencesIn=function(e){return!(e&&Object.prototype.hasOwnProperty.call(e,"sequences"))},de.biancoroyal.modbus.basics.sendEmptyMsgOnFail=function(e,s,t){e.emptyMsgOnFail&&(t.payload="",s&&s.message&&s.name?t.error=s:t.error=Error(s),t.error.nodeStatus=e.statusText,e.send([t,t]))},de.biancoroyal.modbus.basics.logMsgError=function(e,s,t){e.showErrors&&e.error(s,t)},de.biancoroyal.modbus.basics.buildNewMessage=function(e,s,t){return e?Object.assign(s,t):t},module.exports=de.biancoroyal.modbus.basics; | ||
//# sourceMappingURL=maps/modbus-basics.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";module.exports=function(a){require("source-map-support").install();var c=require("./modbus-basics"),l=require("./core/modbus-client-core"),u=require("./core/modbus-queue-core"),d=require("debug")("contribModbus:config:client");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";this.clienttype=e.clienttype,void 0===e.parallelUnitIdsAllowed?this.bufferCommands=!0:this.bufferCommands=e.bufferCommands,this.queueLogEnabled=e.queueLogEnabled,this.stateLogEnabled=e.stateLogEnabled,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.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;var o=this;function r(e){a.settings.verbose&&o.warn("Client -> "+e+o.serverInfo)}function s(e){a.settings.verbose&&l.internalDebug("Client -> "+e+o.serverInfo)}o.isFirstInitOfConnection=!0,o.closingModbus=!1,o.client=null,o.bufferCommandList=new Map,o.sendingAllowed=new Map,o.unitSendingAllowed=[],o.messageAllowedStates=l.messagesAllowedStates,o.serverInfo="",o.stateMachine=null,o.stateService=null,o.stateMachine=l.createStateMachineService(),o.actualServiceState=o.stateMachine.initialState,o.actualServiceStateBefore=o.actualServiceState,o.stateService=l.startStateService(o.stateMachine),o.reconnectTimeoutId=0,o.serialSendingAllowed=!1,o.internalDebugLog=d,u.queueSerialLockCommand(o),o.setDefaultUnitId=function(){"tcp"===this.clienttype?o.unit_id=0:o.unit_id=1},o.setUnitIdFromPayload=function(e){var t=l.getActualUnitId(o,e);l.checkUnitId(t,o.clienttype)||o.setDefaultUnitId(),o.client.setID(t),e.unitId=t},!Number.isNaN(o.unit_id)&&l.checkUnitId(o.unit_id,o.clienttype)||o.setDefaultUnitId(),o.updateServerinfo=function(){"tcp"===o.clienttype?o.serverInfo=" TCP@"+o.tcpHost+":"+o.tcpPort:o.serverInfo=" Serial@"+o.serialPort+":"+o.serialBaudrate+"bit/s",o.serverInfo+=" default Unit-Id: "+o.unit_id},o.queueLog=function(e){o.bufferCommands&&o.queueLogEnabled&&s(e)},o.stateService.subscribe(function(e){var t;if(o.actualServiceStateBefore=o.actualServiceState,o.actualServiceState=e,t=e.value,o.stateLogEnabled&&s(t),e.value&&void 0!==o.actualServiceState.value&&o.actualServiceStateBefore.value!==o.actualServiceState.value){if(e.matches("init")){r("fsm init state after "+o.actualServiceStateBefore.value),o.updateServerinfo(),u.initQueue(o),o.reconnectTimeoutId=0;try{o.isFirstInitOfConnection?(o.isFirstInitOfConnection=!1,r("first fsm init in 500 ms"),setTimeout(o.connectClient,n)):(r("fsm init in "+o.reconnectTimeout+" ms"),setTimeout(o.connectClient,o.reconnectTimeout))}catch(e){o.error(e,{payload:"client connection error "+i})}o.emit("mbinit")}e.matches("connected")&&(r("fsm connected after state "+o.actualServiceStateBefore.value+i),u.queueSerialUnlockCommand(o),o.emit("mbconnected")),e.matches("activated")&&(o.emit("mbactive"),o.bufferCommands&&!u.checkQueuesAreEmpty(o)&&o.stateService.send("QUEUE")),e.matches("queueing")&&("tcp"===o.clienttype?o.stateService.send("SEND"):o.serialSendingAllowed&&(u.queueSerialLockCommand(o),o.stateService.send("SEND"))),e.matches("sending")&&(setTimeout(function(){u.dequeueCommand(o)},o.commandDelay),o.emit("mbqueue")),e.matches("opened")&&(u.queueSerialUnlockCommand(o),o.emit("mbopen")),e.matches("switch")&&(o.emit("mbswitch"),o.stateService.send("CLOSE")),e.matches("closed")&&(o.emit("mbclosed"),o.stateService.send("RECONNECT")),e.matches("stopped")&&(r("stopped state without reconnecting"),o.emit("mbclosed")),e.matches("failed")&&(r("fsm failed state after "+o.actualServiceStateBefore.value+i),o.emit("mberror","Modbus Failure On State "+o.actualServiceStateBefore.value+i),o.stateService.send("BREAK")),e.matches("broken")&&(r("fsm broken state after "+o.actualServiceStateBefore.value+i),o.emit("mbbroken","Modbus Broken On State "+o.actualServiceStateBefore.value+i),o.reconnectOnTimeout?o.stateService.send("RECONNECT"):o.stateService.send("ACTIVATE")),e.matches("reconnecting")&&(r("fsm reconnect state after "+o.actualServiceStateBefore.value+i),u.queueSerialLockCommand(o),o.emit("mbreconnecting"),o.reconnectTimeout<=0&&(o.reconnectTimeout=2e3),setTimeout(function(){o.reconnectTimeoutId=0,o.stateService.send("INIT")},o.reconnectTimeout))}}),o.connectClient=function(){if(o.client)try{o.client.close(function(){s("connection closed")}),s("connection close sent")}catch(e){s(e.message)}if(o.client=null,o.client=new t,o.clientTimeout||(o.clientTimeout=1e3),o.reconnectTimeout||(o.reconnectTimeout=2e3),"tcp"===o.clienttype){if(!l.checkUnitId(o.unit_id,o.clienttype))return o.error(new Error("wrong unit-id (0..255)"),{payload:o.unit_id}),void o.stateService.send("FAILURE");switch(o.tcpType){case"C701":s("C701 port UDP bridge"),o.client.connectC701(o.tcpHost,{port:o.tcpPort,autoOpen:!0}).then(o.setTCPConnectionOptions).then(o.setTCPConnected).catch(o.modbusTcpErrorHandling);break;case"TELNET":s("Telnet port"),o.client.connectTelnet(o.tcpHost,{port:o.tcpPort,autoOpen:!0}).then(o.setTCPConnectionOptions).catch(o.modbusTcpErrorHandling);break;case"TPC-RTU-BUFFERED":s("TCP RTU buffered port"),o.client.connectTcpRTUBuffered(o.tcpHost,{port:o.tcpPort,autoOpen:!0}).then(o.setTCPConnectionOptions).catch(o.modbusTcpErrorHandling);break;default:s("TCP port"),o.client.connectTCP(o.tcpHost,{port:o.tcpPort,autoOpen:!0}).then(o.setTCPConnectionOptions).catch(o.modbusTcpErrorHandling)}}else{if(!l.checkUnitId(o.unit_id,o.clienttype))return o.error(new Error("wrong unit-id serial (0..247)"),{payload:o.unit_id}),void o.stateService.send("FAILURE");if(o.serialConnectionDelay||(o.serialConnectionDelay=n),!o.serialPort)return o.error(new Error("wrong serial port"),{payload:o.serialPort}),void o.stateService.send("FAILURE");var e={baudRate:parseInt(o.serialBaudrate),dataBits:parseInt(o.serialDatabits),stopBits:parseInt(o.serialStopbits),parity:o.serialParity,autoOpen:!1};switch(o.serialType){case"ASCII":s("ASCII port serial"),o.client.connectAsciiSerial(o.serialPort,e).then(o.setSerialConnectionOptions).catch(o.modbusSerialErrorHandling);break;case"RTU":s("RTU port serial"),o.client.connectRTU(o.serialPort,e).then(o.setSerialConnectionOptions).catch(o.modbusSerialErrorHandling);break;default:s("RTU buffered port serial"),o.client.connectRTUBuffered(o.serialPort,e).then(o.setSerialConnectionOptions).catch(o.modbusSerialErrorHandling)}}},o.setTCPConnectionOptions=function(){o.client.setID(o.unit_id),o.client.setTimeout(o.clientTimeout),o.stateService.send("CONNECT")},o.setTCPConnected=function(){l.modbusSerialDebug("modbus tcp connected on "+o.tcpHost)},o.setSerialConnectionOptions=function(){o.stateService.send("OPENSERIAL"),setTimeout(o.openSerialClient,parseInt(o.serialConnectionDelay))},o.modbusErrorHandling=function(e){u.queueSerialUnlockCommand(o),e.message?l.modbusSerialDebug("modbusErrorHandling:"+e.message):l.modbusSerialDebug("modbusErrorHandling:"+JSON.stringify(e)),e.errno&&l.networkErrors.includes(e.errno)&&o.stateService.send("FAILURE")},o.modbusTcpErrorHandling=function(e){u.queueSerialUnlockCommand(o),o.showErrors&&o.error(e),e.message?l.modbusSerialDebug("modbusTcpErrorHandling:"+e.message):l.modbusSerialDebug("modbusTcpErrorHandling:"+JSON.stringify(e)),e.errno&&l.networkErrors.includes(e.errno)&&o.stateService.send("BREAK")},o.modbusSerialErrorHandling=function(e){u.queueSerialUnlockCommand(o),o.showErrors&&o.error(e),e.message?l.modbusSerialDebug("modbusSerialErrorHandling:"+e.message):l.modbusSerialDebug("modbusSerialErrorHandling:"+JSON.stringify(e)),o.stateService.send("BREAK")},o.openSerialClient=function(){"opened"===o.actualServiceState.value?(s("time to open Unit "+o.unit_id),l.modbusSerialDebug("modbus connection opened"),o.client.setID(o.unit_id),o.client.setTimeout(parseInt(o.clientTimeout)),o.client._port.on("close",o.onModbusClose),o.stateService.send("CONNECT")):(s("wrong state on connect serial "+o.actualServiceState.value),l.modbusSerialDebug("modbus connection not opened state is %s",o.actualServiceState.value),o.stateService.send("BREAK"))},o.onModbusClose=function(){u.queueSerialUnlockCommand(o),r("Modbus closed port"),l.modbusSerialDebug("modbus closed port"),o.stateService.send("CLOSE")},o.on("readModbus",function(t,e,n){var i=o.actualServiceState;-1===o.messageAllowedStates.indexOf(i.value)?n(new Error("Client Not Ready To Read At State "+i.value),t):o.bufferCommands?u.pushToQueueByUnitId(o,l.readModbus,t,e,n).then(function(){o.queueLog(JSON.stringify({info:"queued read msg",message:t.payload,state:i.value,queueLength:o.bufferCommandList.get(t.queueUnitId).length}))}).catch(function(e){n(e,t)}).finally(function(){o.stateService.send("QUEUE")}):l.readModbus(o,t,e,n)}),o.on("writeModbus",function(t,e,n){var i=o.actualServiceState;-1===o.messageAllowedStates.indexOf(i.value)?n(new Error("Client Not Ready To Write At State "+i.value),t):o.bufferCommands?u.pushToQueueByUnitId(o,l.writeModbus,t,e,n).then(function(){o.queueLog(JSON.stringify({info:"queued write msg",message:t.payload,state:i.value,queueLength:o.bufferCommandList.get(t.queueUnitId).length}))}).catch(function(e){n(e,t)}).finally(function(){o.stateService.send("QUEUE")}):l.writeModbus(o,t,e,n)}),o.activateSending=function(n){return o.sendingAllowed.set(n.queueUnitId,!0),u.queueSerialUnlockCommand(o),new Promise(function(e,t){try{o.bufferCommands&&(o.queueLog(JSON.stringify({info:"queue response activate sending",queueLength:o.bufferCommandList.length,sendingAllowed:o.sendingAllowed.get(n.queueUnitId),serialSendingAllowed:o.serialSendingAllowed,queueUnitId:n.queueUnitId})),u.checkQueuesAreEmpty(o)&&o.stateService.send("EMPTY")),e()}catch(e){t(e)}})},s("initialized"),o.setMaxListeners(0),o.on("reconnect",function(){o.stateService.send("CLOSE")}),o.on("dynamicReconnect",function(e,t,n){if(c.invalidPayloadIn(e))throw new Error("Message Or Payload Not Valid");l.internalDebug("Dynamic Reconnect Parameters "+JSON.stringify(e.payload)),l.setNewNodeSettings(o,e)?t(e):n(new Error("Message Or Payload Not Valid"),e),l.internalDebug("Dynamic Reconnect Starts on actual state "+o.actualServiceState.value),o.stateService.send("SWITCH")}),o.on("close",function(t){var n=o.name||o.id;o.closingModbus=!0,s("stop fsm on close "+n),o.stateService.send("STOP"),s("close node "+n),o.internalDebugLog("close node "+n),o.removeAllListeners(),o.client?o.client.isOpen?o.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())}),o.registeredNodeList={},o.registerForModbus=function(e){o.registeredNodeList[e]=e,1===Object.keys(o.registeredNodeList).length&&(o.closingModbus=!1,o.stateService.send("NEW"),o.stateService.send("INIT")),o.emit("mbregister",e)},o.setStoppedState=function(e,t){o.stateService.send("STOP"),o.emit("mbderegister",e),t()},o.closeConnectionWithoutRegisteredNodes=function(e,t){0===Object.keys(o.registeredNodeList).length?(o.closingModbus=!0,o.client&&"stopped"!==o.actualServiceState.value&&o.client.isOpen?o.client.close(function(){o.setStoppedState(e,t)}):o.setStoppedState(e,t)):o.setStoppedState(e,t)},o.deregisterForModbus=function(t,n){try{delete o.registeredNodeList[t],o.closingModbus?(n(),o.emit("mbderegister",t)):o.closeConnectionWithoutRegisteredNodes(t,n)}catch(e){r(e.message+" on de-register node "+t),o.error(e),n()}}}),a.httpAdmin.get("/modbus/serial/ports",a.auth.needsPermission("serial.read"),function(e,t){require("serialport").list().then(function(e){t.json(e)}).catch(function(e){t.json([e.message]),l.internalDebug(e.message)})})}; | ||
"use strict";module.exports=function(a){require("source-map-support").install();var c=require("./modbus-basics"),l=require("./core/modbus-client-core"),u=require("./core/modbus-queue-core"),d=require("debug")("contribModbus:config:client");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";this.clienttype=e.clienttype,void 0===e.parallelUnitIdsAllowed?this.bufferCommands=!0:this.bufferCommands=e.bufferCommands,this.queueLogEnabled=e.queueLogEnabled,this.stateLogEnabled=e.stateLogEnabled,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.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;var o=this;function r(e){a.settings.verbose&&o.warn("Client -> "+e+o.serverInfo)}function s(e){a.settings.verbose&&l.internalDebug("Client -> "+e+o.serverInfo)}o.isFirstInitOfConnection=!0,o.closingModbus=!1,o.client=null,o.bufferCommandList=new Map,o.sendingAllowed=new Map,o.unitSendingAllowed=[],o.messageAllowedStates=l.messagesAllowedStates,o.serverInfo="",o.stateMachine=null,o.stateService=null,o.stateMachine=l.createStateMachineService(),o.actualServiceState=o.stateMachine.initialState,o.actualServiceStateBefore=o.actualServiceState,o.stateService=l.startStateService(o.stateMachine),o.reconnectTimeoutId=0,o.serialSendingAllowed=!1,o.internalDebugLog=d,u.queueSerialLockCommand(o),o.setDefaultUnitId=function(){"tcp"===this.clienttype?o.unit_id=0:o.unit_id=1},o.setUnitIdFromPayload=function(e){var t=l.getActualUnitId(o,e);l.checkUnitId(t,o.clienttype)||o.setDefaultUnitId(),o.client.setID(t),e.unitId=t},!Number.isNaN(o.unit_id)&&l.checkUnitId(o.unit_id,o.clienttype)||o.setDefaultUnitId(),o.updateServerinfo=function(){"tcp"===o.clienttype?o.serverInfo=" TCP@"+o.tcpHost+":"+o.tcpPort:o.serverInfo=" Serial@"+o.serialPort+":"+o.serialBaudrate+"bit/s",o.serverInfo+=" default Unit-Id: "+o.unit_id},o.queueLog=function(e){o.bufferCommands&&o.queueLogEnabled&&s(e)},o.stateService.subscribe(function(e){var t;if(o.actualServiceStateBefore=o.actualServiceState,o.actualServiceState=e,t=e.value,o.stateLogEnabled&&s(t),e.value&&void 0!==o.actualServiceState.value&&o.actualServiceStateBefore.value!==o.actualServiceState.value){if(e.matches("init")){r("fsm init state after "+o.actualServiceStateBefore.value),o.updateServerinfo(),u.initQueue(o),o.reconnectTimeoutId=0;try{o.isFirstInitOfConnection?(o.isFirstInitOfConnection=!1,r("first fsm init in 500 ms"),setTimeout(o.connectClient,n)):(r("fsm init in "+o.reconnectTimeout+" ms"),setTimeout(o.connectClient,o.reconnectTimeout))}catch(e){o.error(e,{payload:"client connection error "+i})}o.emit("mbinit")}e.matches("connected")&&(r("fsm connected after state "+o.actualServiceStateBefore.value+i),u.queueSerialUnlockCommand(o),o.emit("mbconnected")),e.matches("activated")&&(o.emit("mbactive"),o.bufferCommands&&!u.checkQueuesAreEmpty(o)&&o.stateService.send("QUEUE")),e.matches("queueing")&&("tcp"===o.clienttype?o.stateService.send("SEND"):o.serialSendingAllowed&&(u.queueSerialLockCommand(o),o.stateService.send("SEND"))),e.matches("sending")&&(setTimeout(function(){u.dequeueCommand(o)},o.commandDelay),o.emit("mbqueue")),e.matches("opened")&&(u.queueSerialUnlockCommand(o),o.emit("mbopen")),e.matches("switch")&&(o.emit("mbswitch"),o.stateService.send("CLOSE")),e.matches("closed")&&(o.emit("mbclosed"),o.stateService.send("RECONNECT")),e.matches("stopped")&&(r("stopped state without reconnecting"),o.emit("mbclosed")),e.matches("failed")&&(r("fsm failed state after "+o.actualServiceStateBefore.value+i),o.emit("mberror","Modbus Failure On State "+o.actualServiceStateBefore.value+i),o.stateService.send("BREAK")),e.matches("broken")&&(r("fsm broken state after "+o.actualServiceStateBefore.value+i),o.emit("mbbroken","Modbus Broken On State "+o.actualServiceStateBefore.value+i),o.reconnectOnTimeout?o.stateService.send("RECONNECT"):o.stateService.send("ACTIVATE")),e.matches("reconnecting")&&(r("fsm reconnect state after "+o.actualServiceStateBefore.value+i),u.queueSerialLockCommand(o),o.emit("mbreconnecting"),o.reconnectTimeout<=0&&(o.reconnectTimeout=2e3),setTimeout(function(){o.reconnectTimeoutId=0,o.stateService.send("INIT")},o.reconnectTimeout))}}),o.connectClient=function(){if(o.client)try{o.client.close(function(){s("connection closed")}),s("connection close sent")}catch(e){s(e.message)}if(o.client=null,o.client=new t,o.clientTimeout||(o.clientTimeout=1e3),o.reconnectTimeout||(o.reconnectTimeout=2e3),"tcp"===o.clienttype){if(!l.checkUnitId(o.unit_id,o.clienttype))return o.error(new Error("wrong unit-id (0..255)"),{payload:o.unit_id}),void o.stateService.send("FAILURE");switch(o.tcpType){case"C701":s("C701 port UDP bridge"),o.client.connectC701(o.tcpHost,{port:o.tcpPort,autoOpen:!0}).then(o.setTCPConnectionOptions).then(o.setTCPConnected).catch(o.modbusTcpErrorHandling);break;case"TELNET":s("Telnet port"),o.client.connectTelnet(o.tcpHost,{port:o.tcpPort,autoOpen:!0}).then(o.setTCPConnectionOptions).catch(o.modbusTcpErrorHandling);break;case"TCP-RTU-BUFFERED":s("TCP RTU buffered port"),o.client.connectTcpRTUBuffered(o.tcpHost,{port:o.tcpPort,autoOpen:!0}).then(o.setTCPConnectionOptions).catch(o.modbusTcpErrorHandling);break;default:s("TCP port"),o.client.connectTCP(o.tcpHost,{port:o.tcpPort,autoOpen:!0}).then(o.setTCPConnectionOptions).catch(o.modbusTcpErrorHandling)}}else{if(!l.checkUnitId(o.unit_id,o.clienttype))return o.error(new Error("wrong unit-id serial (0..247)"),{payload:o.unit_id}),void o.stateService.send("FAILURE");if(o.serialConnectionDelay||(o.serialConnectionDelay=n),!o.serialPort)return o.error(new Error("wrong serial port"),{payload:o.serialPort}),void o.stateService.send("FAILURE");var e={baudRate:parseInt(o.serialBaudrate),dataBits:parseInt(o.serialDatabits),stopBits:parseInt(o.serialStopbits),parity:o.serialParity,autoOpen:!1};switch(o.serialType){case"ASCII":s("ASCII port serial"),o.client.connectAsciiSerial(o.serialPort,e).then(o.setSerialConnectionOptions).catch(o.modbusSerialErrorHandling);break;case"RTU":s("RTU port serial"),o.client.connectRTU(o.serialPort,e).then(o.setSerialConnectionOptions).catch(o.modbusSerialErrorHandling);break;default:s("RTU buffered port serial"),o.client.connectRTUBuffered(o.serialPort,e).then(o.setSerialConnectionOptions).catch(o.modbusSerialErrorHandling)}}},o.setTCPConnectionOptions=function(){o.client.setID(o.unit_id),o.client.setTimeout(o.clientTimeout),o.stateService.send("CONNECT")},o.setTCPConnected=function(){l.modbusSerialDebug("modbus tcp connected on "+o.tcpHost)},o.setSerialConnectionOptions=function(){o.stateService.send("OPENSERIAL"),setTimeout(o.openSerialClient,parseInt(o.serialConnectionDelay))},o.modbusErrorHandling=function(e){u.queueSerialUnlockCommand(o),e.message?l.modbusSerialDebug("modbusErrorHandling:"+e.message):l.modbusSerialDebug("modbusErrorHandling:"+JSON.stringify(e)),e.errno&&l.networkErrors.includes(e.errno)&&o.stateService.send("FAILURE")},o.modbusTcpErrorHandling=function(e){u.queueSerialUnlockCommand(o),o.showErrors&&o.error(e),e.message?l.modbusSerialDebug("modbusTcpErrorHandling:"+e.message):l.modbusSerialDebug("modbusTcpErrorHandling:"+JSON.stringify(e)),e.errno&&l.networkErrors.includes(e.errno)&&o.stateService.send("BREAK")},o.modbusSerialErrorHandling=function(e){u.queueSerialUnlockCommand(o),o.showErrors&&o.error(e),e.message?l.modbusSerialDebug("modbusSerialErrorHandling:"+e.message):l.modbusSerialDebug("modbusSerialErrorHandling:"+JSON.stringify(e)),o.stateService.send("BREAK")},o.openSerialClient=function(){"opened"===o.actualServiceState.value?(s("time to open Unit "+o.unit_id),l.modbusSerialDebug("modbus connection opened"),o.client.setID(o.unit_id),o.client.setTimeout(parseInt(o.clientTimeout)),o.client._port.on("close",o.onModbusClose),o.stateService.send("CONNECT")):(s("wrong state on connect serial "+o.actualServiceState.value),l.modbusSerialDebug("modbus connection not opened state is %s",o.actualServiceState.value),o.stateService.send("BREAK"))},o.onModbusClose=function(){u.queueSerialUnlockCommand(o),r("Modbus closed port"),l.modbusSerialDebug("modbus closed port"),o.stateService.send("CLOSE")},o.on("readModbus",function(t,e,n){var i=o.actualServiceState;-1===o.messageAllowedStates.indexOf(i.value)?n(new Error("Client Not Ready To Read At State "+i.value),t):o.bufferCommands?u.pushToQueueByUnitId(o,l.readModbus,t,e,n).then(function(){o.queueLog(JSON.stringify({info:"queued read msg",message:t.payload,state:i.value,queueLength:o.bufferCommandList.get(t.queueUnitId).length}))}).catch(function(e){n(e,t)}).finally(function(){o.stateService.send("QUEUE")}):l.readModbus(o,t,e,n)}),o.on("writeModbus",function(t,e,n){var i=o.actualServiceState;-1===o.messageAllowedStates.indexOf(i.value)?n(new Error("Client Not Ready To Write At State "+i.value),t):o.bufferCommands?u.pushToQueueByUnitId(o,l.writeModbus,t,e,n).then(function(){o.queueLog(JSON.stringify({info:"queued write msg",message:t.payload,state:i.value,queueLength:o.bufferCommandList.get(t.queueUnitId).length}))}).catch(function(e){n(e,t)}).finally(function(){o.stateService.send("QUEUE")}):l.writeModbus(o,t,e,n)}),o.activateSending=function(n){return o.sendingAllowed.set(n.queueUnitId,!0),u.queueSerialUnlockCommand(o),new Promise(function(e,t){try{o.bufferCommands&&(o.queueLog(JSON.stringify({info:"queue response activate sending",queueLength:o.bufferCommandList.length,sendingAllowed:o.sendingAllowed.get(n.queueUnitId),serialSendingAllowed:o.serialSendingAllowed,queueUnitId:n.queueUnitId})),u.checkQueuesAreEmpty(o)&&o.stateService.send("EMPTY")),e()}catch(e){t(e)}})},s("initialized"),o.setMaxListeners(0),o.on("reconnect",function(){o.stateService.send("CLOSE")}),o.on("dynamicReconnect",function(e,t,n){if(c.invalidPayloadIn(e))throw new Error("Message Or Payload Not Valid");l.internalDebug("Dynamic Reconnect Parameters "+JSON.stringify(e.payload)),l.setNewNodeSettings(o,e)?t(e):n(new Error("Message Or Payload Not Valid"),e),l.internalDebug("Dynamic Reconnect Starts on actual state "+o.actualServiceState.value),o.stateService.send("SWITCH")}),o.on("close",function(t){var n=o.name||o.id;o.closingModbus=!0,s("stop fsm on close "+n),o.stateService.send("STOP"),s("close node "+n),o.internalDebugLog("close node "+n),o.removeAllListeners(),o.client?o.client.isOpen?o.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())}),o.registeredNodeList={},o.registerForModbus=function(e){o.registeredNodeList[e]=e,1===Object.keys(o.registeredNodeList).length&&(o.closingModbus=!1,o.stateService.send("NEW"),o.stateService.send("INIT")),o.emit("mbregister",e)},o.setStoppedState=function(e,t){o.stateService.send("STOP"),o.emit("mbderegister",e),t()},o.closeConnectionWithoutRegisteredNodes=function(e,t){0===Object.keys(o.registeredNodeList).length?(o.closingModbus=!0,o.client&&"stopped"!==o.actualServiceState.value&&o.client.isOpen?o.client.close(function(){o.setStoppedState(e,t)}):o.setStoppedState(e,t)):o.setStoppedState(e,t)},o.deregisterForModbus=function(t,n){try{delete o.registeredNodeList[t],o.closingModbus?(n(),o.emit("mbderegister",t)):o.closeConnectionWithoutRegisteredNodes(t,n)}catch(e){r(e.message+" on de-register node "+t),o.error(e),n()}}}),a.httpAdmin.get("/modbus/serial/ports",a.auth.needsPermission("serial.read"),function(e,t){require("serialport").list().then(function(e){t.json(e)}).catch(function(e){t.json([e.message]),l.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;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;var t=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={},(r=new r({sandbox:{node:t}})).run("node.vector.getCoil = "+e.funcGetCoil),r.run("node.vector.getDiscreteInput = "+e.funcGetDiscreteInput),r.run("node.vector.getInputRegister = "+e.funcGetInputRegister),r.run("node.vector.getHoldingRegister = "+e.funcGetHoldingRegister),r.run("node.vector.setCoil = "+e.funcSetCoil),r.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._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.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),e.payload.disableMsgOutput||t.send(o(e)))}),t.on("close",function(){d.setNodeStatusTo("closed",t),t.modbusServer._server&&t.modbusServer._server.close(),t.modbusServer=null})})}catch(e){c(e.message)}}; | ||
"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;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;var t=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={},(r=new r({sandbox:{node:t}})).run("node.vector.getCoil = "+e.funcGetCoil),r.run("node.vector.getDiscreteInput = "+e.funcGetDiscreteInput),r.run("node.vector.getInputRegister = "+e.funcGetInputRegister),r.run("node.vector.getHoldingRegister = "+e.funcGetHoldingRegister),r.run("node.vector.setCoil = "+e.funcSetCoil),r.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._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.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),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.14.0", | ||
"version": "5.14.1", | ||
"private": false, | ||
"description": "The all in one Modbus TCP and Serial contribution package for Node-RED.", | ||
"dependencies": { | ||
"@xstate/fsm": "~1.6.0", | ||
"bson": "~4.3.0", | ||
@@ -13,8 +14,7 @@ "debug": "~4.3.1", | ||
"source-map-support": "~0.5.19", | ||
"vm2": "~3.9.3", | ||
"@xstate/fsm": "~1.6.0" | ||
"vm2": "~3.9.3" | ||
}, | ||
"optionalDependencies": { | ||
"serialport": "~9.0.7", | ||
"@serialport/list": "~9.0.7" | ||
"@serialport/list": "~9.0.7", | ||
"serialport": "~9.0.7" | ||
}, | ||
@@ -49,3 +49,4 @@ "keywords": [ | ||
"Modbus-IO-Config": "modbus/modbus-io-config.js", | ||
"Modbus-Response-Filter": "modbus/modbus-response-filter.js" | ||
"Modbus-Response-Filter": "modbus/modbus-response-filter.js", | ||
"Modbus-Flex-Sequencer": "modbus/modbus-flex-sequencer.js" | ||
} | ||
@@ -52,0 +53,0 @@ }, |
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
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
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
8353770
186
138140
21