yaacov / node-modbus-serial

A pure JavaScript implemetation of MODBUS-RTU (and TCP) for NodeJS
ISC License
620 stars 238 forks source link

modbus - baudRate 115200 - does not work #561

Open robert-beecloud opened 1 month ago

robert-beecloud commented 1 month ago

Hi, node-modbus-serial works only when baudRate is 9600. When I change it to 19200 or 115200 - it does not work :(

It is very important for my project. Serial port is working with my NFC card reader on 115200 and I need to connect to my diagnostic tool over modbus with the speed higher then default: 9600.

My simple code below. I tested it also with serialPort object and without it

var {SerialPort} = require("serialport"); var serialPort = new SerialPort({ path: "/dev/ttymxc2", baudRate: 115200, autoOpen: false});

// create an empty modbus client var ModbusRTU = require("modbus-serial"); var client = new ModbusRTU(serialPort);

// open connection to a serial port //client.connectRTUBuffered('/dev/ttymxc2', { baudRate: 9600}, run);

client.open(run);

function run() { client.setID(1); if (client.isOpen) client.readInputRegisters(0, 10, function(err, data) { if (err) { console.log(err); } else { console.log(data.data); } }); } setInterval(run, 1000);

Thanks for any help!

yaacov commented 1 month ago

Hi, thank you for the issue, I added a help wanted flag so people that may help will know to look here

robert-beecloud commented 1 month ago

Hi, I have tested my configuration and I solved it! node-mobus-serial is not a problem - it works perfect ;) Problem was with USB-RS485 converter! Everybody should know that working with USB-RS485 converter for 5 USD is not a good idea. Thanks.