Example Program object fix

The following is a simple example fix for a Program object included in the widely-distributed NiagaraAX demo station. It is one of several Programs flagged with a “WARNING unable to compile” entry when AX-3.8 station backup .dist file for the demo station is used as source in the N4 migration tool.

A related snippet from the migration report (log file) looks like below.

WARNING unable to compile Program object PxHome.Graphics.Residential.First Floor.
GarageProgram
C:\Users\e333988\Niagara4.x\temp\Prog_ea44c5d3b904631ea44c5d3b904631.java:40: error: 
cannot find symbol
    Action action = getProgram().getAction("execute");
                    ^
  symbol:   method getProgram()
  location: class Prog_ea44c5d3b904631ea44c5d3b904631

This error relates to use of getProgram(), as described in API changes.

Opening the migrated “demo” station in your N4 Workbench, you can follow the ORD given in the warning, and open the Program Editor view for that Program (“GarageProgram”), as shown in the following figure.

Figure 23.   Example Program with issues from migrated “demo” station
Image

The WARNING snippet resulted from use of the now-obsolete getProgram(), which must be replaced by getComponent(). Also note the Program status: “Program is out of date and requires compile.”

If you compile the Program now without making any changes, various errors (4) appear in the console area at the bottom of the Workbench window, as shown below.

Figure 24.   Example errors from a compile before making any Program changes
Image

After replacing the two getProgram() instances to getComponent(), saving and then recompiling again, errors are reduced to two—related to use of getDouble() for primitives (25. Figure 28).

Figure 25.   Example Program with remaining issues from primitive syntax errors
Image

This is no longer necessary, as explained in the section Primitives. To fix, simply remove the text shown marked above.

As shown below, now after resaving the Program and recompiling, all errors are gone.

Figure 26.   Example Program object after fixing all issues and recompiling.
Image

Now note the status of the Program is: “Program is up-to-date”, and there are no errors reported in the bottom console area after the last compile and save.