How to implement a task scheduler?

#1

Hi,

To resume, I am working with a S7 PLC and I am aiming to retrieve periodic data and alarms from the S7, so I declared two S7 connectors :

-one for periodic reading
-one for alarm reading

Annotation%202019-04-17%20084958

I also add a status node to monitor the state of S7 connectors, javascript function are juste here to add an information to the

msg.payload as msg.payload.nodeid = 'whatever'

Each nodes status, Alarm and Periodic will execute a respective python script (status.py for Status, alarm.py for Alarm, periodic.py for Periodic), but those scripts can't run at the same time.

A scenario example that can't happen :

Periodic sends data and status sends data at same time

So in order to implement a kind of Scheduler, I tried to use the switch node to test the equality of msg.payload.nodeid so that if the msg.payload.nodeid is equal to the alarm id then it must delay the execution of the status script and periodic script (and if the msg.payload.nodeid is equal to periodic id, delay the two others and so on).

The problem is that using the switch node, I am able to distinguish msg.payload.nodeid but can't schedule tasks.

Do you have any idea?

Kind regards

0 Likes

#2

I am a bit lost on the "scheduler" part. What is the use for the switch node ?

Fill in the blanks:
periodic --> ? --> ?

0 Likes

#3

periodic -> scheduler -> exec script

The scheduler part is not clear for me at all, that's why I used the switch node because I thought I can use it to schedule script execution.

An example scenario :

Periodic node sends msg, then if the nodeid is equal to a certain value (00 for the periodic) then we can exec the script in condition not another script is running (alarm or status)

0 Likes

#4

What about the periodic/alarm nodes, what output do these produce ?
(eg periodic -> debug node with full msg)

0 Likes

#5

They produce this type of output (here is the periodic's output)

Annotation%202019-04-17%20093507

Then I convert the json object to string and my pass it as an argument to python script.

Here is my complete flow which works but only if periodic, alarm and status don't send at same time.

0 Likes

#6

The periodic and alarm both produce the same output ? There is no information to distinguish the 2 ?

0 Likes

#7

No doesn't send same output.

Alarm output is :

Annotation%202019-04-17%20101058

0 Likes

#8

Visual

Function node:

t = msg.payload.nodeid

periodic = null //default
alarm = null //default

if(t=="00"){
   periodic = {payload:"do periodic task"}
}
if(t=="01"){
   alarm = {payload:"do alarm task"}
}

return [periodic,alarm]

Note that you have to add another output to the function node.
First will be periodic second alarm

*edit this is ofcourse also possible with a switch node.

0 Likes

#9

Ok thanks I'll try to do it with the switch node but I got it.

Best

0 Likes