Active Templates are an extremely powerful way of providing a library of re-usable code modules for various functions. Active Templates can embody a great deal of specialist knowledge and math. You get to use that simply by adjusting some settings.
An Active Template is a special kind of program that runs in your PC. It is dedicated to a particular function, say temperature measurement. It has the file extension .tp1 ("tee pee one"). Once you have installed the Active Template support package you can run a template in your PC by double clicking it. When you run the template you can adjust a number of setting to adapt it to your needs. The template then automatically generates the exact SPLat code required to implement the function according to your settings. When you save the template your settings get saved inside the template file. You can also launch a template from inside SPLat/PC using the menu File>Edit Template.
To use Active Templates you need:
The Active Template system includes the ability to automatically check online for updates, and invite you to download newer versions of templates and the support package. You may from time to time update the support package if we write a template that requires support files that are not in existing releases.
When you download an Active Template file (*.tp1) you can simply save it alongside your SPLat program source files. The file name is used in the generated code as part of the subroutine names that you need to call to use the template. If you run a template, change its name field and save it, you will get a new tp1 file with the changed name.
Active Templates are not stand-alone programs. They are software components that provide some specialized functionality. An Active Template no more generates a complete program than a timer relay is a complete control panel. To make use of a template you need to incorporate it into a larger program.
You can incorporate a template into your program by referring to it in a Builder file. Builder knows how to open a template, use your settings inside it to generate the correct SPLat code and then use the Builder tags to dovetail it into your SPLat program.
If you don't want to use Builder you can simply copy and paste the code generated by the template from the template screen directly into your program. Just follow the directions given in the comments in the generated code itself. This may seem quicker and easier initially, but it is harder to maintain. If you change one setting in the template you must rip the old code out of your program, possibly in several places, and graft in the new code. With Builder, once the .b1d file is set up it can be run any number of times on a click of your mouse.
Before trying to integrate an Active Template into your program, you need to understand what the template generated code needs to work. For example:
GoSub to their initialization subroutine before they will work. They will also need a RunTasksForever instruction in the startup code of your program.GoSub to their initialization subroutine before they will work.GoSubs.All the information on feeding and caring for a template is provided in the header comment in the generated code and in the template's documentation here in the SPLat Knowledge Base. There you will find the subroutine names to use in your GoSubs and information on how data is passed (in which registers etc).
Using Builder with templates is initially the more complicated way but it pays off in very much easier ongoing program maintenance.
mytmplt.tp1myprog.spt. In that file write the code that will use the template-generated code. Use Builder tags to distinguish initialization code segment, main program code segment, any NVEM0 segment(s), etc. Use segment names consistent with the template generated ones and the standard segment names documented under Builder. Save the file.myprog.spt and mytmplt.tp1., then is should list those two files (in either order). Save it as, say, mybld.b1d in the same folder as your other files.mybld.b1d file. This should launch SPLat/PC. You will be asked if you want to include trace information. Click Yes. If you have done everything correctly you will get an information box and then see the merged file in the SPLat/PC editor.All access from your program to the template must be via GoSub subroutine calls. Any data gets passed on the register stack (X, Y etc) or floating point registers W and/or Q. You cannot directly access any of the RAM data stored within the template generated code.
This is called encapsulation or data hiding (the two terms tend to be used interchangeably). It means that the code generated by the template is a "black box" module that can only be accessed via its "interface", i.e. the subroutines that are there to allow you access. What goes on inside is private to the module.
All other labels within the code generated by the template include a random hex number that will change every time the template is run, specifically to "hide" them from your code.