3 Star 7 Fork 4

eagleclark / node-modbus

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

node-modbus

介绍

基于 modbus-serial 包开发的一款方便易用的 modbustcp 驱动,更适合自动化工程师的使用习惯。

安装教程

  1. 下载项目 https://gitee.com/eagleye/modbus.git
  2. cd modbus
  3. npm install(国内可以用cnpm install)

使用说明

  1. npm install -g typescript (如果没有TypeScript环境则需要安装)
  2. cd 到项目并使用 npm run build 进行编译
  3. test_tool 文件夹中有测试工具 modscan 与 modsim(需要自己模拟一些数据)
  4. 执行 npm run test 查看效果

例子

import ModbusTCPClient from './modbus_tcp';
import { EnumDataType } from './enum';
import { Register } from './interface';

/**
 * 寄存器
 */
let registerArr: Register[] = [
    // { register: "000100", dataType: EnumDataType.Bit },
    // { register: "400100", dataType: EnumDataType.SwappedDouble },
    // { register: "400100", dataType: EnumDataType.Binary },
    // { register: "400100", dataType: EnumDataType.Int },
    // { register: "400100", dataType: EnumDataType.Decimal },
    { register: '400100', dataType: EnumDataType.Float },
]
/**
 * 读取一次断开的例子
 */
async function example1() {
    let modbusTcpClient = new ModbusTCPClient({ host: '10.211.55.15', port: 502, deviceID: 1 })   
    let result = await modbusTcpClient.setRegisters(registerArr).readOnce();
    console.log(JSON.stringify(result.get('400100')));
}
// example1()

/**
 * 轮询的例子
 */
async function example2() {
    let modbusTcpClient = new ModbusTCPClient({ host: '10.211.55.15', port: 502, deviceID: 1 })
    let result = await modbusTcpClient.setRegisters(registerArr).polling();
    console.log(result);
}
// example2()

/**
 * 写数据的例子
 */
async function example3() {
    let modbusTcpClient = new ModbusTCPClient({ host: '10.211.55.15', port: 502, deviceID: 1 })
    let result = await modbusTcpClient.setRegisters(registerArr).writeData('400100', 12.54);
    console.log(result);
}
example3()
MIT License Copyright (c) 2020 eagleclark 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.

简介

基于modbus-serial开发的一款方便易用的modbus驱动 展开 收起
TypeScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/eagleye/modbus.git
git@gitee.com:eagleye/modbus.git
eagleye
modbus
node-modbus
master

搜索帮助