A simple an easy to use Modbus TCP client/server implementation.
Modbus is a simple Modbus TCP/RTU Client/Server with a simple API. It supports modbus function codes 1 - 6 and 15 and 16.
npm install jsmodbus and you are ready to go.
The test files are implemented using mocha and sinon.
npm install -g mocha and
npm install -g sinon. To run the tests type from the projects root folder
Please feel free to fork and add your own tests.
New in Version 3.0.0
We got rid of all the dependencies like stampit and serialport and make extensive use of es6 features like promisses. This way we, the developer do not have any restrictions on how to use this module. Unfortunatly this way the module probably won't work for nodejs versions lower than 6.0.
For modbus rtu we recommend the serialport npm module, for tcp the net.Socket interface is needed. When you need to keep a connection alive with some reconnect logic, use the node-net-reconnect module from our github page https://github.com/cloud-automation/node-net-reconnect.
If you want to see some debugging information, since Version 3 we use the debug module. You can filter the debug output by defining the DEBUG environment variable like so
TCP Client Example
// create a tcp modbus clientlet Modbus =let net =let socket =let client = socket unitIdlet options ='host' : host'port' : port
RTU Client Example
// create a tcp modbus clientlet Modbus =let SerialPort =let options =baudRate: 57600let socket = "/dev/tty-usbserial1" optionslet client = socket address
Client API Example
// for reconnecting see node-net-reconnect npm module// use socket.on('open', ...) when using serialportsocket;socket
Keeping TCP Connections alive
I've written a module to keep net.Socket connections alive by emitting TCP Keep-Alive messages. Have a look at the node-net-reconnect module.
let modbus =let net =let server =let server = serverserver
Long Running Test Results
We've got a munin server running some scripts. You can find detailed results on jsmodbus.cloud-automation.de.
Copyright (C) 2017 Stefan Poeter (Stefan.Poeter[at]cloud-automation.de)
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.