Hi All,
I'm a new node-red user.
I'm currently working on a Win10 platform with NodeJS v14.18.1 version and Node-Red v2.1.1 version.
In the current project I'm working on, I'm using contrib-s7 module to communicate with a Siemens PLC.
One contrib-S7 node, the S7-In node, used to read variables from PLC, has only an output terminal and I need to inhibit the execution/deployment of this node until I complete some initialization operations.
Can anyone help me to solve this problem?
Thank you in advance.
Hi "TotallyInformation",
thaks for quick feedback.
I need to initialize some global vars and also to read some config files.
Only when these operations are completed, I can start to read PLC values...this is why I need to allow PLC read node execution only once the previous init flow has been correctly completed.
Any ideas?
In that case, the settings.js file is where you should do that. It has a section that lets you set global variables before Node-RED has started its flows. However, it does mean writing code to read the files rather than relying on flows.
The problem with trying to read files in Node-RED is that the process is asynchronous so it is highly likely that other parts of your flow will have started before the read completes even if you put the flow in the 1st tab.
Node-RED runs on Node.js so the setttings.js has access to the fs and other core Node.js modules. I think that Node-RED itself also makes use of fs-extra which is an excellent module that enhances some of the core file handling - so you should be able to simply require that in settings.js otherwise just add const fs = require('fs') towards the top of settings.js outside of the module.exports along with any file reading. Then pass along any required data in the functionGlobalContext property.
When reading files, obviously, you want to probably use the "sync" versions of file reads so that the process doesn't just carry on regardless before your reads have finished.
Thanks "TotallyInformation, for your suggestions, but they are quite far away from my knowledges...I'm not sure I can understand and implement as you said what I need...being a node-red user new
Hi Ghayne,
what do you mean? Can you clarify a little bit better?
In my project, at initialization phase, the S7-In node is use to read some plc tags to initialize some global vars.
Then a different S7-In node (configured in the same way as the one used for inti phase) has to be "executed" cyclically every 10s to acquire PLC tags.