Skip to content

Implementation of the MODBUS IP/ASCII/RTU master and slave over TCP/UDP/Serial for Node.js.

License

Notifications You must be signed in to change notification settings

morkai/h5.modbus

Repository files navigation

h5.modbus

Implementation of the MODBUS IP/ASCII/RTU master and slave over TCP/UDP/Serial/WebSocket for Node.js.

TODO

  • Remaining messages
  • Tests
  • Documentation
  • npm publish

Requirements

Installation

npm install github:morkai/h5.modbus#master

Usage

'use strict';

const modbus = require('h5.modbus');

const slave = modbus.createSlave({requestHandler: handleRequest});
const master = modbus.createMaster();

master.once('open', () => master.readHoldingRegisters(0x0000, 10, handleResponse));

function handleRequest(unit, request, respond)
{
  respond(modbus.ExceptionCode.IllegalFunctionCode);
}

function handleResponse(err, res)
{
  if (err)
  {
    console.error(`[master#error] ${err.message}`);
  }
  else if (res.isException())
  {
    console.log(`[master#exception] ${res}`);
  }
  else
  {
    console.log(`[master#response] ${res}`);
  }
}

License

This project is released under the MIT License.

About

Implementation of the MODBUS IP/ASCII/RTU master and slave over TCP/UDP/Serial for Node.js.

Resources

License

Stars

Watchers

Forks

Packages

No packages published