1 Star 0 Fork 0

fjfhdntkm/modbus-tcp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
hanyu- hanyu sadf fde595c 4年前
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Modbus TCP/IP Stream

Build Status

This is a very simple module that uses NodeJS Streams2 to read Modbus TCP data and convert it to JSON and vice-versa.

Upgrade

If you're just starting or just trying to use this library, I advise you to try modbus-stream. It's more complete (it supports all standard function codes) and it was designed to work with TCP, RTU and ASCII modes.

Install

npm install modbus-tcp

Example

var modbus = require("modbus-tcp");
var client = new modbus.Client();
var server = new modbus.Server();

// link client and server streams together
client.writer().pipe(server.reader());
server.writer().pipe(client.reader());
// if you have a socket (stream) you can just
// call client.pipe(socket) or server.pipe(socket)

server.on("read-coils", function (from, to, reply) {
    return reply(null, [ 1, 0, 1, 1 ]);
});

// read coils from unit id = 0, from address 10 to 13
client.readCoils(0, 10, 13, function (err, coils) {
    // coils = [ 1, 0, 1, 1 ]
});

Client Methods

All of the following read methods have the form method(unitId, from, to, next) and write methods have the form method(unitId, addr, val, next), where next is an optional function called if the server replies (with the same transactionId) to the sent message.

  • readCoils
  • readDiscreteInputs
  • readHoldingRegisters
  • readInputRegisters
  • writeSingleCoil
  • writeSingleRegister
  • writeMultipleCoils
  • writeMultipleRegisters

Addresses are exactly as is in protocol, so if you see a paper talking about address 40001 this usually means first record address of that function so it means address 0.

Server Events

  • read-coils
  • read-discrete-inputs
  • read-holding-registers
  • read-input-registers
  • write-single-coil
  • write-single-register
  • write-multiple-coils
  • write-multiple-registers
  • data

This last event is triggered when an unknown function code is received.

Copyright 2016 Diogo Resende Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/linux-composer/modbus-tcp.git
git@gitee.com:linux-composer/modbus-tcp.git
linux-composer
modbus-tcp
modbus-tcp
master

搜索帮助