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

Correct Parameters to reply to writeMultipleRegisters #34

Closed
EricPublic12 opened this issue Feb 4, 2019 · 3 comments
Closed

Correct Parameters to reply to writeMultipleRegisters #34

EricPublic12 opened this issue Feb 4, 2019 · 3 comments
Assignees
Labels

Comments

@EricPublic12
Copy link

I am trying to create a server and I need to send the reply after the client calls writeMultipleRegisters.
What are the correct parameters to send back and is there a helper function that will create the response?

@dresende
Copy link
Member

dresende commented Feb 5, 2019

You just need to reply the address of the first register and the number of registers written.

const modbus = require("modbus-stream");

modbus.tcp.server({ debug: null }, (connection) => {
	let one_hundred  = Buffer.alloc(2);
	let one_thousand = Buffer.alloc(2);
	let ten_thousand = Buffer.alloc(2);

	one_hundred.writeUInt16BE(100, 0);
	one_thousand.writeUInt16BE(1000, 0);
	ten_thousand.writeUInt16BE(10000, 0);

	connection.writeMultipleRegisters({ address: 123, values: [ one_hundred, one_thousand, ten_thousand ] }, (err, info) => {
		console.log("response", info.response);
	});
}).listen(12345, () => {
	modbus.tcp.connect(12345, { debug: null }, (err, connection) => {
		connection.on("write-multiple-registers", (info, reply) => {
			console.log("request", info.request);

			console.log("one hundred", info.request.values[0].readUInt16BE(0));
			console.log("one thousand", info.request.values[1].readUInt16BE(0));
			console.log("ten thousand", info.request.values[2].readUInt16BE(0));

			return reply(null, info.request.address, info.request.quantity);
		});
	});
});

@dresende dresende closed this as completed Feb 5, 2019
@dresende dresende self-assigned this Feb 5, 2019
@EricPublic12
Copy link
Author

Are the same reply parameters used for writesingleRegister?

@dresende
Copy link
Member

dresende commented Feb 6, 2019

The responses are always based on standard. For writeSingleRegister you should return the address and the value written (instead of the quantity). Basically you just reply the same thing you receive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants