UNPKG

node-red-contrib-modbus

Version:

The all in one Modbus TCP and Serial contribution long term supported package for Node-RED.

3 lines (2 loc) 1.63 kB
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