Skip to content

readAllItems and writeItems stopped when is waiting #132

@gustavotremont

Description

@gustavotremont

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions