Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modbus server , address set error while using , and I fixed it #464

Closed
wei1224hf opened this issue May 16, 2024 · 2 comments
Closed

modbus server , address set error while using , and I fixed it #464

wei1224hf opened this issue May 16, 2024 · 2 comments
Assignees
Labels
bug community could be done by the community fixed handled by plus4nodered team https://p4nr.com/ pull request welcome send your pull request and contribute to the project Stale

Comments

@wei1224hf
Copy link

wei1224hf commented May 16, 2024

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
}

@biancode
Copy link
Contributor

Hi, can I ask you to test again with version 5.40+?

@biancode biancode added pull request welcome send your pull request and contribute to the project fixed community could be done by the community labels Jun 23, 2024
@biancode biancode added the handled by plus4nodered team https://p4nr.com/ label Jul 24, 2024
Copy link

This issue is stale because it has been open 60 days with no activity. It will be closed in 30 days, but can be saved by removing the stale label or commenting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug community could be done by the community fixed handled by plus4nodered team https://p4nr.com/ pull request welcome send your pull request and contribute to the project Stale
Projects
None yet
Development

No branches or pull requests

4 participants