plcpeople / nodepccc

Library for node.js to communicate with some Allen-Bradley programmable controllers (PLCs)
MIT License
81 stars 24 forks source link

When polling at 100ms, eventually start getting 'Waiting to read for all R/W operations to complete. Will re-trigger readAllItems in 100ms.' #2

Closed dlbrown06 closed 9 years ago

dlbrown06 commented 9 years ago

Do you guys have plans of implementing this with callbacks so that the application running the module can make sure not to call again until the previous has returned?

Using the async module and altering the example a bit with:

conn.addItems('TEST9');

    async.forever(
        function(next) {
            //conn.readAllItems(valuesReady);

            conn.readAllItems(function (err, values) {
                if (err) { console.log("SOMETHING WENT WRONG READING VALUES!!!!"); }
                console.log(values);
                doneReading = true;
                if (doneWriting) { process.exit(); }
            });

            setTimeout(function () {
                next();
            }, 100);
        },
        function(err) {
            console.log('ERROR: ' + err);
        }
    );

After a few seconds of running I continue to get this:

{ TEST9: 4 }
[17439,716142848] Waiting to read for all R/W operations to complete.  Will re-trigger readAllItems in 100ms.
[17439,716207848] Waiting to read for all R/W operations to complete.  Will re-trigger readAllItems in 100ms.
[17439,716244339] Waiting to read for all R/W operations to complete.  Will re-trigger readAllItems in 100ms.
[17439,716670828] Waiting to read for all R/W operations to complete.  Will re-trigger readAllItems in 100ms.
{ TEST9: 16 }
[17439,817173683] Waiting to read for all R/W operations to complete.  Will re-trigger readAllItems in 100ms.
[17439,817237162] Waiting to read for all R/W operations to complete.  Will re-trigger readAllItems in 100ms.
[17439,817270232] Waiting to read for all R/W operations to complete.  Will re-trigger readAllItems in 100ms.
[17439,817303682] Waiting to read for all R/W operations to complete.  Will re-trigger readAllItems in 100ms.
{ TEST9: 2 }
plcpeople commented 9 years ago

We've always found it best to call "next" from within the callback, just a few lines up, rather than from a setTimeout, or even if you call the timeout from within the callback if you want to avoid continuous polling, it should avoid the message you're seeing.

dlbrown06 commented 9 years ago

Wow... must be getting late in the day. Thanks for pointing that out.

Module looks great by the way.