Giter VIP home page Giter VIP logo

node-modbus-tcp's Introduction

Modbus TCP/IP Stream

Build Status

This is a very simple module that uses NodeJS Streams2 to read Modbus TCP data and convert it to JSON and vice-versa.

Upgrade

If you're just starting or just trying to use this library, I advise you to try modbus-stream. It's more complete (it supports all standard function codes) and it was designed to work with TCP, RTU and ASCII modes.

Install

npm install modbus-tcp

Example

var modbus = require("modbus-tcp");
var client = new modbus.Client();
var server = new modbus.Server();

// link client and server streams together
client.writer().pipe(server.reader());
server.writer().pipe(client.reader());
// if you have a socket (stream) you can just
// call client.pipe(socket) or server.pipe(socket)

server.on("read-coils", function (from, to, reply) {
    return reply(null, [ 1, 0, 1, 1 ]);
});

// read coils from unit id = 0, from address 10 to 13
client.readCoils(0, 10, 13, function (err, coils) {
    // coils = [ 1, 0, 1, 1 ]
});

Client Methods

All of the following read methods have the form method(unitId, from, to, next) and write methods have the form method(unitId, addr, val, next), where next is an optional function called if the server replies (with the same transactionId) to the sent message.

  • readCoils
  • readDiscreteInputs
  • readHoldingRegisters
  • readInputRegisters
  • writeSingleCoil
  • writeSingleRegister
  • writeMultipleCoils
  • writeMultipleRegisters

Addresses are exactly as is in protocol, so if you see a paper talking about address 40001 this usually means first record address of that function so it means address 0.

Server Events

  • read-coils
  • read-discrete-inputs
  • read-holding-registers
  • read-input-registers
  • write-single-coil
  • write-single-register
  • write-multiple-coils
  • write-multiple-registers
  • data

This last event is triggered when an unknown function code is received.

node-modbus-tcp's People

Contributors

dresende avatar jacobq avatar relovution avatar

Watchers

HelloWorld!!! avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.