node-modbus-serial-master
所属分类:串口编程
开发工具:JavaScript
文件大小:48KB
下载次数:9
上传日期:2017-07-28 08:38:40
上 传 者:
ashang126
说明: 用node.js实现串口通讯。node.js将javascript的使用焕发了新的生命,同时将其直接操控串口,更是直接可用于工业控制。
(Implementation of serial communication with node.js. Node.js brings new life to the use of JavaScript, and directly controls the serial port, which is directly used for industrial control. Implementation of serial communication with node.js.)
文件列表:
.eslintrc.json (8591, 2017-04-27)
.travis.yml (38, 2017-04-27)
LICENSE (759, 2017-04-27)
apis (0, 2017-04-27)
apis\connection.js (6856, 2017-04-27)
apis\promise.js (2770, 2017-04-27)
examples (0, 2017-04-27)
examples\buffer.js (1105, 2017-04-27)
examples\buffertcp.js (983, 2017-04-27)
examples\debug.js (1223, 2017-04-27)
examples\logger.js (1840, 2017-04-27)
examples\server.js (769, 2017-04-27)
examples\simple.js (1524, 2017-04-27)
examples\write.js (1291, 2017-04-27)
gulpfile.js (1376, 2017-04-27)
index.d.ts (3819, 2017-04-27)
index.js (20109, 2017-04-27)
npm-update.sh (47, 2017-04-27)
npm-upgrade.sh (67, 2017-04-27)
package.json (1000, 2017-04-27)
ports (0, 2017-04-27)
ports\asciiport.js (7258, 2017-04-27)
ports\c701port.js (5405, 2017-04-27)
ports\rtubufferedport.js (4848, 2017-04-27)
ports\tcpport.js (3892, 2017-04-27)
ports\tcprtubufferedport.js (6642, 2017-04-27)
ports\telnetport.js (5272, 2017-04-27)
ports\testport.js (7398, 2017-04-27)
servers (0, 2017-04-27)
servers\servertcp.js (8675, 2017-04-27)
test (0, 2017-04-27)
test\Lint (0, 2017-04-27)
test\Lint\test.js (403, 2017-04-27)
test\apis (0, 2017-04-27)
test\apis\promise.js (2103, 2017-04-27)
test\mocks (0, 2017-04-27)
test\mocks\SerialPortMock.js (1028, 2017-04-27)
... ...
# modbus-serial
A pure JavaScript implemetation of MODBUS-RTU (Serial and TCP) for NodeJS.
[![NPM download](https://img.shields.io/npm/dm/modbus-serial.svg)](http://www.npm-stats.com/~packages/modbus-serial)
[![NPM version](https://badge.fury.io/js/modbus-serial.png)](http://badge.fury.io/js/modbus-serial)
[![Build Status](https://travis-ci.org/yaacov/node-modbus-serial.svg?branch=master)](https://travis-ci.org/yaacov/node-modbus-serial)
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.**
----
- [What can I do with this module ?](#what-can-i-do-with-this-module-)
- [Compatibility](#compatibility)
- [Examples](#examples)
- [Methods](https://github.com/yaacov/node-modbus-serial/wiki/Methods)
----
#### 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:
* https://github.com/yaacov/arduino-modbus-slave
* https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino
Arduino sketch for irrigation timer with modbus support:
* https://github.com/yaacov/arduino-irrigation-timer
Node Modbus-WebSocket bridge:
* https://github.com/yaacov/node-modbus-ws
#### Compatibility
###### This classes are implemented:
* FC1 "Read Coil Status"
* FC2 "Read Input Status"
* FC3 "Read Holding Registers"
* FC4 "Read Input Registers"
* FC5 "Force Single Coil"
* FC6 "Preset Single Register"
* FC15 "Force Multiple Coil"
* FC16 "Preset Multiple Registers"
###### 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
``` javascript
// create an empty modbus client
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();
// open connection to a serial port
client.connectRTU("/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);
}
```
----
###### Logger Serial
``` javascript
// 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
``` javascript
// 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);
```
----
###### ModbusTCP Server
``` javascript
// create an empty modbus client
var ModbusRTU = require("modbus-serial");
var vector = {
getInputRegister: function(addr, unitID) { return addr; },
getHoldingRegister: function(addr, unitID) { return addr + 8000; },
getCoil: function(addr, unitID) { return (addr % 2) === 0; },
setRegister: function(addr, value, unitID) { console.log("set register", addr, value, unitID); return; },
setCoil: function(addr, value, unitID) { console.log("set coil", addr, value, unitID); return; }
};
// 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 });
```
to get more see [Examples](https://github.com/yaacov/node-modbus-serial/wiki)
近期下载者:
相关文件:
收藏者: