Defining a Module
To use a module in a program, you must declare it using the DEFINE_MODULE
keyword. This tells the NetLinx compiler to add the module to the program, effectively merging the
module’s event handling and mainline code with the containing program (or module). In other words,
the program will have one event table and one mainline routine consisting of code from the main
program and all modules declared using the MODULE statement.
The example below demonstrates how a NetLinx module is incorporated into a main program. In this example the main program has no event table or mainline code.
A module is defined by the MODULE_NAME entry on the first line of the file.
Syntax
The MODULE_NAME entry identifies the file as containing a NetLinx module, as opposed to a standard NetLinx source code file. The module name is any valid string literal not to exceed 64 characters. A file can contain only one module and the file name must be the same as the module name with the addition of the ".AXS" extension.
Module parameters behave exactly like subroutine parameters; the parameter list is optional. The value for each parameter is set either by the main program or another module. If the value of a parameter is changed, both the main program and the module see the change.
- Constants and expressions cannot be used as arguments in the parameter list.
- Persistent variables do not work in Modules.
All parameters to a module must be on of the intrinsic types: CHAR, INTEGER, SINTEGER, LONG, SLONG, FLOAT, DOUBLE, DEV, DEVCHAN or DEVLEV. Also, any array of any of the intrinsic types can be used.
The example below defines a module named ModuleExample.
Aside from the MODULE_NAME entry, the code looks like any standard NetLinx source code file:
Technically, modules can contain declarations to other modules, provided that no circular references are involved.
However, because different instances of the same module must not be separated by instances of a different module, it is highly recommended that you do not declare modules from within other modules if you have multiple declarations of the parent module they will then be separated by the declarations of the child module.