Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
modbus-serial
Advanced tools
A pure JavaScript implemetation of MODBUS-RTU (and TCP) for NodeJS
This class makes ModbusRTU (and TCP) calls fun and easy.
Modbus is a serial communications protocol, first used in 1979. Modbus is simple and robust, openly published, royalty-free and easy to deploy and maintain.
npm install modbus-serial
This class makes it fun and easy to communicate with electronic devices such as irrigation controllers, protocol droids and robots. It talks with devices that use a serial line (e.g. RS485, RS232). Many industrial electronic devices implement modbus. Arduino can also talk modbus and you can control your projects and robots using modbus.
Arduino library for modbus slave: https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino
Arduino sketch for irrigation timer with modbus support: https://github.com/yaacov/irrigation-timer-for-arduino
This class implements FC3 "Read Holding Registers", FC4 "Read Input Registers" and FC16 "Preset Multiple Registers" of modbus-RTU.
https://github.com/voodootikigod/node-serialport
[ modbus-TCP connection is done using an internal port (see examples) ]
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort("/dev/ttyUSB0", {baudrate: 9600});
var ModbusRTU = require("modbus-serial");
var modbusRTU = new ModbusRTU(serialPort);
modbusRTU.open();
// write the values 0, 0xffff to registers starting at address 5
// on device number 1.
setTimeout(function() {
modbusRTU.writeFC16(1, 5, [0 , 0xffff]);
}, 1000);
// read the values of 2 registers starting at address 5
// on device number 1. and log the values to the console.
setTimeout(function() {
modbusRTU.writeFC4(1, 5, 2, function(err, data) {
console.log(data);
});
}, 2000);
// close communication
setTimeout(function() {
serialPort.close();
}, 3000);
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort("/dev/ttyUSB0", {baudrate: 9600});
var ModbusRTU = require("modbus-serial");
var modbusRTU = new ModbusRTU(serialPort);
modbusRTU.open();
// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
setInterval(function() {
modbusRTU.writeFC4(1, 0, 10, function(err, data) {
console.log(data.data);
});
}, 1000);
var TcpPort = require("modbus-serial").TcpPort;
var tcpPort = new TcpPort("192.168.1.42");
var ModbusRTU = require("modbus-serial");
var modbusRTU = new ModbusRTU(tcpPort);
modbusRTU.open();
// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
setInterval(function() {
modbusRTU.writeFC4(1, 0, 10, function(err, data) {
console.log(data.data);
});
}, 1000);
var SerialPort = require("serialport").SerialPort;
var serialPort = new SerialPort("/dev/ttyUSB0", {baudrate: 9600});
var ModbusRTU = require("modbus-serial");
var modbusRTU = new ModbusRTU(serialPort);
modbusRTU.open();
// read 2 16bit-registers to get one 32bit number
setTimeout(function() {
modbusRTU.writeFC4(1, 5, 2, function(err, data) {
console.log(data.buffer.readUInt32BE());
});
}, 2000);
// close communication
setTimeout(function() {
serialPort.close();
}, 3000);
Opens a modbus connection using the given serial port.
Called when a connection has been opened.
Writes "Read Holding Registers" (FC=03) request to serial port.
The slave unit address.
The Data Address of the first register.
The total number of registers requested.
Called once the unit returns an answer. The callback should be a function that looks like: function (error, data) { ... }
error - null on success, error string o/w
data - an object with two fildes:
data.data: array of unsinged 16 bit registers.
data.buffer: raw baffer of bytes returned by slave.
Writes "Read Input Registers" (FC=04) request to serial port.
The slave unit address.
The Data Address of the first register.
The total number of registers requested.
Called once the unit returns an answer. The callback should be a function that looks like: function (error, data) { ... }
error - null on success, error string o/w
data - an object with two fildes:
data.data: array of unsinged 16 bit registers.
data.buffer: raw baffer of bytes returned by slave.
Writes "Preset Multiple Registers" (FC=16) request to serial port.
The slave unit address.
The Data Address of the first register.
The array of values to set into the registers.
Called once the unit returns an answer. The callback should be a function that looks like: function (error, data) { ... }
FAQs
A pure JavaScript implemetation of MODBUS-RTU (Serial and TCP) for NodeJS.
The npm package modbus-serial receives a total of 2,645 weekly downloads. As such, modbus-serial popularity was classified as popular.
We found that modbus-serial demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.