node-red-contrib-modbus
Advanced tools
Comparing version 5.40.0 to 5.41.0
@@ -1,2 +0,2 @@ | ||
require("source-map-support").install();var de=de||{biancoroyal:{modbus:{io:{core:{}}}}};de.biancoroyal.modbus.io.core.internalDebug=de.biancoroyal.modbus.io.core.internalDebug||require("debug")("contribModbus:io:core"),de.biancoroyal.modbus.io.core.LineByLineReader=de.biancoroyal.modbus.io.core.LineByLineReader||require("line-by-line"),de.biancoroyal.modbus.io.core.core=de.biancoroyal.modbus.io.core.core||require("./modbus-core"),de.biancoroyal.modbus.io.core.nameValuesFromIOFile=function(r,e,s,a,t){var i=[],d=de.biancoroyal.modbus.io.core;return r.ioFile&&r.ioFile.configData&&r.ioFile.configData.forEach(function(e){e.valueAddress&&e.valueAddress.startsWith("%I")&&i.push(d.buildInputAddressMapping("MB-INPUTS",e,Number(r.ioFile.addressOffset),Number(t),r.logIOActivities)),e.valueAddress&&e.valueAddress.startsWith("%Q")&&i.push(d.buildOutputAddressMapping("MB-OUTPUTS",e,Number(r.ioFile.addressOffset),Number(t),r.logIOActivities))}),i=d.insertValues(i,s,r.logIOActivities),d.convertValuesByType(i,s,a,r.logIOActivities)},de.biancoroyal.modbus.io.core.allValueNamesFromIOFile=function(r){var s=[],a=de.biancoroyal.modbus.io.core;return r&&r.configData&&r.configData.forEach(function(e){e.valueAddress&&e.valueAddress.startsWith("%I")&&s.push(a.buildInputAddressMapping("MB-INPUTS",e,Number(r.addressOffset),0)),e.valueAddress&&e.valueAddress.startsWith("%Q")&&s.push(a.buildOutputAddressMapping("MB-OUTPUTS",e,Number(r.addressOffset),0))}),s},de.biancoroyal.modbus.io.core.getDataTypeFromFirstCharType=function(e){switch(e){case"w":return"Word";case"d":return"Double";case"r":return"Real";case"f":return"Float";case"i":return"Integer";case"l":return"Long";case"b":return"Boolean";default:return"Unsigned Integer"}},de.biancoroyal.modbus.io.core.buildInputAddressMapping=function(e,r,s,a,t){var i,d=de.biancoroyal.modbus.io.core,o=0,u=0,n=0,l=0,b=null,c=r.name.substring(0,1),m=r.valueAddress.substring(2,3),p=r.valueAddress.substring(0,3);switch(c){case"w":case"u":o=Number(r.valueAddress.split(p)[1]),n=1,l=16;break;case"i":o=Number(r.valueAddress.split(p)[1]),l="W"===m?(n=1,16):(n=2,32);break;case"r":case"f":o=Number(r.valueAddress.split(p)[1]),n=2,l=32;break;case"d":o=Number(r.valueAddress.split(p)[1]),n=4,l=64;break;case"l":o=Number(r.valueAddress.split(p)[1]),n=5,l=80;break;case"b":"X"===m&&(b=r.valueAddress.split("%IX")[1].split("."),o=Math.floor(Number(b[0])/2),u=8*Number(b[0])+Number(b[1]),l=n=1);break;default:t&&d.internalDebug("unknown input type "+c),l=0}return l?(i=o-(Number(s)||0),{register:e,name:r.name,addressStart:o,addressOffset:n,addressOffsetIO:Number(s)||0,addressStartIO:i,registerAddress:i-Number(a),coilStart:u,bitAddress:b,Bit:b?8*Number(b[0])+Number(b[1]):0,bits:l,dataType:d.getDataTypeFromFirstCharType(c),type:"input"}):{name:r.name,type:c,mapping:r,error:"variable name does not match input mapping"}},de.biancoroyal.modbus.io.core.buildOutputAddressMapping=function(e,r,s,a,t){var i,d=de.biancoroyal.modbus.io.core,o=0,u=0,n=0,l=0,b=null,c=r.name.substring(0,1),m=r.valueAddress.substring(2,3),p=r.valueAddress.substring(0,3);switch(c){case"w":case"u":o=Number(r.valueAddress.split(p)[1]),n=1,l=16;break;case"i":o=Number(r.valueAddress.split(p)[1]),l="W"===m?(n=1,16):(n=2,32);break;case"r":case"f":o=Number(r.valueAddress.split(p)[1]),n=2,l=32;break;case"d":o=Number(r.valueAddress.split(p)[1]),n=4,l=64;break;case"l":o=Number(r.valueAddress.split(p)[1]),n=5,l=80;break;case"b":"X"===m&&(b=r.valueAddress.split("%QX")[1].split("."),o=Math.floor(Number(b[0])/2),u=8*Number(b[0])+Number(b[1]),l=n=1);break;default:t&&d.internalDebug("unknown output type "+c),l=0}return l?(i=o-(Number(s)||0),{register:e,name:r.name,addressStart:o,addressOffset:n,addressOffsetIO:Number(s)||0,addressStartIO:i,registerAddress:i-Number(a),coilStart:u,bitAddress:b,Bit:b?8*Number(b[0])+Number(b[1]):0,bits:l,dataType:d.getDataTypeFromFirstCharType(c),type:"output"}):{name:r.name,type:c,mapping:r,error:"variable name does not match output mapping"}},de.biancoroyal.modbus.io.core.insertValues=function(e,r,s){var a=de.biancoroyal.modbus.io.core,t=0;for(t in e){var i=e[t];if(!i||!Object.prototype.hasOwnProperty.call(i,"registerAddress")||i.registerAddress<0)s&&a.internalDebug("Item Not Valid To Insert Value "+JSON.stringify(i));else{if(de.biancoroyal.modbus.io.core.isRegisterSizeWrong(r,i.registerAddress,Number(i.bits))){s&&a.internalDebug("Insert Value Register Reached At Address-Start-IO:"+i.registerAddress+" Bits:"+Number(i.bits));break}switch(Number(i.bits)){case 1:i.value=!!(r[i.registerAddress]&Math.pow(i.bitAddress[1],2));break;case 16:i.value=r[i.registerAddress];break;case 32:i.value=r[i.registerAddress+1]<<16|r[i.registerAddress];break;case 64:i.value=r[i.registerAddress+3]<<48|r[i.registerAddress+2]<<32|r[i.registerAddress+1]<<16|r[i.registerAddress];break;case 80:i.value=r[i.registerAddress+4]<<64|r[i.registerAddress+3]<<48|r[i.registerAddress+2]<<32|r[i.registerAddress+1]<<16|r[i.registerAddress];break;default:i.value=null}}}return e},de.biancoroyal.modbus.io.core.getValueFromBufferByDataType=function(e,r,s,a){var t,i,d=de.biancoroyal.modbus.io.core,o=s.length/2;if(r<0||r>s.length)a&&(d.internalDebug("Wrong Buffer Access Parameter Type:"+e.dataType+" Register-Length: "+o+" Buffer-Length:"+s.length+" Address-Buffer-Offset:"+r),d.internalDebug(JSON.stringify(e)));else switch(a&&d.internalDebug("Get Value From Buffer By Data Type:"+e.dataType+" Register:"+e.registerAddress+" Bits:"+Number(e.bits)),e.dataType){case"Boolean":e.value=!!(s.readUInt16BE(r)&Math.pow(e.bitAddress[1],2));break;case"Word":"8"===e.bits?e.value=s.readInt8(r):(e.value=s.readInt16BE(r),e.convertedValue=!1);break;case"Integer":switch(e.bits){case"8":e.value=s.readInt8(r);break;case"32":e.value=s.readInt32BE(r);break;case"64":t=s.readUInt32BE(4),i=s.readUInt32BE(0),e.value=i*Math.pow(2,32)+t;break;default:e.value=s.readInt16BE(r)}break;case"Real":case"Float":e.value=s.readFloatBE(r,4);break;case"Double":e.value=s.readDoubleBE(r,8);break;case"Long":e.value=s.readDoubleBE(r,10);break;default:switch(e.bits){case"8":e.value=s.readUInt8(r);break;case"32":e.value=s.readUInt32BE(r);break;case"64":e.value=s.readUIntBE(r,8);break;default:e.value=s.readUInt16BE(r),e.convertedValue=!1}}return e},de.biancoroyal.modbus.io.core.convertValuesByType=function(e,r,s,a){var t,i=de.biancoroyal.modbus.io.core,d=0;for(d in e){var o=e[d];if(!o||!Object.prototype.hasOwnProperty.call(o,"dataType")||!Object.prototype.hasOwnProperty.call(o,"registerAddress")||o.registerAddress<0)a&&i.internalDebug("Item Not Valid To Convert "+JSON.stringify(o));else{if(de.biancoroyal.modbus.io.core.isRegisterSizeWrong(r,o.registerAddress,Number(o.bits))){a&&i.internalDebug("Insert Value Register Reached At Address-Start-IO:"+o.registerAddress+" Bits:"+Number(o.bits));break}if(!(s.buffer instanceof Buffer)){a&&i.internalDebug("Response Buffer Is Not A Buffer");break}t=2*Number(o.registerAddress);try{i.getValueFromBufferByDataType(o,t,s.buffer,a)}catch(e){i.internalDebug(e.message)}}}return e},de.biancoroyal.modbus.io.core.filterValueNames=function(e,r,s,a,t){var i,d,o,u;return r.length&&r.filter?(i=de.biancoroyal.modbus.io.core,d=2!==s&&4!==s?"input":"output",o=a,u=Number(a)+Number(t)-1,e.logIOActivities&&i.internalDebug("adr:"+a+" quantity:"+t+" startRegister:"+o+" endRegister:"+u+" functionType:"+d),r.filter(function(e){return 0<=e.registerAddress&&e.addressStartIO>=o&&e.addressStartIO<=u&&e.type===d})):r},de.biancoroyal.modbus.io.core.isRegisterSizeWrong=function(e,r,s){s=Number(s)||16,r=Number(r),s=16<s?r+s/16-1:r;return r<0||e.length<r||s>e.length},de.biancoroyal.modbus.io.core.buildMessageWithIO=function(e,r,s,a){var t=this.core.getOriginalMessage(e.bufferMessageList,a),i=(t.modbusRequest=Object.assign({},a.payload),t.payload=r,t.topic=a.topic,t.responseBuffer=s,Object.assign({},t));return i.payload=s,i.values=r,delete i.responseBuffer,e.useIOFile&&e.ioFile.lastUpdatedAt&&(s=this.nameValuesFromIOFile(e,a,r,s,parseInt(a.payload.address)||0),s=this.filterValueNames(e,s,parseInt(a.payload.fc)||3,parseInt(a.payload.address)||0,parseInt(a.payload.quantity)||1,e.logIOActivities),e.useIOForPayload?(t.payload=s,t.values=r):(t.payload=r,t.valueNames=s),i.valueNames=s),[t,i]},module.exports=de.biancoroyal.modbus.io.core; | ||
require("source-map-support").install();var de=de||{biancoroyal:{modbus:{io:{core:{}}}}};de.biancoroyal.modbus.io.core.internalDebug=de.biancoroyal.modbus.io.core.internalDebug||require("debug")("contribModbus:io:core"),de.biancoroyal.modbus.io.core.LineByLineReader=de.biancoroyal.modbus.io.core.LineByLineReader||require("line-by-line"),de.biancoroyal.modbus.io.core.core=de.biancoroyal.modbus.io.core.core||require("./modbus-core"),de.biancoroyal.modbus.io.core.nameValuesFromIOFile=function(r,e,s,a,t){var i=[],d=de.biancoroyal.modbus.io.core;return r.ioFile&&r.ioFile.configData&&r.ioFile.configData.forEach(function(e){e.valueAddress&&e.valueAddress.startsWith("%I")&&i.push(d.buildInputAddressMapping("MB-INPUTS",e,Number(r.ioFile.addressOffset),Number(t),r.logIOActivities)),e.valueAddress&&e.valueAddress.startsWith("%Q")&&i.push(d.buildOutputAddressMapping("MB-OUTPUTS",e,Number(r.ioFile.addressOffset),Number(t),r.logIOActivities))}),i=d.insertValues(i,s,r.logIOActivities),d.convertValuesByType(i,s,a,r.logIOActivities)},de.biancoroyal.modbus.io.core.allValueNamesFromIOFile=function(r){var s=[],a=de.biancoroyal.modbus.io.core;return r&&r.configData&&r.configData.forEach(function(e){e.valueAddress&&e.valueAddress.startsWith("%I")&&s.push(a.buildInputAddressMapping("MB-INPUTS",e,Number(r.addressOffset),0)),e.valueAddress&&e.valueAddress.startsWith("%Q")&&s.push(a.buildOutputAddressMapping("MB-OUTPUTS",e,Number(r.addressOffset),0))}),s},de.biancoroyal.modbus.io.core.getDataTypeFromFirstCharType=function(e){switch(e){case"w":return"Word";case"d":return"Double";case"r":return"Real";case"f":return"Float";case"i":return"Integer";case"l":return"Long";case"b":return"Boolean";default:return"Unsigned Integer"}},de.biancoroyal.modbus.io.core.buildInputAddressMapping=function(e,r,s,a,t){var i,d=de.biancoroyal.modbus.io.core,o=0,u=0,n=0,l=0,b=null,c=r.name.substring(0,1),m=r.valueAddress.substring(2,3),p=r.valueAddress.substring(0,3);switch(c){case"w":case"u":o=Number(r.valueAddress.split(p)[1]),n=1,l=16;break;case"i":o=Number(r.valueAddress.split(p)[1]),l="W"===m?(n=1,16):(n=2,32);break;case"r":case"f":o=Number(r.valueAddress.split(p)[1]),n=2,l=32;break;case"d":o=Number(r.valueAddress.split(p)[1]),n=4,l=64;break;case"l":o=Number(r.valueAddress.split(p)[1]),n=5,l=80;break;case"b":"X"===m&&(b=r.valueAddress.split("%IX")[1].split("."),o=Math.floor(Number(b[0])/2),u=8*Number(b[0])+Number(b[1]),l=n=1);break;default:t&&d.internalDebug("unknown input type "+c),l=0}return l?(i=o-(Number(s)||0),{register:e,name:r.name,addressStart:o,addressOffset:n,addressOffsetIO:Number(s)||0,addressStartIO:i,registerAddress:i-Number(a),coilStart:u,bitAddress:b,Bit:b?8*Number(b[0])+Number(b[1]):0,bits:l,dataType:d.getDataTypeFromFirstCharType(c),type:"input"}):{name:r.name,type:c,mapping:r,error:"variable name does not match input mapping"}},de.biancoroyal.modbus.io.core.buildOutputAddressMapping=function(e,r,s,a,t){var i,d=de.biancoroyal.modbus.io.core,o=0,u=0,n=0,l=0,b=null,c=r.name.substring(0,1),m=r.valueAddress.substring(2,3),p=r.valueAddress.substring(0,3);switch(c){case"w":case"u":o=Number(r.valueAddress.split(p)[1]),n=1,l=16;break;case"i":o=Number(r.valueAddress.split(p)[1]),l="W"===m?(n=1,16):(n=2,32);break;case"r":case"f":o=Number(r.valueAddress.split(p)[1]),n=2,l=32;break;case"d":o=Number(r.valueAddress.split(p)[1]),n=4,l=64;break;case"l":o=Number(r.valueAddress.split(p)[1]),n=5,l=80;break;case"b":"X"===m&&(b=r.valueAddress.split("%QX")[1].split("."),o=Math.floor(Number(b[0])/2),u=8*Number(b[0])+Number(b[1]),l=n=1);break;default:t&&d.internalDebug("unknown output type "+c),l=0}return l?(i=o-(Number(s)||0),{register:e,name:r.name,addressStart:o,addressOffset:n,addressOffsetIO:Number(s)||0,addressStartIO:i,registerAddress:i-Number(a),coilStart:u,bitAddress:b,Bit:b?8*Number(b[0])+Number(b[1]):0,bits:l,dataType:d.getDataTypeFromFirstCharType(c),type:"output"}):{name:r.name,type:c,mapping:r,error:"variable name does not match output mapping"}},de.biancoroyal.modbus.io.core.insertValues=function(e,r,s){var a=de.biancoroyal.modbus.io.core,t=0;for(t in e){var i=e[t];if(!i||!Object.prototype.hasOwnProperty.call(i,"registerAddress")||i.registerAddress<0)s&&a.internalDebug("Item Not Valid To Insert Value "+JSON.stringify(i));else{if(de.biancoroyal.modbus.io.core.isRegisterSizeWrong(r,i.registerAddress,Number(i.bits))){s&&a.internalDebug("Insert Value Register Reached At Address-Start-IO:"+i.registerAddress+" Bits:"+Number(i.bits));break}switch(Number(i.bits)){case 1:i.value=!!(r[i.registerAddress]&Math.pow(i.bitAddress[1],2));break;case 16:i.value=r[i.registerAddress];break;case 32:i.value=r[i.registerAddress+1]<<16|r[i.registerAddress];break;case 64:i.value=r[i.registerAddress+3]<<48|r[i.registerAddress+2]<<32|r[i.registerAddress+1]<<16|r[i.registerAddress];break;case 80:i.value=r[i.registerAddress+4]<<64|r[i.registerAddress+3]<<48|r[i.registerAddress+2]<<32|r[i.registerAddress+1]<<16|r[i.registerAddress];break;default:i.value=null}}}return e},de.biancoroyal.modbus.io.core.getValueFromBufferByDataType=function(e,r,s,a){var t,i,d=de.biancoroyal.modbus.io.core,o=s.length/2;if(r<0||s.length<r)a&&(d.internalDebug("Wrong Buffer Access Parameter Type:"+e.dataType+" Register-Length: "+o+" Buffer-Length:"+s.length+" Address-Buffer-Offset:"+r),d.internalDebug(JSON.stringify(e)));else switch(a&&d.internalDebug("Get Value From Buffer By Data Type:"+e.dataType+" Register:"+e.registerAddress+" Bits:"+Number(e.bits)),e.dataType){case"Boolean":e.value=!!(s.readUInt16BE(r)&Math.pow(e.bitAddress[1],2));break;case"Word":"8"===e.bits?e.value=s.readInt8(r):(e.value=s.readInt16BE(r),e.convertedValue=!1);break;case"Integer":switch(e.bits){case"8":e.value=s.readInt8(r);break;case"32":e.value=s.readInt32BE(r);break;case"64":t=s.readUInt32BE(4),i=s.readUInt32BE(0),e.value=i*Math.pow(2,32)+t;break;default:e.value=s.readInt16BE(r)}break;case"Real":case"Float":e.value=s.readFloatBE(r,4);break;case"Double":e.value=s.readDoubleBE(r,8);break;case"Long":e.value=s.readDoubleBE(r,10);break;default:switch(e.bits){case"8":e.value=s.readUInt8(r);break;case"32":e.value=s.readUInt32BE(r);break;case"64":e.value=s.readUIntBE(r,8);break;default:e.value=s.readUInt16BE(r),e.convertedValue=!1}}return e},de.biancoroyal.modbus.io.core.convertValuesByType=function(e,r,s,a){var t,i=de.biancoroyal.modbus.io.core,d=0;for(d in e){var o=e[d];if(!o||!Object.prototype.hasOwnProperty.call(o,"dataType")||!Object.prototype.hasOwnProperty.call(o,"registerAddress")||o.registerAddress<0)a&&i.internalDebug("Item Not Valid To Convert "+JSON.stringify(o));else{if(de.biancoroyal.modbus.io.core.isRegisterSizeWrong(r,o.registerAddress,Number(o.bits))){a&&i.internalDebug("Insert Value Register Reached At Address-Start-IO:"+o.registerAddress+" Bits:"+Number(o.bits));break}if(!(s.buffer instanceof Buffer)){a&&i.internalDebug("Response Buffer Is Not A Buffer");break}t=2*Number(o.registerAddress);try{i.getValueFromBufferByDataType(o,t,s.buffer,a)}catch(e){i.internalDebug(e.message)}}}return e},de.biancoroyal.modbus.io.core.filterValueNames=function(e,r,s,a,t){var i,d,o,u;return r.length&&r.filter?(i=de.biancoroyal.modbus.io.core,d=2!==s&&4!==s?"input":"output",o=a,u=Number(a)+Number(t)-1,e.logIOActivities&&i.internalDebug("adr:"+a+" quantity:"+t+" startRegister:"+o+" endRegister:"+u+" functionType:"+d),r.filter(function(e){return 0<=e.registerAddress&&o<=e.addressStartIO&&e.addressStartIO<=u&&e.type===d})):r},de.biancoroyal.modbus.io.core.isRegisterSizeWrong=function(e,r,s){s=Number(s)||16,r=Number(r),s=16<s?r+s/16-1:r;return r<0||e.length<r||s>e.length},de.biancoroyal.modbus.io.core.buildMessageWithIO=function(e,r,s,a){var t=this.core.getOriginalMessage(e.bufferMessageList,a),i=(t.modbusRequest=Object.assign({},a.payload),t.payload=r,t.topic=a.topic,t.responseBuffer=s,Object.assign({},t));return i.payload=s,i.values=r,delete i.responseBuffer,e.useIOFile&&e.ioFile.lastUpdatedAt&&(s=this.nameValuesFromIOFile(e,a,r,s,parseInt(a.payload.address)||0),s=this.filterValueNames(e,s,parseInt(a.payload.fc)||3,parseInt(a.payload.address)||0,parseInt(a.payload.quantity)||1,e.logIOActivities),e.useIOForPayload?(t.payload=s,t.values=r):(t.payload=r,t.valueNames=s),i.valueNames=s),[t,i]},module.exports=de.biancoroyal.modbus.io.core; | ||
//# sourceMappingURL=../maps/core/modbus-io-core.js.map |
@@ -1,2 +0,2 @@ | ||
require("source-map-support").install();var _=require("underscore"),de=de||{biancoroyal:{modbus:{core:{server:{}}}}};de.biancoroyal.modbus.core.server.internalDebug=de.biancoroyal.modbus.core.server.internalDebug||require("debug")("contribModbus:core:server"),de.biancoroyal.modbus.core.server.bufferFactor=8,de.biancoroyal.modbus.core.server.memoryTypes=["holding","coils","input","discrete"],de.biancoroyal.modbus.core.server.memoryUint16Types=["holding","input"],de.biancoroyal.modbus.core.server.memoryUint8Types=["coils","discrete"],de.biancoroyal.modbus.core.server.getLogFunction=function(e){return e.internalDebugLog||de.biancoroyal.modbus.core.server.internalDebug},de.biancoroyal.modbus.core.server.isValidMemoryMessage=function(e){return!1===_.isUndefined(e.payload)&&e.payload.register&&Number.isInteger(e.payload.address)&&0<=e.payload.address&&e.payload.address<=65535},de.biancoroyal.modbus.core.server.isValidMessage=function(e){return!1===_.isUndefined(e)&&!1===_.isUndefined(e.payload)},de.biancoroyal.modbus.core.server.copyToModbusFlexBuffer=function(e,r){switch(r.payload.register){case"holding":r.bufferData.copy(e.registers,r.bufferSplitAddress);break;case"coils":r.bufferData.copy(e.coils,r.bufferAddress);break;case"input":r.bufferData.copy(e.registers,r.bufferAddress);break;case"discrete":r.bufferData.copy(e.coils,r.bufferSplitAddress);break;default:return!1}return!0},de.biancoroyal.modbus.core.server.writeToModbusFlexBuffer=function(e,r){switch(r.payload.register){case"holding":e.registers.writeUInt16BE(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt16BE(0):r.bufferPayload,r.bufferSplitAddress);break;case"coils":e.coils.writeUInt8(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt8(0):r.bufferPayload,r.bufferAddress);break;case"input":e.registers.writeUInt16BE(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt16BE(0):r.bufferPayload,r.bufferAddress);break;case"discrete":e.coils.writeUInt8(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt8(0):r.bufferPayload,r.bufferSplitAddress);break;default:return!1}return!0},de.biancoroyal.modbus.core.server.writeModbusFlexServerMemory=function(e,r){var o=de.biancoroyal.modbus.core.server;return r.bufferSplitAddress=(parseInt(r.payload.address)+parseInt(e.splitAddress))*o.bufferFactor,r.bufferAddress=parseInt(r.payload.address)*o.bufferFactor,o.convertInputForBufferWrite(r)?o.copyToModbusFlexBuffer(e,r):o.writeToModbusFlexBuffer(e,r)},de.biancoroyal.modbus.core.server.convertInputForBufferWrite=function(e){var r,o=!1;return null!=(r=e.payload.value)&&r.length?(e.bufferPayload=new Uint8Array(null==(r=e.payload)?void 0:r.value),e.bufferData=Buffer.alloc(e.bufferPayload.buffer.byteLength,e.bufferPayload),e.wasMultipleWrite=o=!0):(e.bufferPayload=Number(e.payload.value),e.wasMultipleWrite=!1),o},de.biancoroyal.modbus.core.server.copyToModbusBuffer=function(e,r){switch(r.payload.register){case"holding":r.bufferData.copy(e.modbusServer.holding,r.bufferAddress);break;case"coils":r.bufferData.copy(e.modbusServer.coils,r.bufferAddress);break;case"input":r.bufferData.copy(e.modbusServer.input,r.bufferAddress);break;case"discrete":r.bufferData.copy(e.modbusServer.discrete,r.bufferAddress);break;default:return!1}return!0},de.biancoroyal.modbus.core.server.writeToModbusBuffer=function(e,r){switch(r.payload.register){case"holding":e.modbusServer.holding.writeUInt16BE(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt16BE(0):r.bufferPayload,r.bufferAddress);break;case"coils":e.modbusServer.coils.writeUInt8(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt8(0):r.bufferPayload,r.bufferAddress);break;case"input":e.modbusServer.input.writeUInt16BE(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt16BE(0):r.bufferPayload,r.bufferAddress);break;case"discrete":e.modbusServer.discrete.writeUInt8(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt8(0):r.bufferPayload,r.bufferAddress);break;default:return!1}return!0},de.biancoroyal.modbus.core.server.writeModbusServerMemory=function(e,r){var o=de.biancoroyal.modbus.core.server;return r.bufferAddress=parseInt(r.payload.address)*o.bufferFactor,o.convertInputForBufferWrite(r)?o.copyToModbusBuffer(e,r):o.writeToModbusBuffer(e,r)},de.biancoroyal.modbus.core.server.writeToServerMemory=function(r,o){var e=de.biancoroyal.modbus.core.server;o.payload.register=o.payload.register.toLowerCase();try{e.memoryTypes.includes(o.payload.register)&&e.writeModbusServerMemory(r,o)}catch(e){o.error=e,r.error(e)}},de.biancoroyal.modbus.core.server.writeToFlexServerMemory=function(r,o){var e=de.biancoroyal.modbus.core.server;o.payload.register=o.payload.register?o.payload.register.toLowerCase():void 0;try{e.memoryTypes.includes(o.payload.register)&&e.writeModbusFlexServerMemory(r,o)}catch(e){o.error=e,r.error(e)}},module.exports=de.biancoroyal.modbus.core.server; | ||
require("source-map-support").install();var _=require("underscore"),de=de||{biancoroyal:{modbus:{core:{server:{}}}}};de.biancoroyal.modbus.core.server.internalDebug=de.biancoroyal.modbus.core.server.internalDebug||require("debug")("contribModbus:core:server"),de.biancoroyal.modbus.core.server.bufferFactor=8,de.biancoroyal.modbus.core.server.memoryTypes=["holding","coils","input","discrete"],de.biancoroyal.modbus.core.server.memoryUint16Types=["holding","input"],de.biancoroyal.modbus.core.server.memoryUint8Types=["coils","discrete"],de.biancoroyal.modbus.core.server.getLogFunction=function(e){return e.internalDebugLog||de.biancoroyal.modbus.core.server.internalDebug},de.biancoroyal.modbus.core.server.isValidMemoryMessage=function(e){return!1===_.isUndefined(e.payload)&&e.payload.register&&Number.isInteger(e.payload.address)&&0<=e.payload.address&&e.payload.address<=65535},de.biancoroyal.modbus.core.server.isValidMessage=function(e){return!1===_.isUndefined(e)&&!1===_.isUndefined(e.payload)},de.biancoroyal.modbus.core.server.copyToModbusFlexBuffer=function(e,r){switch(r.payload.register){case"holding":r.bufferData.copy(e.registers,r.bufferSplitAddress);break;case"coils":r.bufferData.copy(e.coils,r.bufferAddress);break;case"input":r.bufferData.copy(e.registers,r.bufferAddress);break;case"discrete":r.bufferData.copy(e.coils,r.bufferSplitAddress);break;default:return!1}return!0},de.biancoroyal.modbus.core.server.writeToModbusFlexBuffer=function(e,r){switch(r.payload.register){case"holding":e.registers.writeUInt16BE(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt16BE(0):r.bufferPayload,r.bufferSplitAddress);break;case"coils":e.coils.writeUInt8(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt8(0):r.bufferPayload,r.bufferAddress);break;case"input":e.registers.writeUInt16BE(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt16BE(0):r.bufferPayload,r.bufferAddress);break;case"discrete":e.coils.writeUInt8(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt8(0):r.bufferPayload,r.bufferSplitAddress);break;default:return!1}return!0},de.biancoroyal.modbus.core.server.writeModbusFlexServerMemory=function(e,r){var o=de.biancoroyal.modbus.core.server;return r.bufferSplitAddress=(parseInt(r.payload.address)+parseInt(e.splitAddress))*o.bufferFactor,r.bufferAddress=parseInt(r.payload.address)*o.bufferFactor,o.convertInputForBufferWrite(r)?o.copyToModbusFlexBuffer(e,r):o.writeToModbusFlexBuffer(e,r)},de.biancoroyal.modbus.core.server.convertInputForBufferWrite=function(e){var r,o=!1;return null!=(r=e.payload.value)&&r.length?(e.bufferPayload=new Uint8Array(null==(r=e.payload)?void 0:r.value),e.bufferData=Buffer.alloc(e.bufferPayload.buffer.byteLength,e.bufferPayload),e.wasMultipleWrite=o=!0):(e.bufferPayload=Number(e.payload.value),e.wasMultipleWrite=!1),o},de.biancoroyal.modbus.core.server.copyToModbusBuffer=function(e,r){switch(r.payload.register){case"holding":r.bufferData.copy(e.modbusServer.holding,r.bufferAddress);break;case"coils":r.bufferData.copy(e.modbusServer.coils,r.bufferAddress);break;case"input":r.bufferData.copy(e.modbusServer.input,r.bufferAddress);break;case"discrete":r.bufferData.copy(e.modbusServer.discrete,r.bufferAddress);break;default:return!1}return!0},de.biancoroyal.modbus.core.server.writeToModbusBuffer=function(e,r){switch(r.payload.register){case"holding":e.modbusServer.holding.writeUInt16BE(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt16BE(0):r.bufferPayload,r.bufferAddress);break;case"coils":e.modbusServer.coils.writeUInt8(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt8(0):r.bufferPayload,r.bufferAddress);break;case"input":e.modbusServer.input.writeUInt16BE(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt16BE(0):r.bufferPayload,r.bufferAddress);break;case"discrete":e.modbusServer.discrete.writeUInt8(Buffer.isBuffer(r.bufferPayload)?r.bufferPayload.readUInt8(0):r.bufferPayload,r.bufferAddress);break;default:return!1}return!0},de.biancoroyal.modbus.core.server.writeModbusServerMemory=function(e,r){var o=de.biancoroyal.modbus.core.server;return r.bufferAddress=parseInt(r.payload.address)*o.bufferFactor,o.convertInputForBufferWrite(r)?o.copyToModbusBuffer(e,r):o.writeToModbusBuffer(e,r)},de.biancoroyal.modbus.core.server.writeToServerMemory=function(r,o){var e=de.biancoroyal.modbus.core.server;o.payload.register=o.payload.register.toLowerCase();try{e.memoryTypes.includes(o.payload.register)&&e.writeModbusServerMemory(r,o)}catch(e){o.error=e,r.error(e)}},de.biancoroyal.modbus.core.server.writeToFlexServerMemory=function(r,o){var e=de.biancoroyal.modbus.core.server;o.payload.register=o.payload.register?o.payload.register.toLowerCase():void 0;try{e.memoryTypes.includes(o.payload.register)&&e.writeModbusFlexServerMemory(r,o)}catch(e){r.error(o.error=e)}},module.exports=de.biancoroyal.modbus.core.server; | ||
//# sourceMappingURL=../maps/core/modbus-server-core.js.map |
@@ -9,3 +9,5 @@ { | ||
"showWarnings": "Show Warnings", | ||
"server": "Server" | ||
"server": "Server", | ||
"emptyMsgOnFail": "Leere msg bei Modbus-Fehler", | ||
"configMsgOnChange": "Config msg bei Modbus-Change" | ||
}, | ||
@@ -12,0 +14,0 @@ "tabs-label": { |
@@ -9,3 +9,5 @@ { | ||
"showWarnings": "Show Warnings", | ||
"server": "Server" | ||
"server": "Server", | ||
"emptyMsgOnFail": "Empty Message on Modbus failure", | ||
"configMsgOnChange": "Config msg on Modbus-Change" | ||
}, | ||
@@ -12,0 +14,0 @@ "tabs-label": { |
@@ -1,2 +0,2 @@ | ||
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("@open-p4nr/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.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()),r.client.removeAllListeners()):(s("Connection closed simple "+n),t()),r.removeAllListeners()}),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")&&!e.actualServiceState.matches("activated")&&(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)})})}; | ||
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("@open-p4nr/modbus-serial"),n=500,i=" Get More About It By Logging",r=(this.clienttype=e.clienttype,this.bufferCommands=void 0===e.parallelUnitIdsAllowed||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,this.parallelUnitIdsAllowed=void 0===e.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.parallelUnitIdsAllowed?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(t,e,n){if(c.invalidPayloadIn(t))throw new Error("Message Or Payload Not Valid");try{u.internalDebug("Dynamic Reconnect Parameters "+JSON.stringify(t.payload)),u.setNewNodeSettings(r,t)?e(t):n(new Error("Message Or Payload Not Valid"),t),u.internalDebug("Dynamic Reconnect Starts on actual state "+r.actualServiceState.value),r.stateService.send("SWITCH")}catch(e){n(e,t)}}),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.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()),r.client.removeAllListeners()):(s("Connection closed simple "+n),t()),r.removeAllListeners()}),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")&&!e.actualServiceState.matches("activated")&&(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 @@ | ||
module.exports=function(t){require("source-map-support").install();var o=require("./modbus-basics"),i=require("debug")("contribModbus:flex:connector");t.nodes.registerType("modbus-flex-connector",function(e){t.nodes.createNode(this,e),this.name=e.name,this.maxReconnectsPerMinute=e.maxReconnectsPerMinute||4,this.emptyQueue=e.emptyQueue,this.showStatusActivities=e.showStatusActivities,this.showErrors=e.showErrors,this.connection=null,this.internalDebugLog=i,this.verboseLogging=t.settings.verbose,this.server=t.nodes.getNode(e.server);var s=this;o.setNodeStatusTo("waiting",s),this.server&&(this.server.registerForModbus(s),o.initModbusClientEvents(s,this.server),s.onConfigDone=function(e){var t=s.showStatusActivities;t&&o.setNodeStatusTo("config done",s),t&&o.setNodeStatusTo(this.server.actualServiceState,s),t||o.setNodeDefaultStatus(s),e.error.nodeStatus=s.statusText,s.emptyMsgOnFail&&(e.payload=""),s.send(e)},s.on("input",function(e){var t;o.invalidPayloadIn(e)||(s.showStatusActivities&&o.setNodeStatusTo(this.server.actualServiceState,s),e.payload.connectorType?(i("dynamicReconnect: ".concat(JSON.stringify(e.payload))),e.payload.emptyQueue=s.emptyQueue,this.server.emit("dynamicReconnect",e,s.onConfigDone,s.onConfigError)):(t=new Error("Payload Not Valid - Connector Type"),s.error(t,e),s.send(e)))}),s.showStatusActivities||o.setNodeDefaultStatus(s))})}; | ||
module.exports=function(t){require("source-map-support").install();var o=require("./modbus-basics"),n=require("debug")("contribModbus:flex:connector");t.nodes.registerType("modbus-flex-connector",function(e){t.nodes.createNode(this,e),this.name=e.name,this.maxReconnectsPerMinute=e.maxReconnectsPerMinute||4,this.emptyQueue=e.emptyQueue,this.showStatusActivities=e.showStatusActivities,this.showErrors=e.showErrors,this.connection=null,this.internalDebugLog=n,this.verboseLogging=t.settings.verbose,this.server=t.nodes.getNode(e.server),this.emptyMsgOnFail=e.emptyMsgOnFail,this.configMsgOnChange=e.configMsgOnChange;var s=this;o.setNodeStatusTo("waiting",s),s.server?(o.setNodeStatusTo("connecting",s),s.server.registerForModbus(s),o.initModbusClientEvents(s,this.server),s.onConfigDone=function(e){s.showStatusActivities?o.setNodeStatusTo(s.server.actualServiceState,s):o.setNodeDefaultStatus(s),s.configMsgOnChange?(e.payload=e.payload||{},e.payload.status="changed"):e.config_change="emitted",s.send(e)},s.onConfigError=function(e,t){n(e.message),s.showErrors&&(s.showStatusActivities?o.setNodeStatusTo("error",s):o.setNodeDefaultStatus(s),e&&e.message?t.error=e:t.error=new Error(e),t.error.nodeStatus=s.statusText,s.error(t.error,t),s.emptyMsgOnFail&&(t.payload=""),s.send(t))},s.on("input",function(e){var t;o.invalidPayloadIn(e)||(s.showStatusActivities&&o.setNodeStatusTo(s.server.actualServiceState,s),e.payload.connectorType?(n("dynamicReconnect: ".concat(JSON.stringify(e.payload))),e.payload.emptyQueue=s.emptyQueue,s.server.emit("dynamicReconnect",e,s.onConfigDone,s.onConfigError)):(t=new Error("Payload Not Valid - Connector Type"),s.error(t,e),s.send(e)))}),s.showStatusActivities?o.setNodeStatusTo("active",s):o.setNodeDefaultStatus(s)):o.setNodeStatusTo("disconnected",s)})}; | ||
//# sourceMappingURL=maps/modbus-flex-connector.js.map |
@@ -1,2 +0,2 @@ | ||
module.exports=function(t){require("source-map-support").install();var o=require("./modbus-basics"),n=require("./core/modbus-core"),s=require("./core/modbus-io-core"),d=require("debug")("contribModbus:flex:getter");t.nodes.registerType("modbus-flex-getter",function(e){t.nodes.createNode(this,e),this.name=e.name,this.showStatusActivities=e.showStatusActivities,this.showErrors=e.showErrors,this.showWarnings=e.showWarnings,this.connection=null,this.useIOFile=e.useIOFile,this.ioFile=t.nodes.getNode(e.ioFile),this.useIOForPayload=e.useIOForPayload,this.logIOActivities=e.logIOActivities,this.emptyMsgOnFail=e.emptyMsgOnFail,this.keepMsgProperties=e.keepMsgProperties,this.internalDebugLog=d,this.verboseLogging=t.settings.verbose,this.delayOnStart=e.delayOnStart,this.startDelayTime=parseInt(e.startDelayTime)||10;var i=this,a=(i.bufferMessageList=new Map,i.INPUT_TIMEOUT_MILLISECONDS=1e3,i.delayOccured=!1,i.inputDelayTimer=null,o.setNodeStatusTo("waiting",i),t.nodes.getNode(e.server));function r(e){t.settings.verbose&&i.showWarnings&&i.warn("Flex-Getter -> "+e)}a&&(a.registerForModbus(i),o.initModbusClientEvents(i,a),i.onModbusReadDone=function(e,t){i.showStatusActivities&&o.setNodeStatusTo("reading done",i),i.send(s.buildMessageWithIO(i,e.data,e,t)),i.emit("modbusFlexGetterNodeDone")},i.errorProtocolMsg=function(e,t){i.showErrors&&o.logMsgError(i,e,t)},i.onModbusReadError=function(e,t){i.internalDebugLog(e.message);var s=n.getOriginalMessage(i.bufferMessageList,t);i.errorProtocolMsg(e,s),o.sendEmptyMsgOnFail(i,e,t),o.setModbusError(i,a,e,s),i.emit("modbusFlexGetterNodeError")},i.prepareMsg=function(e){return"string"==typeof e.payload&&(e.payload=JSON.parse(e.payload)),e.payload.fc=parseInt(e.payload.fc)||3,e.payload.unitid=parseInt(e.payload.unitid),e.payload.address=parseInt(e.payload.address)||0,e.payload.quantity=parseInt(e.payload.quantity)||1,e},i.isValidModbusMsg=function(e){var t=!0;return Number.isInteger(e.payload.fc)&&1<=e.payload.fc&&e.payload.fc<=4||(i.error("FC Not Valid",e),t&=!1),!t||Number.isInteger(e.payload.address)&&0<=e.payload.address&&e.payload.address<=65535||(i.error("Address Not Valid",e),t&=!1),!t||Number.isInteger(e.payload.quantity)&&1<=e.payload.quantity&&e.payload.quantity<=65535||(i.error("Quantity Not Valid",e),t&=!1),t},i.buildNewMessageObject=function(e,t){var s=n.getObjectId();return{topic:t.topic||e.id,messageId:s,payload:{value:t.payload.value||t.value,unitid:t.payload.unitid,fc:t.payload.fc,address:t.payload.address,quantity:t.payload.quantity,emptyMsgOnFail:e.emptyMsgOnFail,keepMsgProperties:e.keepMsgProperties,messageId:s}}},i.isReadyForInput=function(){return a.client&&a.isActive()&&i.delayOccured},i.isNotReadyForInput=function(){return!i.isReadyForInput()},i.resetInputDelayTimer=function(){i.inputDelayTimer&&(r("reset input delay timer node "+i.id),clearTimeout(i.inputDelayTimer)),i.inputDelayTimer=null,i.delayOccured=!1},i.initializeInputDelayTimer=function(){i.resetInputDelayTimer(),i.delayOnStart?(r("initialize input delay timer node "+i.id),i.inputDelayTimer=setTimeout(function(){i.delayOccured=!0},i.INPUT_TIMEOUT_MILLISECONDS*i.startDelayTime)):i.delayOccured=!0},i.initializeInputDelayTimer(),i.on("input",function(t){if(o.invalidPayloadIn(t))r("Invalid message on input.");else if(i.isNotReadyForInput())r("Inject while node is not ready for input.");else if(a.isInactive())r("You sent an input to inactive client. Please use initial delay on start or send data more slowly.");else{t=Object.assign({},t);try{var e,s=i.prepareMsg(t);i.isValidModbusMsg(s)&&(e=i.buildNewMessageObject(i,s),i.bufferMessageList.set(e.messageId,o.buildNewMessage(i.keepMsgProperties,s,e)),a.emit("readModbus",e,i.onModbusReadDone,i.onModbusReadError))}catch(e){i.errorProtocolMsg(e,t),o.sendEmptyMsgOnFail(i,e,t)}i.showStatusActivities&&o.setNodeStatusTo(a.actualServiceState,i)}}),i.on("close",function(e){i.resetInputDelayTimer(),o.setNodeStatusTo("closed",i),i.bufferMessageList.clear(),a.deregisterForModbus(i.id,e)}),i.showStatusActivities||o.setNodeDefaultStatus(i))})}; | ||
module.exports=function(s){require("source-map-support").install();var n=require("./modbus-basics"),i=require("./core/modbus-core"),d=require("./core/modbus-io-core"),u=require("debug")("contribModbus:flex:getter");s.nodes.registerType("modbus-flex-getter",function(e){s.nodes.createNode(this,e),this.name=e.name,this.showStatusActivities=e.showStatusActivities,this.showErrors=e.showErrors,this.showWarnings=e.showWarnings,this.connection=null,this.useIOFile=e.useIOFile,this.ioFile=s.nodes.getNode(e.ioFile),this.useIOForPayload=e.useIOForPayload,this.logIOActivities=e.logIOActivities,this.emptyMsgOnFail=e.emptyMsgOnFail,this.keepMsgProperties=e.keepMsgProperties,this.internalDebugLog=u,this.verboseLogging=s.settings.verbose,this.delayOnStart=e.delayOnStart,this.startDelayTime=parseInt(e.startDelayTime)||10;var a,r=this,o=(r.bufferMessageList=new Map,r.INPUT_TIMEOUT_MILLISECONDS=1e3,r.delayOccured=!1,r.inputDelayTimer=null,n.setNodeStatusTo("waiting",r),s.nodes.getNode(e.server));function t(e){s.settings.verbose&&r.showWarnings&&r.warn("Flex-Getter -> "+e)}o&&(o.registerForModbus(r),n.initModbusClientEvents(r,o),r.onModbusReadDone=function(e,t){r.showStatusActivities&&n.setNodeStatusTo("reading done",r),r.send(d.buildMessageWithIO(r,e.data,e,t)),r.emit("modbusFlexGetterNodeDone")},r.errorProtocolMsg=function(e,t){r.showErrors&&n.logMsgError(r,e,t)},r.onModbusReadError=function(e,t){r.internalDebugLog(e.message);var s=i.getOriginalMessage(r.bufferMessageList,t);r.errorProtocolMsg(e,s),n.sendEmptyMsgOnFail(r,e,t),n.setModbusError(r,o,e,s),r.emit("modbusFlexGetterNodeError")},r.prepareMsg=function(e){return"string"==typeof e.payload&&(e.payload=JSON.parse(e.payload)),e.payload.fc=parseInt(e.payload.fc)||3,e.payload.unitid=parseInt(e.payload.unitid),e.payload.address=parseInt(e.payload.address)||0,e.payload.quantity=parseInt(e.payload.quantity)||1,e},r.isValidModbusMsg=function(e){var t=!0;return Number.isInteger(e.payload.fc)&&1<=e.payload.fc&&e.payload.fc<=4||(r.error("FC Not Valid",e),t&=!1),!t||Number.isInteger(e.payload.address)&&0<=e.payload.address&&e.payload.address<=65535||(r.error("Address Not Valid",e),t&=!1),!t||Number.isInteger(e.payload.quantity)&&1<=e.payload.quantity&&e.payload.quantity<=65535||(r.error("Quantity Not Valid",e),t&=!1),t},r.buildNewMessageObject=function(e,t){var s=i.getObjectId();return{topic:t.topic||e.id,messageId:s,payload:{value:t.payload.value||t.value,unitid:t.payload.unitid,fc:t.payload.fc,address:t.payload.address,quantity:t.payload.quantity,emptyMsgOnFail:e.emptyMsgOnFail,keepMsgProperties:e.keepMsgProperties,messageId:s}}},r.isReadyForInput=function(){return o.client&&o.isActive()&&r.delayOccured},r.isNotReadyForInput=function(){return!r.isReadyForInput()},r.resetInputDelayTimer=function(){r.inputDelayTimer&&(t("reset input delay timer node "+r.id),clearTimeout(r.inputDelayTimer)),r.inputDelayTimer=null,r.delayOccured=!1},r.initializeInputDelayTimer=function(){r.resetInputDelayTimer(),r.delayOnStart?(t("initialize input delay timer node "+r.id),r.inputDelayTimer=setTimeout(function(){r.delayOccured=!0},r.INPUT_TIMEOUT_MILLISECONDS*r.startDelayTime)):r.delayOccured=!0},r.initializeInputDelayTimer(),a=[],r.on("input",function(e){n.invalidPayloadIn(e)?t("Invalid message on input."):r.isNotReadyForInput()?t("Inject while node is not ready for input."):o.isInactive()?t("You sent an input to inactive client. Please use initial delay on start or send data more slowly."):(a.push(e),function e(){if(0===a.length)return void r.emit("modbusFlexGetterNodeDone");var t=a.shift();t=Object.assign({},t);try{var s,i=r.prepareMsg(t);r.isValidModbusMsg(i)?(s=r.buildNewMessageObject(r,i),r.bufferMessageList.set(s.messageId,n.buildNewMessage(r.keepMsgProperties,i,s)),o.emit("readModbus",s,r.onModbusReadDone,r.onModbusReadError)):(r.errorProtocolMsg(new Error("Invalid Modbus message"),t),n.sendEmptyMsgOnFail(r,new Error("Invalid Modbus message"),t))}catch(e){r.errorProtocolMsg(e,t),n.sendEmptyMsgOnFail(r,e,t)}e()}())}),r.on("close",function(e){r.resetInputDelayTimer(),n.setNodeStatusTo("closed",r),r.bufferMessageList.clear(),o.deregisterForModbus(r.id,e)}),r.showStatusActivities||n.setNodeDefaultStatus(r))})}; | ||
//# sourceMappingURL=maps/modbus-flex-getter.js.map |
@@ -1,2 +0,2 @@ | ||
module.exports=function(i){require("source-map-support").install();var r=require("./core/modbus-io-core");i.nodes.registerType("modbus-io-config",function(e){var t=require("fs-extra"),a=(i.nodes.createNode(this,e),this.name=e.name,this.path=e.path,this.format=e.format,this.addressOffset=e.addressOffset,this);function n(){a.lineReader.removeAllListeners(),a.lineReader.on("error",function(e){r.internalDebug(e.message)}),a.lineReader.on("line",function(e){e&&a.configData.push(e)}),a.lineReader.on("end",function(){a.lastUpdatedAt=Date.now(),r.internalDebug("Read IO Done From File "+a.path),a.warn({payload:r.allValueNamesFromIOFile(a),name:"Modbus Value Names From IO File",path:a.path}),a.emit("updatedConfig",a.configData)}),r.internalDebug("Loading IO File Started For "+a.path)}a.setMaxListeners(0),a.lastUpdatedAt=null,t.existsSync(a.path)?(a.lineReader=new r.LineByLineReader(a.path),r.internalDebug("Read IO File "+a.path),a.configData=[],n(),a.watcher=t.watchFile(a.path,function(e,t){r.internalDebug("the current mtime is: ".concat(e.mtime)),r.internalDebug("the previous mtime was: ".concat(t.mtime)),e.mtime!==t.mtime&&(r.internalDebug("Reload IO File "+a.path),a.configData=[],delete a.lastUpdatedAt,a.lineReader.removeAllListeners(),a.lineReader=new r.LineByLineReader(a.path),n(),r.internalDebug("Reloading IO File Started For "+a.path))}),a.on("close",function(e){t.unwatchFile(a.path),a.watcher.stop(),a.lineReader.removeAllListeners(),a.removeAllListeners(),e()})):(r.internalDebug("IO File Not Found "+a.path),a.warn("Modbus IO File Not Found "+a.path))})}; | ||
module.exports=function(i){require("source-map-support").install();var r=require("./core/modbus-io-core");i.nodes.registerType("modbus-io-config",function(e){var a,t=require("fs-extra"),n=(i.nodes.createNode(this,e),this.name=e.name,this.path=e.path,this.format=e.format,this.addressOffset=e.addressOffset,this);n.setMaxListeners(0),n.lastUpdatedAt=null,t.existsSync(n.path)?(a=function(){n.lineReader.removeAllListeners(),n.lineReader.on("error",function(e){r.internalDebug(e.message)}),n.lineReader.on("line",function(e){e&&n.configData.push(e)}),n.lineReader.on("end",function(){n.lastUpdatedAt=Date.now(),r.internalDebug("Read IO Done From File "+n.path),n.warn({payload:r.allValueNamesFromIOFile(n),name:"Modbus Value Names From IO File",path:n.path}),n.emit("updatedConfig",n.configData)}),r.internalDebug("Loading IO File Started For "+n.path)},n.lineReader=new r.LineByLineReader(n.path),r.internalDebug("Read IO File "+n.path),n.configData=[],a(),n.watcher=t.watchFile(n.path,function(e,t){r.internalDebug("the current mtime is: ".concat(e.mtime)),r.internalDebug("the previous mtime was: ".concat(t.mtime)),e.mtime!==t.mtime&&(r.internalDebug("Reload IO File "+n.path),n.configData=[],delete n.lastUpdatedAt,n.lineReader.removeAllListeners(),n.lineReader=new r.LineByLineReader(n.path),a(),r.internalDebug("Reloading IO File Started For "+n.path))})):(r.internalDebug("IO File Not Found "+n.path),n.warn("Modbus IO File Not Found "+n.path)),n.on("close",function(e){t.unwatchFile(n.path),n.watcher.stop(),n.lineReader.removeAllListeners(),n.removeAllListeners(),e()})})}; | ||
//# sourceMappingURL=maps/modbus-io-config.js.map |
{ | ||
"name": "node-red-contrib-modbus", | ||
"version": "5.40.0", | ||
"version": "5.41.0", | ||
"private": false, | ||
@@ -60,5 +60,3 @@ "description": "The all in one Modbus TCP and Serial contribution long term supported package for Node-RED.", | ||
"modbus", | ||
"extras/argumentMaps/defaults", | ||
"extras/argumentMaps/ArgumentMaps.md", | ||
".npmrc" | ||
"extras" | ||
], | ||
@@ -71,4 +69,4 @@ "bugs": { | ||
"changelog": "npm run rewrite-changelog", | ||
"test": "npm run lint && mocha ./test --parallel --recursive --reporter dot", | ||
"test:slow": "npm run lint && mocha ./test --recursive --reporter dot", | ||
"test": "npm run lint && mocha ./test --parallel --recursive --reporter dot --timeout 6000", | ||
"test:slow": "npm run lint && mocha ./test --recursive --reporter dot --timeout 12000", | ||
"test:verbose": "npm run lint && mocha ./test --recursive", | ||
@@ -79,3 +77,3 @@ "test:withStop": "npm run lint && mocha ./test --recursive --bail", | ||
"test:e2e": "npm run lint && mocha './test/units/modbus-write-e2e-test.js' --parallel --recursive --reporter dot --timeout 100000", | ||
"test:units": "npm run lint && mocha './test/units/modbus-client-test.js' --parallel --recursive --reporter dot --timeout 100000", | ||
"test:units": "npm run lint && mocha './test/units/modbus-client-test.js' --parallel --recursive --reporter dot", | ||
"test:core": "npm run lint && mocha './test/core/*-test.js' --parallel --recursive", | ||
@@ -85,6 +83,6 @@ "test-nyc": "nyc --reporter=html --reporter=text mocha --recursive", | ||
"test-with-coverage": "nyc --reporter=lcovonly mocha --recursive -R spec && cat ./coverage/lcov.info | codacy-coverage --token $CODACY_COVERAGE_TOKEN && rm -rf ./coverage", | ||
"coverage": "npm run lint && nyc mocha ./test --parallel --recursive --reporter dot --timeout 10000", | ||
"coverage": "npm run lint && nyc --reporter=html --reporter=text mocha ./test --parallel --recursive --reporter dot --timeout 10000", | ||
"coverage-nyc": "npm run lint && nyc report --reporter=text-lcov | coveralls", | ||
"build": "npm run lint && gulp", | ||
"prepublishOnly": "npm run lint && npm run rewrite-changelog && npm test && mocha test --recursive --reporter dot && npm run test-npx && npm run build", | ||
"prepublishOnly": "npm run clean && npm run lint && npm run rewrite-changelog && npm test && npm run coverage && npm run build", | ||
"ci-publish": "ci-publish", | ||
@@ -125,3 +123,3 @@ "release": "standard-version -a", | ||
"nock": "^13.5.4", | ||
"node-red": "^4.0.0-beta.4", | ||
"node-red": "^4.0.2", | ||
"node-red-node-test-helper": "^0.3.4", | ||
@@ -128,0 +126,0 @@ "nyc": "^15.1.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8698044
199
139627