Any well laid out project will consist of more than just the Main Routine. When a project is first created in Studio 5000, a pre-created Task called MainTask will be created, inside this will be a Program called MainProgram, and inside this will be a Routine called MainRoutine

Whilst you can create your entire program in this routine, it’s better practice to split it up and process the logic across multiple routines:

This approach gives some segregation between functionality of different areas, but also allows for System_A / System_B to be exported and placed into another project if its something that is frequently used.

By providing this sort of structure to your project layout, you can visualize how this MainProgram is going to operate:

Just by segregating some logic into different routines enables us to have a better understanding of project flow.

Calling Routines From The MainRoutine

The JSR or Jump To Sub Routine function can be used to call another Routine:

By placing a JSR instruction, you can then choose a Routine to call. In this case, we’ll select the Inputs routine:

Note that when a JSR is placed, Input Par and Return Par fields are present. In this particular case, we’re not passing any Input or Output parameters to the Routine that we are calling. You can remove these using the Right Click menu.

You should end up with the just the call to the Inputs routine:

We can do the same for the other Routines in our Program:

The above image shows all of the Routines being called within the MainRoutine. Note that they will be called in the order they they are presented above, due to the scan order of the logic.

The JSR that called System_A also passes an Input Parameter. This is required because the System_A Routine requires that the Mode is set on entry into the Routine:

This is then used in the local logic of System_A.

Input / Output parameters can be a great way of reusing the same Routine with different data sets, or creating an interface so that data can be passed without having to look at the Controller Tags all the time. By creating parameters for a Routine, it further increases the flexibility to export to a different project.


Check Out Another Post

Leave a Reply