I have googled and searched alot for my issues but did not get any threat of use. I have the same issue as https://github.com/yaacov/node-modbus-serial/issues/115 but i am using a Windows 10 OS. I tried the suggested solutions but still same issue. I think it should be simple but been stuck for days now
var path = "COM3";
var ModbusRTU = require("modbus-serial");
var client = new ModbusRTU();
client.connectRTUBuffered(path, { baudRate: 9600, stopbits: 1, databits: 8, parity: 'none' }, false, read());
client.setID(1);
function read() {
// read the 20 registers starting at address 0
// on device number 1.
var data = client.readHoldingRegisters(0, 20)
console.log(data)
}
With this code i get no port permission/ permission denied error. PORT INFORMATION via Device manager port properties
- BITS PER SECOND: 9600
- DATA BITS: 8
- PARITY: NONE
- STOP BITS: 1
- FLOW CONTROL: NONE
OUTPUT 1: (node:10784) UnhandledPromiseRejectionWarning: Error: Opening COM3: Access denied
Tried to open the port manually
var x = setInterval(function () {
if (client.isOpen) {
client.setID(1);
//console.log("WORKING WORKING");
try {
client.readHoldingRegisters(0, 10, function (err, data) {
console.log(data);
});
} catch (err) {
console.log("Error Encountered: " + err)
}
} else {
console.log("ERROR ERROR ERROR");
}
}, 1000);