cmseaton42 / node-ethernet-ip

A Lightweight Ethernet/IP API written to interface with Rockwell ControlLogix/CompactLogix Controllers.
MIT License
265 stars 106 forks source link

Add worker to better handle concurrent requests #2

Closed cmseaton42 closed 6 years ago

cmseaton42 commented 6 years ago

Expected Behavior

Calling readTagGroup/writeTagGroup while scanning or calling multiple readTag/writeTag methods in a row without the use of ASYNC/AWAIT will be handled appropriately without the chance of tags being assigned the wrong values by mistake.

Current Behavior

Currently, If a user were to do something like the following...

const group = new TagGroup();
group.add(new Tag("dint1"));
group.add(new Tag("dint2"));

const PLC = new Controller();
PLC.subscribe(new Tag("dint3"));

PLC.connect("192.168.1.1").then(() => {
    PLC.scan();
    PLC.readTagGroup(group);
});

or...

const tag1 = new Tag("dint1");
const tag2 = new Tag("dint2");

PLC.connect("192.168.1.1").then(() => {
    PLC.readTag(tag1);
    PLC.readTag(tag2);
});

then there is a chance that the Controller class can step on other outgoing network requests due to the async nature of js as well as the non-descriptive structure of the CIP Read Tag Service network responses. This could cause the tags to be assigned wrong values.

Possible Solution

Offload Read/Write responsibilities to a worker to synchronously run the requested tasks. This could be implemented as a priority queue (giving call priority to requests originating to the scan group).

Environment

cmseaton42 commented 6 years ago

Feature added in 1.1.0 release