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

Question about getting response from device #56

Open
p0tvin29 opened this issue Jan 16, 2020 · 0 comments
Open

Question about getting response from device #56

p0tvin29 opened this issue Jan 16, 2020 · 0 comments

Comments

@p0tvin29
Copy link

p0tvin29 commented Jan 16, 2020

I have a lock system hooked up to the tcp controller i'm using with node-modbus. I can successfully send the unlock to modbus but I'm trying to figure out a way to listen to the device. After unlocking, when the device LOCKS how do I listen on port 502 so that I can trigger an event?

My current code is:

modbus.tcp.connect(502, "10.100.55.17", { debug: "automaton-2454" }, (err, connection) => {
    //do something with connection
		connection.writeSingleCoil({ address: 0, value: 0 }, (err, info) => {
        console.log("response", info.response);
    });

		connection.writeSingleCoil({ address: 0, value: 1 }, (err, info) => {
        console.log("response", info.response);
    });

		connection.on("read-coils", (request, reply) => {
				console.log("**READ-COILS**")
				reply(null, [ 0, 0, 0, 0, 0, 0, 0, 0 ]);
		});

		connection.on("write-single-coil", (request, reply) => {
				console.log("**WRITE-SINGLE-COIL**")
				reply(null, 0, 1);
		});
});


modbus.tcp.server({ debug: "server" }, (connection) => {
    // do something with connection

		connection.on("read-coils", (request, reply) => {
				console.log("**READ-COILS**")
				//reply(null, [ 0, 0, 0, 0, 0, 0, 0, 0 ]);
		});

		connection.on("write-single-coil", (request, reply) => {
				console.log("**WRITE-SINGLE-COIL**")
				//reply(null, 0, 1);
		});

		connection.on("read-single-coil", (request, reply) => {
				console.log("**READ-SINGLE-COIL**")
				reply(null, 0, 1);
		});

		connection.readCoils({ address: 0, quantity: 16 }, (err, info) => {
        console.log("response", info.response);
    });

		connection.readCoils({ from: 0, to: 7 }, (err, info) => {
        console.log("PDU", info.pdu);
        console.log("response", info.response.data);
    });

}).listen(502, () => {
    // ready
		console.log("** GOT RESPONSE FROM DEVICE **")

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

No branches or pull requests

1 participant