A simple and reliable Modbus RTU library for Node.js using SerialPort and Raspberry Pi GPIO with MAX485 RS485 transceivers.
npm install max485-raspberry-nodejs
const ModbusRTU = require("max485-raspberry-nodejs");
const client = new ModbusRTU({ path: "/dev/ttyAMA0", baudRate: 9600, re_pin: 27, de_pin: 17 });
(async () => {
await new Promise(resolve => setTimeout(resolve, 2000));
await client.write(1, 1, 1);
const value = await client.read(1, 1);
console.log(`Register value: ${value}`);
})();
• Supports Modbus RTU communication over RS485
• Handles TX/RX switching for MAX485 chips
• Implements retry logic to handle timeouts and bad responses
• CRC validation for error detection
• Optimized for Raspberry Pi GPIO control
MIT