All Projects → yaacov → Node Modbus Serial

yaacov / Node Modbus Serial

Licence: isc
A pure JavaScript implemetation of MODBUS-RTU (and TCP) for NodeJS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Modbus Serial

Modbus Tcp Client
PHP client for Modbus TCP and Modbus RTU over TCP (can be used for serial)
Stars: ✭ 89 (-72.62%)
Mutual labels:  modbus-tcp
EasyModbusTCP.Java
EasyModbusTCP library for Java implementation
Stars: ✭ 76 (-76.62%)
Mutual labels:  modbus-tcp
Modbus-TCP
Modbus TCP client library to interact with Modbus servers such as PLCs.
Stars: ✭ 43 (-86.77%)
Mutual labels:  modbus-tcp
Genmon
Generac Generator Monitoring using a Raspberry Pi and WiFi
Stars: ✭ 143 (-56%)
Mutual labels:  modbus-tcp
Pyscada
PyScada is a open source scada system that uses the Django framework as backend
Stars: ✭ 233 (-28.31%)
Mutual labels:  modbus-tcp
huawei solar
Home Assistant integration for Huawei Solar inverters via Modbus
Stars: ✭ 126 (-61.23%)
Mutual labels:  modbus-tcp
Esp32modbustcp
Modbus client for ESP32
Stars: ✭ 51 (-84.31%)
Mutual labels:  modbus-tcp
solaredge modbus
SolarEdge Modbus data collection library
Stars: ✭ 49 (-84.92%)
Mutual labels:  modbus-tcp
Mbusd
Open-source Modbus TCP to Modbus RTU (RS-232/485) gateway.
Stars: ✭ 233 (-28.31%)
Mutual labels:  modbus-tcp
go-modbus
modbus write in pure go, support rtu,ascii,tcp master library,also support tcp slave.(WIP new implement<old: https://github.com/thinkgos/gomodbus >)
Stars: ✭ 124 (-61.85%)
Mutual labels:  modbus-tcp
Jlibmodbus
JLibModbus is an implementation of the Modbus protocol v1.1b in java language.
Stars: ✭ 149 (-54.15%)
Mutual labels:  modbus-tcp
Modbustool
A modbus master and slave test tool with import and export functionality, supports TCP, UDP and RTU.
Stars: ✭ 187 (-42.46%)
Mutual labels:  modbus-tcp
ModbusMechanic
Cross platform GUI MODBUS TCP/RTU simulator & gateway. Interprets data types including ascii float and int.
Stars: ✭ 63 (-80.62%)
Mutual labels:  modbus-tcp
Modbuspp
A C++ Library for Modbus TCP Protocol
Stars: ✭ 108 (-66.77%)
Mutual labels:  modbus-tcp
Regulator
DIY Arduino consumption regulator build to use excess solar power for auxiliary 'summer' heating. The solar power data are retrieved over SunSpec Modbus TCP. IoT monitoring with Blynk and local Web server.
Stars: ✭ 32 (-90.15%)
Mutual labels:  modbus-tcp
Pymodbus
A full modbus protocol written in python
Stars: ✭ 1,225 (+276.92%)
Mutual labels:  modbus-tcp
modbus-esp8266
Most complete Modbus library for Arduino. A library that allows your Arduino board to communicate via Modbus protocol, acting as a master, slave or both. Supports network transport (Modbus TCP) and Serial line/RS-485 (Modbus RTU). Supports Modbus TCP Security for ESP8266/ESP32.
Stars: ✭ 332 (+2.15%)
Mutual labels:  modbus-tcp
Node Modbus
Modbus TCP Client/Server implementation for Node.JS
Stars: ✭ 313 (-3.69%)
Mutual labels:  modbus-tcp
rodbus
Rust implementation of Modbus with idiomatic bindings for C, C++, .NET, and Java
Stars: ✭ 34 (-89.54%)
Mutual labels:  modbus-tcp
arduino-modbus-rtu-tcp-gateway
Arduino-based Modbus RTU to Modbus TCP/UDP gateway with web interface. Allows you to connect Modbus RTU slaves (such as sensors, energy meters, HVAC devices) to Modbus TCP/UDP masters (such as home automation systems). You can adjust settings through web interface.
Stars: ✭ 56 (-82.77%)
Mutual labels:  modbus-tcp

modbus-serial

A pure JavaScript implemetation of MODBUS-RTU (Serial and TCP) for NodeJS.

NPM download NPM version Build Status

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.

This package makes Modbus calls and serve fun and easy.



Install

npm install modbus-serial

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

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

What can I do with this module ?

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 libraries for modbus slave:

Arduino sketch for irrigation timer with modbus support:

Node Modbus-WebSocket bridge:

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.

These classes are implemented:
Class Function
FC1 "Read Coil Status" readCoils(coil, len)
FC2 "Read Input Status" readDiscreteInputs(addr, arg)
FC3 "Read Holding Registers" readHoldingRegisters(addr, len)
FC4 "Read Input Registers" readInputRegisters(addr, len)
FC5 "Force Single Coil" writeCoil(coil, binary) //NOT setCoil
FC6 "Preset Single Register"
FC15 "Force Multiple Coil" writeRegister(addr, value)
FC16 "Preset Multiple Registers" writeRegisters(addr, valueAry)
FC43/14 "Read Device Identification" (supported ports: TCP, RTU) readDeviceIdentification(id, obj)
Client Serial:
  • modbus-RTU (SerialPort): Over serial line [require node serialport].
  • modbus-RTU (RTUBufferedPort): Over buffered serial line [require node serialport].
  • modbus-ASCII (AsciiPort): Over serial line [require node serialport].
Client TCP:
  • modbus-TCP (TcpPort): Over TCP/IP line.
  • modbus-RTU (UdpPort): Over C701 server, commercial UDP to serial bridge.
  • modbus-RTU (TcpRTUBufferedPort): Over TCP/IP line, TCP/IP serial RTU buffered device.
  • modbus-RTU (TelnetPort): Over Telnet server, TCP/IP serial bridge.
Server
  • modbus-TCP (ServerTCP): Over TCP/IP line.

Examples

Read and Write
// create an empty modbus client
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();

// open connection to a serial port
client.connectRTUBuffered("/dev/ttyUSB0", { baudRate: 9600 }, write);

function write() {
    client.setID(1);

    // write the values 0, 0xffff to registers starting at address 5
    // on device number 1.
    client.writeRegisters(5, [0 , 0xffff])
        .then(read);
}

function read() {
    // read the 2 registers starting at address 5
    // on device number 1.
    client.readHoldingRegisters(5, 2)
        .then(console.log);
}

Read on multiple slaves
const ModbusRTU = require("modbus-serial");
// create an empty modbus client
const client = new ModbusRTU();
// open connection to a serial port
client.connectRTUBuffered("/dev/ttyS0", { baudRate: 9600 });
// set timeout, if slave did not reply back
client.setTimeout(500);

// list of meter's id
const metersIdList = [10, 11, 12, 13, 14];

const getMetersValue = async (meters) => {
    try{
        // get value of all meters
        for(let meter of meters) {
            // output value to console
            console.log(await getMeterValue(meter));
            // wait 100ms before get another device
            await sleep(100);
	}
    } catch(e){
        // if error, handle them here (it should not)
        console.log(e)
    } finally {
        // after get all data from salve repeate it again
        setImmediate(() => {
            getMetersValue(metersIdList);
        })
    }
}

const getMeterValue = async (id) => {
    try {
        // set ID of slave
        await client.setID(id);
        // read the 1 registers starting at address 0 (first register)
        let val =  await client.readInputRegisters(0, 1);
        // return the value
        return val.data[0];
    } catch(e){
        // if error return -1
        return -1
    }
}

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));


// start get value
getMetersValue(metersIdList);


Logger Serial
// create an empty modbus client
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();

// open connection to a serial port
client.connectRTUBuffered("/dev/ttyUSB0", { baudRate: 9600 });
client.setID(1);

// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
setInterval(function() {
    client.readHoldingRegisters(0, 10, function(err, data) {
        console.log(data.data);
    });
}, 1000);

Logger TCP
// create an empty modbus client
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();

// open connection to a tcp line
client.connectTCP("127.0.0.1", { port: 8502 });
client.setID(1);

// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
setInterval(function() {
    client.readHoldingRegisters(0, 10, function(err, data) {
        console.log(data.data);
    });
}, 1000);

Logger UDP
// create an empty modbus client
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();

// open connection to a udp line
client.connectUDP("127.0.0.1", { port: 8502 });
client.setID(1);

// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
setInterval(function() {
    client.readHoldingRegisters(0, 10, function(err, data) {
        console.log(data.data);
    });
}, 1000);

ModbusTCP Server
// create an empty modbus client
var ModbusRTU = require("modbus-serial");
var vector = {
    getInputRegister: function(addr, unitID) {
        // Synchronous handling
        return addr;
    },
    getHoldingRegister: function(addr, unitID, callback) {
        // Asynchronous handling (with callback)
        setTimeout(function() {
            // callback = function(err, value)
            callback(null, addr + 8000);
        }, 10);
    },
    getCoil: function(addr, unitID) {
        // Asynchronous handling (with Promises, async/await supported)
        return new Promise(function(resolve) {
            setTimeout(function() {
                resolve((addr % 2) === 0);
            }, 10);
        });
    },
    setRegister: function(addr, value, unitID) {
        // Asynchronous handling supported also here
        console.log("set register", addr, value, unitID);
        return;
    },
    setCoil: function(addr, value, unitID) {
        // Asynchronous handling supported also here
        console.log("set coil", addr, value, unitID);
        return;
    },
    readDeviceIdentification: function(addr) {
        return {
            0x00: "MyVendorName",
            0x01: "MyProductCode",
            0x02: "MyMajorMinorRevision",
            0x05: "MyModelName",
            0x97: "MyExtendedObject1",
            0xAB: "MyExtendedObject2"
        };
    }
};

// set the server to answer for modbus requests
console.log("ModbusTCP listening on modbus://0.0.0.0:8502");
var serverTCP = new ModbusRTU.ServerTCP(vector, { host: "0.0.0.0", port: 8502, debug: true, unitID: 1 });

serverTCP.on("socketError", function(err){
    // Handle socket error if needed, can be ignored
    console.error(err);
});

to get more see Examples

Serial connection

node-modbus-serial use node-serialport for serial communication, for serial port options settings it passes to serial port the openOptions object, default serial port settings are 9600,8,n,1.

client.connectRTUBuffered("/dev/ttyUSB0", { baudRate: 9600, parity: 'even' });
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].