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
How the heck does this thing work anyway? Great question!
The Basics
Getting Connected
const Controller = ; const PLC = ; // Controller.connect(IP_ADDR[, SLOT])// NOTE: SLOT = 0 (default) - 0 if CompactLogixPLC;
Controller.properties Object
name: String // eg "1756-L83E/B" serial_number: Number slot: Number time: Date // last read controller WallClock datetime path: Buffer version: String // eg "30.11" status: Number faulted: Boolean // will be true if any of the below are true minorRecoverableFault: Boolean minorUnrecoverableFault: Boolean majorRecoverableFault: Boolean majorUnrecoverableFault: Boolean io_faulted: Boolean
Set the Clock of the Controller
NOTE Controller.prototype.readWallClock
and Controller.prototype.writeWallClock
are experimental features and may not be available on all controllers. 1756-L8 ControlLogix Controllers are currently the only PLCs supporting these features.
Sync Controller WallClock to PC Datetime
const Controller = ; const PLC = ; PLC;
Set Controller WallClock to a Specific Date
const Controller = ; const PLC = ; PLC;
Reading Tags
NOTE: Currently, the Tag
Class only supports Atomic datatypes (SINT, INT, DINT, REAL, BOOL). Not to worry, support for STRING, ARRAY, and UDTs are in the plans and coming soon! =]
Reading Tags Individually
...
const Controller Tag = ; const PLC = ; // Create Tag Instancesconst fooTag = "contTag"; // Controller Scope Tagconst barTag = "progTag" "prog"; // Program Scope Tag in PLC Program "prog" PLC;
Additional Tag Name Examples ...
const fooTag = "Program:prog.progTag"; // Alternative Syntax for Program Scope Tag in PLC Program "prog"const barTag = "arrayTag[0]"; // Array Elementconst bazTag = "arrayTag[0,1,2]"; // Multi Dim Array Elementconst quxTag = "integerTag.0"; // SINT, INT, or DINT Bitconst quuxTag = "udtTag.Member1"; // UDT Tag Atomic Memberconst quuzTag = "boolArray[0]" null BIT_STRING; // bool array tag MUST have the data type "BIT_STRING" passed in
Reading Tags as a Group
...
const Controller Tag TagGroup = ; const PLC = ;const group = ; // Add some tags to groupgroup; // Controller Scope Taggroup; // Program Scope Tag in PLC Program "prog" PLC;
Writing Tags
NOTE: You MUST read the tags first or manually provide a valid CIP datatype. The following examples are taking the latter approach.
Writing Tags Individually
...
const Controller Tag EthernetIP = ;const DINT BOOL = EthernetIPCIPDataTypesTypes; const PLC = ; // Create Tag Instancesconst fooTag = "contTag" null DINT; // Controller Scope Tagconst barTag = "progTag" "prog" BOOL; // Program Scope Tag in PLC Program "prog" PLC;
Writing Tags as a Group
...
const Controller Tag TagGroup EthernetIP = ;const DINT BOOL = EthernetIPCIPDataTypesTypes; const PLC = ;const group = ; // Create Tag Instancesconst fooTag = "contTag" null DINT; // Controller Scope Tagconst barTag = "progTag" "prog" BOOL; // Program Scope Tag in PLC Program "prog" group; // Controller Scope Taggroup; // Program Scope Tag in PLC Program "prog" PLC;
Lets Get Fancy
Subscribing to Controller Tags
const Controller Tag = ; const PLC = ; // Add some tags to groupPLC; // Controller Scope TagPLC; // Program Scope Tag in PLC Program "prog" PLC; // Catch the Tag "Changed" and "Initialized" EventsPLC;
Demos
- Monitor Tags for Changes Demo
const Controller Tag = ; // Intantiate Controllerconst PLC = ; // Subscribe to TagsPLC;PLC;PLC;PLC; // Connect to PLC at IP, SLOTPLC; // Initialize Event HandlersPLC
Built With
- NodeJS - The Engine
- javascript - ES2017 - The Language
Contributers
- Canaan Seaton - Owner - GitHub Profile - Personal Website
- Patrick McDonagh - Collaborator - GitHub Profile
- Jeremy Henson - Collaborator - Github Profile
Related Projects
Wanna become a contributor? Here's how!
License
This project is licensed under the MIT License - see the LICENCE file for details