Standard modbus programs work but mine doesn't
CromaBAR opened this issue · 0 comments
Hello everyone,
We're trying to query holding registers from a device connected to a Windows PC through a serial port DB9 Halfduplex ( Dual wire RS-485 <--> Dual wire RS485).
The program that I used was working successfully in a Linux PC.
When we used the same program on Windows, it didn't work at first. Then, we tried other standard programs and they can poll holding registers successfully with different configurations.
- ModbusPoll (https://www.modbustools.com/modbus_poll.html)
- ModScan (http://www.win-tech.com/)
The configuration in both is almost the same except for one thing: In ModScan I do not activate DSR nor CTS. In ModbusPoll I have to activate 'RTS Toggle'.
I supposed that I had to toggle RTS manually everytime that I send a request for holding registers but I don't really know how to do it with this library (Or even if it's necessary)
This is the basic program for testing that we were using:
const ModbusRTU = require("modbus-serial")
const client = new ModbusRTU();
client.setID(1);
client.setTimeout(10000);
async function connectRTU(){
return await client.connectRTU("COM1", {
baudrate: 9600,
parity: 'None',
stopBits: 1,
dataBits: 8,
//rtscts: true,
//rtsMode: 'Toggle',
//flowControl: true,
//xon: true,
//xoff: true,
//xany: true,
//hupcl: true,
//lock: true
}, read)
}
async function read(){
console.log('Reading...')
await client.readHoldingRegisters(0, 10).then(function(d) {
console.log(d)
}).catch(function(e){
console.log(e.message)
});
}
var port = connectRTU();
The problem with this code is that always gives 'Timeout'.
We tried running on shell: set DEBUG=* && node myProgram.js
And the output was:
serialport/bindings-cpp loading WindowsBinding +0ms
serialport/stream opening path: COM1 +0ms
serialport/bindings-cpp open +0ms
serialport/stream opened path: COM1 +7ms
Reading...
serialport/stream _write 8 bytes of data +3ms
serialport/bindings-cpp write 8 bytes +7ms
serialport/stream _read reading { start: 0, toRead: 65536} +2ms
serialport/bindings-cpp read +3ms
serialport/stream binding.write write finished +2ms
Timed out
What more can we test? We tried a lot of combinations with the portOptions, but we almost always get the same results.