All Projects → node-modbus → Stream

node-modbus / Stream

Licence: mit
NodeJS Modbus Stream

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Stream

Qtswissarmyknife
QSAK (Qt Swiss Army Knife) is a multi-functional, cross-platform debugging tool based on Qt.
Stars: ✭ 196 (+71.93%)
Mutual labels:  serial, tcp, udp, modbus
Ohsce
PHP HI-REL SOCKET TCP/UDP/ICMP/Serial .高可靠性PHP通信&控制框架SOCKET-TCP/UDP/ICMP/硬件Serial-RS232/RS422/RS485 AND MORE!
Stars: ✭ 206 (+80.7%)
Mutual labels:  serial, tcp, udp, modbus
Esp8266 Wifi Uart Bridge
Transparent WiFi (TCP, UDP) to UART Bridge, in AP or STATION mode
Stars: ✭ 107 (-6.14%)
Mutual labels:  serial, tcp, udp
node-drivers
Industrial protocol drivers in node.js
Stars: ✭ 20 (-82.46%)
Mutual labels:  tcp, udp, modbus
Scriptcommunicator serial Terminal
Scriptable cross-platform data terminal which supports: serial port, UDP, TCP, SPI, I2C and CAN.
Stars: ✭ 462 (+305.26%)
Mutual labels:  serial, tcp, udp
Pingtunnel
ping tunnel is a tool that advertises tcp/udp/socks5 traffic as icmp traffic for forwarding.
Stars: ✭ 1,904 (+1570.18%)
Mutual labels:  tcp, udp
Mr2
Mr.2 can help you expose local server to external network. Support both TCP/UDP, of course support HTTP. Zero-Configuration.
Stars: ✭ 1,102 (+866.67%)
Mutual labels:  tcp, udp
Pytcp
PyTCP is an attempt to create fully functional TCP/IP stack in Python. It supports TCP stream based transport with reliable packet delivery based on sliding window mechanism and basic congestion control. It also supports IPv6/ICMPv6 protocols with SLAAC address configuration. It operates as user space program attached to Linux TAP interface. As of today stack is able to send and receive traffic over Internet using IPv4 and IPv6 default gateways for routing. Since goal of this project is purely educational (at least at this point) the clarity of code is preferred over its efficiency. For the same reason security features are not being implemented just yet unless they are integral part of TCP/IP suite protocols specification.
Stars: ✭ 65 (-42.98%)
Mutual labels:  tcp, udp
Objectdeliverer
ObjectDeliverer is a data transmission / reception library for Unreal Engine (C ++, Blueprint).
Stars: ✭ 78 (-31.58%)
Mutual labels:  tcp, udp
Godsharp.socket
An easy-to-use .NET socket server and client.
Stars: ✭ 35 (-69.3%)
Mutual labels:  tcp, udp
Netassistant
A UDP/TCP Assistant. 网络调试助手
Stars: ✭ 66 (-42.11%)
Mutual labels:  tcp, udp
Modbuspp
A C++ Library for Modbus TCP Protocol
Stars: ✭ 108 (-5.26%)
Mutual labels:  tcp, modbus
Reactor Netty
TCP/HTTP/UDP/QUIC client/server with Reactor over Netty
Stars: ✭ 1,743 (+1428.95%)
Mutual labels:  tcp, udp
Media Tutorial
流处理,TCP和UDP,WebRTC和Blob
Stars: ✭ 47 (-58.77%)
Mutual labels:  tcp, udp
Ruby Escper
Escper is a collection of essential tools that make printing of plain text and images to one or many serial thermal printers easy. Both USB and serial (RS232) printers are supported and detected automatically. Escper is useful for Ruby based Point of Sale systems that want to print receipts or tickets.
Stars: ✭ 64 (-43.86%)
Mutual labels:  serial, tcp
Objecttransport
Send and Receive objects over TCP or UDP
Stars: ✭ 39 (-65.79%)
Mutual labels:  tcp, udp
Logbert
Logbert is an advanced log message viewer for log4net, log4j and others.
Stars: ✭ 70 (-38.6%)
Mutual labels:  tcp, udp
Ddos Rootsec
DDOS Archive by RootSec (Scanners, BotNets (Mirai and QBot Premium & Normal and more), Exploits, Methods, Sniffers)
Stars: ✭ 108 (-5.26%)
Mutual labels:  tcp, udp
N2o
⭕ N2O: Distributed Application Server
Stars: ✭ 1,262 (+1007.02%)
Mutual labels:  tcp, udp
T Io
解决其它网络框架没有解决的用户痛点,让天下没有难开发的网络程序
Stars: ✭ 1,331 (+1067.54%)
Mutual labels:  tcp, udp

Modbus Stream

Build Status Package Version

This is a NodeJS module to help you process modbus data. It uses pdu to build the core PDU and then uses transports to extend the rest.

Features

  • [x] Support almost every standard function code
  • [x] Support standard exceptions
  • [x] Support transports
    • [x] TCP
    • [x] RTU
    • [x] ASCII
  • [x] Support drivers
    • [x] TCP
    • [x] UDP
    • [x] Serial (RS232, RS485)

Example

This is my current test.js file. It creates a client and a server network socket and the server requests coils as soon as the client connects.

var modbus = require("modbus-stream");

modbus.tcp.server({ debug: "server" }, (connection) => {
    connection.readCoils({ address: 5, quantity: 8 }, (err, info) => {
        console.log("response", info.response.data);
    });
}).listen(12345, () => {
    modbus.tcp.connect(12345, { debug: "client" }, (err, connection) => {
        connection.on("read-coils", (request, reply) => {
            reply(null, [ 1, 0, 1, 0, 1, 1, 0, 1 ]);
        });
    });
});

Usage

Connection

To connect to a modbus device over TCP, use:

var modbus = require("modbus-stream");

modbus.tcp.connect(502, "134.2.56.231", { debug: "automaton-2454" }, (err, connection) => {
    // do something with connection
});

To listen for connections over TCP, use:

var modbus = require("modbus-stream");

modbus.tcp.server({ debug: "server" }, (connection) => {
    // do something with connection
}).listen(502, () => {
    // ready
});

To connecto to a modbus device over a serial port, use:

var modbus = require("modbus-stream");

modbus.serial.connect("/dev/ttyS123", { debug: "automaton-123" }, (err, connection) => {
    // do something with connection
});

Requests

After having a connection, you can send requests and listen for responses.

modbus.serial.connect("/dev/ttyS123", { debug: "automaton-123" }, (err, connection) => {
    if (err) throw err;

    connection.readCoils({ address: 52, quantity: 8, extra: { unitId: 25 } }, (err, res) => {
        if (err) throw err;

        console.log(res); // response
    })
});

Every method accepts an object options which have defaults parameters (like address = 0) and a callback, in case you want to see the response from the remote device. Here is a list of supported function codes and the corresponding methods:

Base Reads

  • readCoils (address = 0, quantity = 1)
  • readDiscreteInputs (address = 0, quantity = 1)
  • readHoldingRegisters (address = 0, quantity = 1)
  • readInputRegisters (address = 0, quantity = 1)

Base Writes

  • writeSingleCoil (address = 0, value = 0)
  • writeSingleRegister (address = 0, value = <Buffer 0x00 0x00>)
  • writeMultipleCoils (address = 0, values = [])
  • writeMultipleRegisters (address = 0, values = [ <Buffer 0x00 0x00> ])

File Records

  • readFileRecord (requests = [])
  • writeFileRecord (requests = [])

FIFO

  • readFifoQueue (address = 0)

Advanced

  • maskWriteRegister (address = 0, andmask = 0xFFFF, ormask = 0x0000)
  • readWriteMultipleRegisters (read_address = 0, read_quantity = 1, write_address = 0, values = [ <Buffer 0x00 0x00> ])
  • readDeviceIdentification (type = "BasicDeviceIdentification", id = "ProductName")
  • readExceptionStatus ()
  • getCommEventCounter ()
  • getCommEventLog ()

For more information on these methods, look at the pdu repository which is used to build the packets.

Responses

To respond to remote requests, listen for events.

modbus.serial.connect("/dev/ttyS123", {
    // except "debug", everything else is the default for serial
    baudRate : 9600,
    dataBits : 8,
    stopBits : 1,
    parity   : "none",
    debug    : "automaton-123"
}, (err, connection) => {
    if (err) throw err;

    connection.events.on("read-coils", (req, reply) => {
        console.log(req); // request

        // ...
        return reply(null, [ data ]);
    })
});

Events

There are events propagated from the transports up to the stream. You should bind some event listener just in case the connection or serial device errors or just closes. Remember that in NodeJS, an emitted error event without a listener will cause the process to throw an uncaughtException.

Transport Closed (close)

This event is emitted when the serialport module emits a close event or when a socket emits an end event.

Transport Error (error)

This event if something happens to the underlying stream, like a ECONNRESET or something similar.

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].