npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-red-contrib-modbus-api

v0.3.0

Published

Modbus-Server API nodes.

Downloads

225

Readme

node-red-contrib-modbus-api

Build Status

Create your own modbus-server graphically in node-red as you would create an http API. Configure modbus-in nodes for every possible address you want to supply, gather and prepare a response in the flow and conclude with a modbus-out node to transmit the respose back to the client.

A request consists of a modbus register and a modbus function code (FC)

Supported nodejs versions are 8, 10 and 12 as well as node-red in version 0.18.x - 1.x and up. Previous versions of node-red might also work, but are not tested.

Installation

To install run

npm install node-red-contrib-modbus-api --production

Omit the --production flag, in order to install the development dependencies for testing and coverage.

This node depends on modbus-serial as the main package and will install it along with it.

Usage

Screenshot 01 - Multiple modbus API flows

After a first modbus in node is placed a modbus server has to be created and assigned to it. This server will be the source for the node of any requests a client will send to the bound address and port.

Screenshot 02 - Modbus in config page

The modbus in node will then spawn messages on it's node output whenever a request on the modbus server matches the configured register, command and unitID of the modbus in node.

Screenshot 03 - Modbus server config page

Within the flow you may retrieve any data from within node-red. Be aware, that the default timeout for some of the modbus clients is gracefully chosen to be around 2000ms. In most cases this may be much shorter, so pay attantion to the round-trip time of you messages and request handling.

After you placed some data into the payload of your flows message you may send it to a modbus out node. Currently this node just takes care of validating the input message and invokes the modbus response. In future versions of this node it may be possible to also specify modbus response propertie like error or exception codes.

Details of Implementation

For a detailed overview of the modbus protocol see the modbus specification document (v1_1b3).

The following read and write functions are implemented:

  • FC 1 Read Input Register
  • FC 2 Read Descrete Value
  • FC 3 Read Holding Register
  • FC 4 Read Coil
  • FC 5 Set Register
  • FC 6 Set Coil

This is also coupled to the implementation status of the modbus-serial package.

Modbus Responses and Exceptions

There are basic exceptions provided by the node-modbus-serial package.

Implemented error codes for request/response are:

  • 0x02 - invalid register

Request size

Currently it is not possible to request more than 128 registers at a time. This will cause node-red to crash. I'm on it to implement a fix in the underlying library. It will not be possible to request more than that though.

Contribution

To setup your local development environment first clone this repository and then use docker to get your node-red environment up and running like this:

sudo docker run -p 1880:1880 -v $PWD:/tmp/node-red-contrib-modbus-api:Z -d --name nodered nodered/node-red-docker

After you saved your changes to the code update the installation within the container with this command:

sudo docker exec -it nodered npm install /tmp/node-red-contrib-modbus-api/ && sudo docker restart nodered

Note on --privileged and -u root: This could be required on linux machines with SELinux to avoid permission errors. Keep in mind that this is insecure and considered real bad practice. Alternativly configure your SELinux to allow access from the container to the local mounted volume in order to install the npm dependencies. This should be avoidable with the :Z flag behind volume definition.

Testing and Coverage-Report

First npm install for the dev dependencies. Tests, linting and code coverage are then available through:

npm test
npm run coverage
npm run lint

License

The BSD 3-Clause License

Alexander Wellbrock

Roadmap

  • Implementation of write functions
  • Automatically create a modbus server if there is none
  • Hook into the modbus-serial debug function and get it out to node-red
  • Implement modbus exceptions for the modbus out node
  • Implement data type selection and validation for modbus out node