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

Changing PLC Scan Rate has no effect #7

Closed MattCost closed 6 years ago

MattCost commented 6 years ago

Changing PLC Scan rate has no effect. Tags are scanned as fast as possible

Current Behavior

Tags are scanned as fast as possible

Expected Behavior

Tags should be scanned every X ms

Possible Solution (Optional)

ethernet-ip\src\controller\index.js line 433 - should be "await delay(this.state.scan_rate);"

Your Environment

cmseaton42 commented 6 years ago

Hmmm, the master branch shows line 433 as what you are recommending already. Can you add your code so I can get a look at what you are doing?

MattCost commented 6 years ago

https://github.com/cmseaton42/node-ethernet-ip/blob/master/src/controller/index.js That version doesn't have the await

const { Controller, Tag } = require("ethernet-ip");

const PLC = new Controller();

// Add some tags to group
PLC.subscribe(new Tag("TestRead")); // Controller Scope Tag

PLC.connect("10.115.45.52", 0).then(() => {
    console.log("Connected to PLC!");
    console.log(PLC.properties);

    PLC.scan_rate = 1500;

    // Begin Scanning
    PLC.scan();
});

// Catch the Tag "Changed" and "Initialized" Events
PLC.forEach(tag => {
    // Called on the First Successful Read from the Controller
    tag.on("Initialized", tag => {
        console.log("Initialized", tag.value);
    });

    // Called if Tag.controller_value changes
    tag.on("Changed", (tag, oldValue) => {
        console.log("Changed:", tag.value);
    });
});
cmseaton42 commented 6 years ago

Ahhhh, good catch. Patching now.

cmseaton42 commented 6 years ago

@MattCost v1.1.2 should resolve the issue. Let me know if everything seems to be working when you upgrade.

MattCost commented 6 years ago

Yup! Working as expected now.

cmseaton42 commented 6 years ago

Sweet, Thanks for the heads up!