Language Elements
56
NetLinx Programming Language Reference Guide
Subroutines
A subroutine is a section of code that stands alone, and can be called from anywhere else in the program.
DEFINE_CALL subroutines
The
DEFINE_CALL
is the standard method provided by NetLinx for defining subroutines.
DEFINE_CALL '<subroutine name>' [(Param1,Param2,...)]
{
(* statements *)
}
where
(Param1, Param2, ...)
refers to a comma-separated list of
<datatype><variable>
pairs. For example,
"INTEGER Size"
would be one pair.
DEFINE_CALL
names must not conflict with previously defined constants, variables, buffers, or wait
names. Unlike identifiers,
DEFINE_CALL
names are case sensitive.
A subroutine may accept parameters. To do this, each parameter and its type must be listed within the set
of parentheses to the right of the subroutine name, as shown below:
DEFINE_CALL 'Read Input' (CHAR Buffer)[ ]
{
}
To invoke a user-defined subroutine, use the
CALL
keyword plus the name of subroutine and any
required calling parameters.
CALL 'Read Input' (Buf1)
In NetLinx,
DEFINE_CALL
supports the
RETURN
statement (as shown in the following example),
although return values are not supported.
DEFINE_CALL 'Read Input' (CHAR Buffer)
{
if (nChars = 0)
{
RETURN // exit subroutine
}
(* read input *)
}
SYSTEM_CALL subroutines
A
SYSTEM_CALL
subroutine is a special type of
DEFINE_CALL
subroutine defined in a separate
program file called a
LIB file
with a
PROGRAM_NAME
entry matching the subroutine name.
PROGRAM_NAME = 'COSX'
DEFINE_CALL 'COSX' (FLOAT X)
{
(* body of subroutine *)
}
To invoke a system call, use the
SYSTEM_CALL
keyword followed by the name in single quotes and any
calling parameters, as shown below:
SYSTEM_CALL 'COSX' (45)
System calls are resolved automatically at compile time, without requiring an
INCLUDE
instruction to
include the system call source file.
Summary of Contents for NETLINX PROGRAMMING LANGUAGE
Page 15: ...Table of Contents xiii NetLinx Programming Language Reference Guide...
Page 16: ...xiv NetLinx Programming Language Reference Guide Table of Contents...
Page 18: ...Introduction 2 NetLinx Programming Language Reference Guide...
Page 76: ...Language Elements 60 NetLinx Programming Language Reference Guide...
Page 106: ...Combining Devices Levels and Channels 90 NetLinx Programming Language Reference Guide...
Page 112: ...Master To Master M2M 96 NetLinx Programming Language Reference Guide...
Page 182: ...Reserved Identifiers 166 NetLinx Programming Language Reference Guide...
Page 204: ...NetLinx UniCode Functions 188 NetLinx Programming Language Reference Guide...
Page 244: ...Appendix B Glossary 228 NetLinx Programming Language Reference Guide...
Page 245: ...Appendix B Glossary 229 NetLinx Programming Language Reference Guide...