modbus server , address set error while using , and I fixed it
Opened this issue · 1 comments
Which node-red-contrib-modbus version are you using?
/home/gene/nodejs/userDir1881
What happened?
using modbus server ,
inject data from input , with funcion content:
msg.payload = { 'value': 1, 'register': 'holding', 'address': 1, 'disableMsgOutput': 0 };
return msg;
after sending this to modbus-server node , the address 1 did not change , but the address 8 changed.
Server
Modbus-Server Node
How can this be reproduced?
deploy a modbus server node , send data :
msg.payload = { 'value': 1, 'register': 'holding', 'address': 1, 'disableMsgOutput': 0 };
What did you expect to happen?
using another software ModScan32.exe , monitoring data ,
the address 1 data of the modbus server from node-red should changed to 1,
but it did not , address 8 changed to 1 instead.
Other Information
I have already fixed this bug by
modbus-server-core.js , line 130:
de.biancoroyal.modbus.core.server.writeToModbusBuffer = function (node, msg) {
function setBit(buffer, i, bit, value){
if(value == 0){
buffer[i] &= ~(1 << bit);
}else{
buffer[i] |= (1 << bit);
}
}
switch (msg.payload.register) {
case 'holding':
node.modbusServer.holding.writeUInt16BE(msg.bufferPayload, msg.bufferAddress/4)
break
case 'coils':
const address = msg.bufferAddress/8;
const idx = Math.floor(address/8) ;
const idx2 = address%8;
setBit(node.modbusServer.coils,idx,idx2,msg.bufferPayload);
break
case 'input':
const address_ = msg.bufferAddress/8;
const idx_ = Math.floor(address_/8) ;
const idx2_ = address_%8;
setBit(node.modbusServer.input,idx_,idx2_,msg.bufferPayload);
break
case 'discrete':
node.modbusServer.discrete.writeUInt8(msg.bufferPayload, msg.bufferAddress/4)
break
default:
return false
}
return true
}
Hi, can I ask you to test again with version 5.40+?