Skip to content

A Lightweight Ethernet/IP API written to interface with Rockwell ControlLogix/CompactLogix Controllers.

License

Notifications You must be signed in to change notification settings

NodeRich/node-ethernet-ip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm Gitter license GitHub stars

Node Ethernet/IP

A simple and lightweight node based API for interfacing with Rockwell Control/CompactLogix PLCs.

Prerequisites

latest version of NodeJS

Getting Started

Install with npm

npm install ethernet-ip --save

The API

Detailed Documentation Coming Soon...

Demos

  • Simple Demo

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);
    }
};

Built With

Contributers

License

This project is licensed under the MIT License - see the LICENCE file for details

About

A Lightweight Ethernet/IP API written to interface with Rockwell ControlLogix/CompactLogix Controllers.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%