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:
- modbus-serial (works for TCP and Serial)
- jsmodbus (root of this package).
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 = let server = node_modbusservertcpcomplete port : 502 responseDelay: 200
Client TCP
const node_modbus = const client = node_modbusclienttcpcomplete 'host': 'modbus.server.local' /* IP or name of server host */ 'port': 502 /* well known Modbus port */ 'unitId': 1 'timeout': 2000 /* 2 sec */ 'autoReconnect': true /* reconnect on connection is lost */ 'reconnectTimeout': 15000 /* wait 15 sec if auto reconnect fails to often */ 'logLabel' : 'ModbusClientTCP' /* label to identify in log files */ 'logLevel': 'debug' /* for less log use: info, warn or error */ 'logEnabled': true const time_interval = 1000clientclient
Server Serial
TBD
Client Serial
const node_modbus = const client = node_modbusclientserialcomplete 'portName': '/dev/ttyS0' /* COM1 */ 'baudRate': 9600 /* */ 'dataBits': 8 /* 5, 6, 7 */ 'stopBits': 1 /* 1.5, 2 */ 'parity': 'none' /* even, odd, mark, space */ 'connectionType': 'RTU' /* RTU or ASCII */ 'connectionDelay': 250 /* 250 msec - sometimes you need more on windows */ 'timeout': 2000 /* 2 sec */ 'autoReconnect': true /* reconnect on connection is lost */ 'reconnectTimeout': 15000 /* wait 15 sec if auto reconnect fails to often */ 'logLabel' : 'ModbusClientSerial' /* label to identify in log files */ 'logLevel': 'debug' /* for less log use: info, warn or error */ 'logEnabled': true /* here we need none connect call */ const time_interval = 1000client
License
Based on jsmodbus