Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readAllItems and writeItems stopped when is waiting #132

Open
gustavotremont opened this issue Oct 24, 2022 · 1 comment
Open

readAllItems and writeItems stopped when is waiting #132

gustavotremont opened this issue Oct 24, 2022 · 1 comment

Comments

@gustavotremont
Copy link

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
Copy link

lylatr commented Nov 26, 2023

Were you able to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants