A simple-lightweight node based API for interfacing with Rockwell Control/CompactLogix PLCs.
latest version of NodeJS
Install with npm
npm install ethernet-ip --save
Detailed Documentation Coming Soon...
- Simple Demo
const { Controller, Tag, EthernetIP } = require("ethernet-ip");
const { SINT, INT, DINT, REAL, BOOL } = EthernetIP.CIP.DataTypes.Types;
// Intantiate Controller
const PLC = new Controller();
// Instantiate some Tag Instances
const tag1 = new Tag("TEST_TAG"); // Controller Scoped
const tag2 = new Tag("TEST", "Prog"); // Locally Scoped in Program "Prog"
const tag3 = new Tag("TEST_REAL", "Prog");
const tag4 = new Tag("TEST_BOOL", "Prog");
// build tag array
const group = [tag1, tag2, tag3, tag4];
// Connect to PLC at IP, SLOT
PLC.connect("10.1.60.205", 5).then(() => {
const { name } = PLC.properties;
// Log Connected to Console
console.log("\n\nConnected to PLC", `${name}`.green.bold, "...\n");
// Read Each Tag in group every 50ms
const interval = setInterval(async () => {
for (let tag of group) {
await PLC.readTag(tag);
}
}, 50);
});
// Subscribe to each tag's "Changed" Event
for (let tag of group) {
tag.on("Changed", (tag, lastValue) => {
console.log(`${tag.name} changed from ${lastValue} -> ${tag.value}`);
});
}
- NodeJS - The Engine
- javascript - ES2017 - The Language
- Canaan Seaton - Owner - GitHub Profile - Personal Website
This project is licensed under the MIT License - see the LICENCE file for details