How to use the jsmodbus.server function in jsmodbus

To help you get started, we’ve selected a few jsmodbus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BiancoRoyal / node-red-contrib-modbus / src / modbus-server.js View on Github external
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)

jsmodbus

Implementation for the Serial/TCP Modbus protocol.

MIT
Latest version published 4 months ago

Package Health Score

69 / 100
Full package analysis

Popular jsmodbus functions