simple-modbus
A simple library for working with Modbus
The aim of this project is to make it extremely easy to work with Modbus with Node.js. It's written in Typescript, so you get easy to use strong typings. The error handling is consistent and easy, and it has a full test suite to ensure repeatable behavior.
Typedoc documentation
Currently Implemented
- Modbus TCP Server
- Modbus RTU Server
- Modbus ASCII Server
- Modbus RTU/IP Server
- Modbus TCP Client
- Modbus RTU Client
- Modbus ASCII Client
- Modbus RTU/IP Client
Function Codes
- 01 - Read Coil Status
- 02 - Read Input Status
- 03 - Read Holding Registers
- 04 - Read Input Registers
- 05 - Force Single Coil
- 06 - Preset Single Register
- 15 - Force Multiple Coils
- 16 - Preset Multiple Registers
Examples
Start a ModbusTCP server, and listen for all implemented Modbus commands.
Typescript:
server.listen502 server.onReadCoilStatus.on server.onReadInputStatus.on server.onReadHoldingRegisters.on server.onReadInputRegisters.on server.onPresetSingleRegister.on server.onPresetMultipleRegisters.on server.onForceSingleCoil.on server.onForceMultipleCoils.on server.onCommandError.on server.onServerError.on
Javascript:
const ModbusTcp = ModbusTcpconst ModbusCommandException = ModbusCommandException const server = ;server; serveronPresetSingleRegister
Options
A server can be initialized with options which will affect its behavior.
const server = new ModbusTcp.Server({ simpleAddressing: false })
- Modbus Addressing: By default, register and coil addresses will be 0 indexed, not using Modbus addresses. To change this, set
simpleAddressing
to false
Contributors
I need help! I've tested this with an Automation Direct Click PLC, but I need people to test with additional types of PLCs and submit issues. If you can include a Wireshark PCAP captue, that would be very helpful as well. All contributions are appreciated!
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!