Function Block Examples
Previous Topic  Next Topic 

The function_block always follows the main..endmain section and may contain an optional onsignal_declaration and zero or more function_declarations and declaration_blocks.      If an onsignal_declaration exists is must reside in the main .TES source file, however the rest of the function_declarations can optionally reside in other .FUN source files.


Below is a small program which calls two functions which are declared after the main…endmain section.      This program also has an onsignal_declaration and another declaration_block:,




main


    my_function1("hello");

    my_function2("world");


endmain


// *** The function block starts here....


func function1(str)

    applog(str);

endfunc


func function2(str)

    applog(str);

endfunc


int a,b;


onsignal

   a=1;

   b=1;


   applog("We have received a signal");


   restart;

endonsignal



As mentioned,  functions can be declared in a separate source file (or in a TEL library file).        The source file that contains the function declaration should have the same name as the function with a “.fun” extension.      For example a function called MYfunction() would need to reside in a file called myfunction.fun.    Unfortunately windows file names are not case sensitive so it is not possible to declare two different functions like ABC() and abc() in two separate .FUN files and be able to distinguish between them using the file name.      For this reason it is advisable not to distinguish between function names by character case alone (i.e. give all functions a unique name), or otherwise include these functions in the main (.TES) source file.


Multiple functions can be declared within a single .FUN file but only the function that has the same name as the .FUN file can be called from another source file (all other functions can only be called from within that particular .FUN file).


Functions can also be combined into a library file (with extension .TEL) using the MKTEL.EXE utility (See Telecom Engine Compiler, and Telecom Engine Utility programs), and these can be linked into the application by providing the name of the TEL file using the L option of the TCL compiler (See Telecom Engine Compiler).