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

@softchef/modbus-poll

v1.0.51

Published

[![npm version](https://badge.fury.io/js/%40softchef%2Fmodbus-poll.svg)](https://badge.fury.io/js/%40softchef%2Fmodbus-poll) ![Release](https://github.com/SoftChef/modbus-poll/workflows/Release/badge.svg) ![npm](https://img.shields.io/npm/dt/@softchef/mod

Downloads

35

Readme

Modbus Poll

npm version Release npm

Modbus Poll can automation polling the Modbus devices by Modbus map table and convert to JSON object by defined property. This package is used modbus-serial package to connect Modbus protocol and operate Modbus commands.

Installation

NPM

npm install @softchef/modbus-poll

Yarn

yarn add @softchef/modbus-poll

Try these options on npm install to build, if you have problems to install

--unsafe-perm --build-from-source

Compatibility

Version of NodeJS: This module has not been tested on every single version of NodeJS. For best results you should stick to LTS versions, which are denoted by even major version numbers e.g. 4.x, 6.x, 8.x.

Config definition

new ModbusPoll(config)

  • type```: dbus client type, support ModbusTCP, ModbusRTU, ModbusRTUBuffered`.
  • name: fine connection name.
  • path: e ModbusRTU serial port path, ex: /dev/ttyUSB0.
  • host: e ModbusTCP IP address.
  • port: e ModbusTCP port, default is 502.
  • serialPorptions: The ModbusRTU options. Reference modbus-serial
  • serialPorptions.baudRate: The serial port's baud rate. Default is 9600.
  • interval: Set the polling interval, Default is 3000ms.
  • timeout: Set Modbus command's timeout. Default is 3000ms.
  • delay: Set read/write command's delay time. Default is 50ms.
  • sensors: Array of Modbus address table for read.
  • sensors[].thingName: Define device name.
  • sensors[].property: Define data property name.
  • sensors[].slaveId: The Modbus device's slave ID.
  • sensors[].functionCode:: The Modbus function code. Supports 0x01, 0x02, 0x03, 0x04. Reference modbus-serial functions.
  • sensors[].address: The Modbus register address.
  • sensors[].quantity: Read data length.
  • sensors[].endian?: The payload's endial, little or big or raw, Default is raw.
  • sensors[].decimal?: When data is a numberic, decimal will convert decimal places. Default is 0. Ex: decimal is 2, data is 2635, result is 26.35.
  • actuators: Array of Modbus address table for control.
  • actuators[].thingName: Define device name.
  • actuators[].property: Define data property name.
  • actuators[].slaveId: The Modbus device's slave ID.
  • actuators[].functionCode:: The Modbus function code. Supports 0x05, 0x06, 0x14, 0x15, 0x16. Reference modbus-serial functions.
  • actuators[].address: The Modbus register address.

Example

Polling Modbus device's data

const config = {}; // Reference config definition
const modbusPoll = new ModbusPoll(config);
await modbusPoll.connect();
modbusPoll.startPolling();
modbusPoll.on('data', (data) => {
  console.log('Receive polling data:', data);
});

Control Modbus device

const config = {
  ...,
  actuators: [
    {
      thingName: 'relay',
      property: 'ch1',
      slaveId: 1,
      functionCode: '0x05',
      address: '0x00'
    }
  ]
};
const modbusPoll = new ModbusPoll(config);
await modbusPoll.connect();
// Control relay.ch1 to "on" and delay 1000 ms.
modbusPoll.write('relay.ch1', 1, 1000)
// Control relay.ch1 to "off" after 1000 ms
modbusPoll.write('relay.ch1', 0)