186-Axcess vs NetLinx on precedence of NOT
Technical Support Guide
Table of Contents
Brand:
- AMX
Models:
- Axcess
- Netlinx
Overview:
According to each of their language reference manuals AXCESS and NetLinx each give the operator NOT highest precedence while
giving AND and OR lowest.
Example Code:
As demonstrated in the following code, however, the two systems behave differently. In reality, AXCESS
gives the operator NOT lowest precedence.
DEFINE_VARIABLE
C
D
E
DEFINE_CALL 'GO' (A,B)
{
C = !A && B
D = B && !A
E = !B && !A
}
DEFINE_PROGRAM
PUSH[1,1]
CALL 'GO' (0,0)
PUSH[1,2]
CALL 'GO' (1,0)
PUSH[1,3]
CALL 'GO' (0,1)
PUSH[1,4]
CALL 'GO' (1,1)
AXCESS RESULTS
A B !A && B B && !A !B && !A
0 0 1 0 1
1 0 1 0 1
0 1 1 1 0
1 1 0 0 1
NETLINX RESULTS
A B !A && B B && !A !B && !A
0 0 0 0 1
1 0 0 0 0
0 1 1 1 0
1 1 0 0 0Key Points:
Note:
The problem applies whether A and B are channels, variables, or expressions, and for OR as well as AND. We've been aware of this problem in AXCESS for years and years.
To solve the problem, we've always recommended the use of (!A) && B instead of !A && B.
However, and this is the critical point, some programs out there are taking advantage of the logic flaw. Where the AXCESS programmer intended the truth table of !(A && B) he/she may have coded !A && B and gotten the desired result. The problem is, if these systems are converted to NetLinx masters, the logic will not work as desired.
Please be aware of this difference as you support programs which are being converted from AXCESS to NetLinx. When it occurs, AXCESS-like operation can generally be achieved by including all the conditions to the right of the NOT in a single set of parentheses.
e.g.
IF (SYSTEM_POWER && ![VCR,PLAY] || [VCR,RECORD])becomes
IF (SYSTEM_POWER && !([VCR,PLAY] || [VCR,RECORD]))I'd like to recommend adding this note to or near the "Operator Precedence" chart in the NetLinx Programming manual:
Note regarding AXCESS programs:
As noted in the chart, the NOT (!) operator has highest precedence in NetLinx systems. In AXCESS systems, NOT (!) has lowest precedence. AXCESS programs that are converted to NetLinx may exhibit logic problems if they use statments which combine NOT (!) and other operators. Please contact Amx Technical Support for help resolving these issues.
Table of Contents