User Guide

Debugging
106
Axcess Programming Language
Tracking down your errors
Finding run-time errors and logic errors can sometimes be difficult. Observing the values of
variables during program execution, following program flow through conditional statements, and
finding the locations of run-time errors are not easy tasks. However, there are some tools to help in
your debugging.
Tracing program flow
Many times, you may want to know if or when your program reaches a certain point. By using the
SEND_STRING keyword, you can send a message to your computer when it reaches a particular
section of code. When a string is sent to device Ø, the information is sent from the Central
Controller's communications port.
Here is an example:
IF (X = Y)
{
SEND_STRING Ø,"'X EQUALS Y!', $ØD, $ØA"
}
ELSE
{
SEND_STRING Ø,"'X DOES NOT EQUAL Y!', $ØD, $ØA"
}
In this example, you can observe at run time which branch the program takes by viewing the
message sent out of the Central Controller's communications port. This technique is also helpful in
locating run-time errors. By sending messages before and after suspected code, you can determine
if the code contains any bugs. For example:
DEFINE_VARIABLE
ARY[1Ø]
X
DEFINE_PROGRAM
X = 11
SEND_STRING Ø, 'BEFORE...'
ARY[X] = 123 (* This will cause an error *)
SEND_STRING Ø, "'...AFTER', $ØD, $ØA"
The resulting output from the Central Controller would look like this if the AMX BUG is on:
BEFORE...BAD ELEMENT ASSIGN BYTE ARRAY
...AFTER
By using the SEND_STRING statements, you can determine that the array assignment is causing
the run-time error message. While the error in this example is obvious, in more complex programs
the error may not be so obvious. In some cases, this debugging technique can prove to be
invaluable.