Closed wongjasont closed 6 years ago
Mhh, i am using v3.0.0 already in an application and i don't have any flaws with the holdingRegister requests so far. What server do you use?
@stefanpoeter These are my dependencies:
"dependencies": {
"commander": "^2.15.1",
"jsmodbus": "^3.0.0",
"net": "^1.0.2"
}
I am using this as my server code.
let net = require('net');
let modbus = require('jsmodbus');
let netServer = new net.Server()
let server = new modbus.server.TCP(netServer);
let socket = new net.Socket();
let opts = {
host: '127.0.0.1',
port : '5440'
};
netServer.listen(5440);
// OTHER LINES HERE (server.on event listeners)
socket.connect(opts);
I've based it solely from SimpleServer.js
example.
@stefanpoeter
I traced the buffer itself and found that the function call is weird:
client.readHoldingRegisters(0, 15)
- Will read 15 32bits registers starting at address 0
client.readHoldingRegisters(1, 15)
- Will read 15 32bits registers starting at address 1
Each address holds 16 bits. I've assumed this to be 32bits, this was the case in the simulator from https://github.com/riptideio/modbus-simulator
So in this buffer for example:
<Buffer 01 02 03 04 05 06 ... >
client.readHoldingRegisters(0, 1)
will result to 0x0102
client.readHoldingRegisters(1, 1)
will result to 0x0203
BUT mind that (111 = 0x6f, 222 = 0xde)
client.writeMultipleRegisters(0, [111])
client.writeMultipleRegisters(1, [222])
will result to the buffer getting:
<Buffer 00 6f 00 de ... >
Meaning the expected behavior of read is quite different from write. Write will apply in 32bits while the address meant in read is in 16-bit offsets.
Is this THE correct expected behavior? If yes how come the address in write is not same as read, if you get what I mean.
@wongjasont You probably mean this section in the code
let startByte = requestBody.start
let endByte = requestBody.start + (requestBody.count * 2)
and you are right, the startByte should be a multiple of two. I'll put this into the 3.0.1 patch.
I'll fixed this in branch v3.1.0-dev, thanks for your contribution.
I've created a runnable test below to demonstrate the issue:
The results of running this (Using jsmodbus v3.0.0):
Seems that coils are doing fine based on the test; but the registers are not.