Cloud-Automation / node-modbus

Modbus TCP Client/Server implementation for Node.JS
465 stars 174 forks source link

Request for tutorial on using Modbus RTU server #240

Closed jaydenpung closed 4 years ago

jaydenpung commented 5 years ago

I'm having trouble using the Modbus RTU server without any documentation, is it possible to have a simple code example on how to use this? For example, I have no idea how to set the unit Id for the server, is this even correct?:

const modbus = require('jsmodbus')
const SerialPort = require('serialport')
const options = {
    baudRate: 9600
}
const socket = new SerialPort("/dev/ttyUSB0", options)
const server = new modbus.server.RTU(socket, 2)
server.on('data', function (data) {
    console.log(data);
});
stefanpoeter commented 4 years ago

Hey @jaydenpung sorry for the late reply, since this is an open source project, feel free to generate a tutorial for RTU. I bet many users would like to see this.