node-modbus
Is not maintained anymore. This package was a mix of all existing Node.js Modbus packages sometime before.
Now we have a great state of very good Modbus packages like:
Feel free to contact me to get this package on NPM to provide your package under the name node-modbus!
just supported until Node 8 LTS
Install
Run the following command in the root directory of your Node-RED install
npm install node-modbus
Run the following command for global install
npm install -g node-modbus
Testing
The test files are implemented using mocha and sinon.
Simply use npm-update.sh
in the source code project.
To run the tests type from the projects root folder mocha test/*
.
Please feel free to fork and add your own tests.
Examples
Server TCP
let node_modbus = require('node-modbus')
let server = node_modbus.server.tcp.complete({ port : 502, responseDelay: 200 })
Client TCP
const node_modbus = require('node-modbus')
const client = node_modbus.client.tcp.complete({
'host': 'modbus.server.local',
'port': 502,
'unitId': 1,
'timeout': 2000,
'autoReconnect': true,
'reconnectTimeout': 15000,
'logLabel' : 'ModbusClientTCP',
'logLevel': 'debug',
'logEnabled': true
})
const time_interval = 1000
client.connect()
client.on('connect', function () {
setInterval( function () {
client.readCoils(0, 13).then((response) => console.log(response.payload))
}, time_interval)
})
Server Serial
TBD
Client Serial
const node_modbus = require('node-modbus')
const client = node_modbus.client.serial.complete({
'portName': '/dev/ttyS0',
'baudRate': 9600,
'dataBits': 8,
'stopBits': 1,
'parity': 'none',
'connectionType': 'RTU',
'connectionDelay': 250,
'timeout': 2000,
'autoReconnect': true,
'reconnectTimeout': 15000,
'logLabel' : 'ModbusClientSerial',
'logLevel': 'debug',
'logEnabled': true
})
const time_interval = 1000
client.on('connect', function () {
setInterval( function () {
client.readCoils(0, 13).then((response) => console.log(response.payload))
}, time_interval)
})
License
MIT
Based on jsmodbus