A simple and 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 } = require("ethernet-ip");
// 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}...\n`);
// Begin Reading Tags
readGroup(group, 50);
});
// Subscribe to each tag's "Changed" Event to Log Values to Console
for (let tag of group) {
tag.on("Changed", (tag, lastValue) => {
console.log(`${tag.name} changed from ${lastValue} -> ${tag.value}`);
});
}
///////////////////// FUNCTION DEFINITIONS ////////////////////////////////////////
// Function to Delay X ms
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
// Function to continuously Read Tag Group Every X ms
const readGroup = async (group, ms) => {
while(true) {
// Read Each Tag in Group
for (let tag of group) {
await PLC.readTag(tag);
}
// Wait X ms until Processing Continues
await delay(ms);
}
};
- 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