Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
modbus-tcp
Advanced tools
Readme
This is a very simple module that uses NodeJS Streams2 to read Modbus TCP data and convert it to JSON and vice-versa.
If you're just starting or just trying to use this library, I advise you to try modbus-stream. It's more complete (it supports all standard function codes) and it was designed to work with TCP, RTU and ASCII modes.
npm install modbus-tcp
var modbus = require("modbus-tcp");
var client = new modbus.Client();
var server = new modbus.Server();
// link client and server streams together
client.writer().pipe(server.reader());
server.writer().pipe(client.reader());
// if you have a socket (stream) you can just
// call client.pipe(socket) or server.pipe(socket)
server.on("read-coils", function (from, to, reply) {
return reply(null, [ 1, 0, 1, 1 ]);
});
// read coils from unit id = 0, from address 10 to 13
client.readCoils(0, 10, 13, function (err, coils) {
// coils = [ 1, 0, 1, 1 ]
});
All of the following read methods have the form method(unitId, from, to, next)
and write methods have the form method(unitId, addr, val, next)
, where next
is an optional function called if the server replies (with the same transactionId) to the sent message.
Addresses are exactly as is in protocol, so if you see a paper talking about address 40001
this usually means first record address of that function so it means address 0
.
This last event is triggered when an unknown function code is received.
FAQs
Modbus TCP/IP
The npm package modbus-tcp receives a total of 69 weekly downloads. As such, modbus-tcp popularity was classified as not popular.
We found that modbus-tcp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.