plcpeople / nodeS7

Node.JS library for communication to Siemens S7 PLCs
MIT License
356 stars 120 forks source link

readAllItems and writeItems stopped when is waiting #132

Open gustavotremont opened 1 year ago

gustavotremont commented 1 year ago

Hi! now i have a problem when i called the function readAllItems or writeItems, there is a part in the code that block

if (self.isWriting() || self.writeInQueue) {
      outputLog("You must wait until all previous writes have finished before scheduling another. ", 0, self.connectionID);
      return 1;  // Watch for this in your code - 1 means it hasn't actually entered into the queue.
}
//readAllItems
if (self.isWaiting()) {
      outputLog("Waiting to read for all R/W operations to complete.  Will re-trigger readAllItems in 100ms.", 0, self.connectionID);
      clearTimeout(self.rereadTimer);
      self.rereadTimer = setTimeout(function() {
          self.rereadTimer = undefined; //already fired, can safely discard
          self.readAllItems.apply(self, arguments);
      }, 100, arg);
      return;
}

in the logs, just show the outputlog of this two codes, and don't continue with the rest of the code, i know that because there are other logs that should show up but don't.

here my code:

exports.getPLCValues = function(s7) {
  logger.verbose('<INVOKE> controller:getPLCValues');
  /**
   * Returns the values readed from the plc or an error
   */
  return new Promise((resolve, reject) => {

    /**
     * Call the method of the nodes7 library to read the variables
     * indicated when the s7 connection started.
     */
    s7.readAllItems(function(anythingBad, values) {
      logger.debug('Reading values from PLC.');
      if (anythingBad) {
        logger.error(
          '<RETURN> controller:valuesReady Something went wrong reading values.'
        );
        const err = 'Something went wrong reading values.';
        reject(err);
      }

      logger.verbose('<RETURN> controller:getPLCValues');
      resolve(values);
    });
  });
};
exports.setPLCValues = function(variable, value, nodes7) {
  logger.verbose('<INVOKE> controller:setPLCValues Variable to write: ' +
    variable + ', value to set: ' + value);
  /**
   * Returns the values readed from the plc or an error
   */
  return new Promise((resolve, reject) => {

    /**
     * Call the method of the nodes7 library to read the variables
     * indicated when the s7 connection started.
     */
    nodes7.writeItems(variable, value, function(anythingBad) {
      logger.debug('Setting: ' + variable + ', to: ' + value);
      if (anythingBad) {
        logger.error(
          '<RETURN> controller:valuesReady Something went wrong writing values. ' + anythingBad
        );
        const err = 'Something went wrong writing values';
        reject(err);
      }

      logger.verbose('<RETURN> controller:setPLCValues');

      resolve('success');
    });
  });
};

I don't really know why this happen, and i hope anyone can help me. If you need more information please tell me. Thank!

lylatr commented 7 months ago

Were you able to fix this?