I’m using a USB-to-RS485 adapter, and the connection seems to be fine. When I read or write, the communication module’s lights (RX and TX) work, but still, I read the registers, and I don’t get any different values. I always receive false in all the registers. I’m unsure about the parameters I pass as the address for reading registers. I’ve tried various parameters, both numbers like 0, 1, 3, and even in hexadecimal because the Omron documentation states the address is 0x5100, but the values never change.
// create an empty modbus client
const ModbusRTU = require("modbus-serial");
const client = new ModbusRTU();
// open connection to a serial port
client.connectRTUBuffered("/dev/ttyUSB0", { baudRate: 9600 });
client.setID(1);
// read the values of 10 registers starting at address 0
// on device number 1. and log the values to the console.
setInterval(function() {
client.readHoldingRegisters(0, 10, function(err, data) {
console.log(data.data);
});
}, 1000);
Danillo Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.