• No results found

Compiling an SCL Program

4 Using SCL

4.7 Compiling an SCL Program

4.7.1 What You Should Know About Compiling

Before you run can run or test your program, you must first compile it. Once you start compilation, the compiler is started automatically. The compiler has the following characteristics:

• You can compile an entire SCL source file in one compilation session or compile selected individual blocks from the source file.

• All syntax errors found by the compiler are displayed in a window.

• Each time a function block is called, a corresponding instance data block is created if it does not already exist.

• You can also compile several SCL source files together by creating an SCL compilation control file.

• Using the Options > Customize menu command, you can set options for the compiler.

Once you have created a user program that is free of errors and has been compiled, you can assume that the program is correct. Problems can, nevertheless, occur when the program is run on the PLC. Use the debugging functions of SCL to find errors of this type.

4.7.2 Customizing the Compiler

You can adapt the compilation to meet your own requirements.

Follow the steps outlined below:

1. Select the menu command Options > Customize to open the "Customize"

dialog box.

2. Select the "Compiler" tab or "Create Block" tab.

3. Enter the options you require in the tab.

S7-SCL V5.3 for S7-300/400

4-16 A5E00290611-01

Options in the "Compiler" Tab

Create object code With this option, you decide whether or not you want to create executable code. Compilation without this option serves simply as a syntax check.

Optimize object code When you select this option, the blocks are optimized in terms of memory requirements and runtime on the PLC. It is advisable to keep this option permanently selected since the optimization has no disadvantages that affect the functionality of the block.

Monitor array limits If you select this option, a check is made during the runtime of the S7 program to determine whether array indexes are within the permitted range according to the declaration for the ARRAY. If an array index exceeds the permitted range, the OK flag is set to FALSE.

Create debug info This option allows you to run a test with the debugger after you have compiled the program and downloaded it to the CPU. The memory requirements of the program and the runtimes on the AS are, however, increased by this option.

Set OK flag This option allows you to query the OK flag in your SCL source texts.

Permit nested comments Select this option if you want to nest comments within other comments in your SCL source file.

Maximum string length: Here, you can reduce the standard length of the STRING data type. The default is 254 characters. The setting affects all output and in/out parameters as well as the return values of functions. Note the value you set must not be smaller than the STRING variables actually used in the program.

Options in the "Create Block" Tab

Overwrite blocks Overwrites existing blocks in the "Blocks" folder of an S7 program if blocks with the same identifier are created during compilation.

Blocks with the same name that already exist on the target system are also overwritten when you download blocks.

If you do not select this option, you are prompted for confirmation before a block is overwritten.

Display warnings You can decide whether you also want warnings displayed in addition to errors following compilation.

Display errors before warnings

You can have errors listed before warnings in the display window.

Generate reference data Select this option if you want reference data to be generated automatically when a block is created.

With the menu command Options > Reference Data, you can also generate or update the reference data later.

Include system attribute 'S7_server'

Select this option if you want the "S7 server" system attribute for parameters to be taken into account when a block is created. You assign this attribute when the parameter is relevant to the configuration of connections or messages. It contains the connection or message number. This option extends the time required for compilation.

4.7.3 Compiling the Program

Before you can test a program or run it, it must first be compiled.To make sure that you always compile the latest version of your SCL source file, it is advisable to select the menu command Options > Customize and to select the option "Save before compiling" in the "Editor" tab. The menu command File > Compile then implicitly saves the SCL source file.

Follow the Steps Outlined Below:

1. Save the SCL source file to be compiled.

2. To create an executable program, you must select the option "Create object code" in the "Compiler" tab of the "Customize" dialog box.

3. If required, modify other compiler settings.

4. Check whether the corresponding symbol table is in the same program folder.

5. You can start compilation in the following ways:

- The menu command File > Compile compiles the entire source file.

- The menu command File > Compile Selected Blocks opens a dialog box in which you can select individual blocks for compilation.

6. The "Errors and Warnings" dialog box displays all syntax errors and warnings that occurred while the program was being compiled. Correct any errors reported by the compiler and then repeat the procedure outlined above.

4.7.4 Creating a Compilation Control File

If you create a compilation control file, you can compile several SCL source files at one time within a source folder. In the compilation control file, you enter the name of the SCL source files in the order in which they are to be compiled.

Follow the Steps Outlined Below:

1. Open the "New" dialog box by selecting the menu command File > New.

2. In the "New" dialog box, select

- a source file folder within an S7 program and - the filter "SCL Compilation Control File"

3. Enter the name of the control file in the corresponding box (max. 24 characters) and confirm with "OK".

4. The file is created and displayed in a working window for further editing.

In the working window, enter the name of the SCL source files to be compiled in the required order and save the file.

5. Then start the compilation by selecting the menu command File > Compile.

S7-SCL V5.3 for S7-300/400

4-18 A5E00290611-01

4.7.5 Debugging the Program After Compilation

All the syntax errors and warnings that occur during compilation are displayed in the "Errors and Warnings" window.If an error occurs, the block cannot be compiled, whereas if only warnings occur, an executable block is compiled. You may still, nevertheless, encounter problems running the block on the PLC.

To correct an error:

1. Select the error and press the F1 key to display a description of the error and instructions on correcting the error.

2. If a line number and column number are displayed, you can locate the error in the source text as follows:

- Click the error message in the "Errors and Warnings" window with the right mouse button and then select the Display Errors command.

- Double-click the error message to position the cursor on the point reported (line, column).

3. Find out the correct syntax in the SCL Language Description.

4. Make the necessary corrections in the source text.

5. Save the source file.

6. Compile the source file again.