KHarms
Oct 21, 2009, 06:17 PM
Did you know that HCA programs support both subroutines and co-routines?
Without getting too much into programmer jargon, a subroutine is one program (call it A) starting another program (call it B) and waiting until it (program B) finishes before continuing (with program A).
A co-routine is one program (call it A) starting another program (call it B) and not waiting for it (program B) to complete before it (program A) continues on. This allows program A and B to be executing sequentially.
In the Visual Programmer a sub-routine is started using the “StartProgram” element. The properties of the StartProgram element have you select the program to start and what trigger to start it with. That sounds a bit odd as the program is being started by the StartProgram element and not by some trigger. So why specify a trigger? Programs can test their starting trigger using the Test element so having the StartProgram element specify a trigger makes it possible for testing on the starting trigger.
Like most other programming “languages” the called program can in turn start another program using a StartProgram. This can happen to a depth of 4 programs before you get an error. So program A can start B, B can start C, C can start D, but D can’t start anything or you get an error.
A co-routine is started using the ON or OFF elements. Once the element executes the named program runs simultaneously with the program that contained the ON or OFF. Here is one slight “wrinkle” on this. The Visual Programmer will allow you to use the ON and OFF elements if the program to be started as a co-routine has an ON or OFF trigger. Sometimes you may find that you have to give the invoked program such a trigger just to keep the Visual Programmer happy. I often use some throw away trigger like P5 On and P5 Off.
Subroutines allow you to break up your programs into manageable units. Co-Routines allow you to get parallel execution. When to use which? Depends upon your need. Just remember that these facilities are more tools for you to work with.
Without getting too much into programmer jargon, a subroutine is one program (call it A) starting another program (call it B) and waiting until it (program B) finishes before continuing (with program A).
A co-routine is one program (call it A) starting another program (call it B) and not waiting for it (program B) to complete before it (program A) continues on. This allows program A and B to be executing sequentially.
In the Visual Programmer a sub-routine is started using the “StartProgram” element. The properties of the StartProgram element have you select the program to start and what trigger to start it with. That sounds a bit odd as the program is being started by the StartProgram element and not by some trigger. So why specify a trigger? Programs can test their starting trigger using the Test element so having the StartProgram element specify a trigger makes it possible for testing on the starting trigger.
Like most other programming “languages” the called program can in turn start another program using a StartProgram. This can happen to a depth of 4 programs before you get an error. So program A can start B, B can start C, C can start D, but D can’t start anything or you get an error.
A co-routine is started using the ON or OFF elements. Once the element executes the named program runs simultaneously with the program that contained the ON or OFF. Here is one slight “wrinkle” on this. The Visual Programmer will allow you to use the ON and OFF elements if the program to be started as a co-routine has an ON or OFF trigger. Sometimes you may find that you have to give the invoked program such a trigger just to keep the Visual Programmer happy. I often use some throw away trigger like P5 On and P5 Off.
Subroutines allow you to break up your programs into manageable units. Co-Routines allow you to get parallel execution. When to use which? Depends upon your need. Just remember that these facilities are more tools for you to work with.