Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let node = this
node.netServer = null
node.modbusServer = null
mbBasics.setNodeStatusTo('initialized', node)
let modbusLogLevel = 'warn'
if (RED.settings.verbose) {
modbusLogLevel = 'debug'
}
try {
node.netServer = new net.Server()
node.modbusServer = new modbus.server.TCP(node.netServer, {
'logLabel': 'ModbusServer',
'logLevel': modbusLogLevel,
'logEnabled': node.logEnabled,
'responseDelay': mbBasics.calc_rateByUnit(node.responseDelay, node.delayUnit),
'coils': Buffer.alloc(node.coilsBufferSize, 0),
'holding': Buffer.alloc(node.holdingBufferSize, 0),
'input': Buffer.alloc(node.inputBufferSize, 0),
'discrete': Buffer.alloc(node.discreteBufferSize, 0)
})
node.modbusServer.on('connection', function (client) {
internalDebugLog('Modbus Server client connection')
if (client && client.socket) {
internalDebugLog('Modbus Server client to ' + JSON.stringify(client.socket.address()) + ' from ' + client.socket.remoteAddress + ' ' + client.socket.remotePort)
}
mbBasics.setNodeStatusTo('active', node)