Host Engineering Forum
General Category => General Discussion => Topic started by: PLCGuy on August 13, 2016, 06:23:00 PM
-
I am not fully understanding the RUN PROGRAM BLOCK.
For example I create a RUN called MOTOR.
In the box it says.".Ran This Scan" and another says,".Done"
Nice I only have to turn on the Box one scan then it turns on. The box that says, ".Ran This Scan" lights up showing it is executing. But the box that says, ".Done" never lights up.
I thought it was momentary so I tried to trap it using Motor.Done to a set bit. The bit never set. So what is the .Done for?
-
Never mind, I got it. I thought by completion it meant it ran all the rungs.
Apparently that is not true.
I put a HALT at the last rung in the last stage and then the .Run lite up once Halt was executed.
So it seems the block has to run then terminate.
I was trying to use a different structure in my stage programming by creating different programs to run devices.
Example, program for motor, program for compressor, etc.
Would like to see example of how others are using programs and stages together.
Normally I just put everything in Main and jump form one stage to the other turning on and off different events.
I would like to see how others are doing this.
-
You should use the EXIT instruction within the Program code block for normal termination (like in an ending stage of a sequence of stage). HALT is for aborting/halting the execution of a different program, say to terminate a different Program code block from $Main during an estop situation.
-
Programs are just like $MAIN. You start them and then they continue to run until you terminate them. They are just another style of self looping code block.
Tasks are one shots. You start it, it runs from the first rung to the last rung and terminates.
Neither one are like subroutines. Both operate like traditional ladder in most senses. The one way that they do not operate like normal ladder is that they have a concept called Yielding. Yielding allows you to do repetitive tasks such as FOR/NEXT, WHILE/WEND, etc and not have to worry about the watchdog timer. You set a yielding time and when that time is reached, the Program or Task will hop out and set a flag to know where it was in the code. The rest of the program will then execute and on the next scan it will pick up where it left off.
All of this is in the help file and explained a lot better than my few paragraphs.
-
Another consideration is lifespan ownership. A program block is started by the supervisor, but after that normally controls its own lifespan. This is most useful for lengthy asynchronous operations like comm operations, status report generation, sending emails, etc. Task blocks remain under the control of the supervisor, and could be long asynchronous operations like a big data sort, but are frequently modules to assist organization, i.e., all the logic associated with a single function.
-
Thanks for all the rrplies. So actually they csn kerp running doing their thing until I want them to stop. The done bit does not necessarily have to come on. When I saw the done bit it threw me off thinking once the program got to the last rung it was done. That was wrong of me. It can run Unless something in the program says stop running.