How to use modbus-serial - 2 common examples

To help you get started, we’ve selected a few modbus-serial 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 kubeedge / kubeedge / mappers / modbus_mapper / sample / sample_server.js View on Github external
// Asynchronous handling supported also here
        console.log("set register", addr, value, unitID);
        holdingValue = value;
        return;
    },
    setCoil: function(addr, value, unitID) {
        // Asynchronous handling supported also here
        console.log("set coil", addr, value, unitID);
        coilValue = Boolean(value);
        return;
    },
};

// set the server to answer for modbus requests
console.log("ModbusTCP listening on modbus://127.0.0.1:5028");
var serverTCP = new ModbusRTU.ServerTCP(vector, { host: "0.0.0.0", port: 5028, debug: true, unitID: 1 });

serverTCP.on("socketError", function(err){
    // Handle socket error if needed, can be ignored
    console.error(err);
});
github BiancoRoyal / node-red-contrib-modbus / src / modbus-flex-server.js View on Github external
node.startServer = function () {
      try {
        if (node.modbusServer === null) {
          try {
            node.modbusServer = new ModbusRTU.ServerTCP(node.vector, {
              host: node.serverAddress,
              port: node.serverPort,
              debug: node.logEnabled,
              unitID: node.unitId
            })
          } catch (err) {
            node.error(err, { payload: 'server net error -> for port 502 on unix, you have to be a super user' })
          }

          node.modbusServer.on('socketError', function (err) {
            internalDebugLog(err.message)
            if (node.showErrors) {
              node.warn(err)
            }
            mbBasics.setNodeStatusTo('error', node)

modbus-serial

A pure JavaScript implemetation of MODBUS-RTU (Serial and TCP) for NodeJS.

ISC
Latest version published 5 months ago

Package Health Score

72 / 100
Full package analysis

Popular modbus-serial functions