S7 PLC output

The S7 output (1500, 1200, 400 and 300) generates code for SIMATIC controllers. Totally Integrated Automation Portal (TIA Portal) is an IDE for the development and testing of SIMATIC controllers. Using the S7 output, the generated PLC code can be imported in TIA Portal. This allows for tight integration and smooth development cycles when implementing controllers on SIMATIC controllers.

Generated output

The CIF PLC code generator can generate code files that can be imported in TIA Portal (see S7 usage).

The following option restrictions apply:

  • The Convert enumerations option must be set to Convert enumerations to integers or Convert enumerations to constants.

The type of integer and real data types to use depends on the PLC integer type size and PLC real type size options. If Automatic is selected, the following data types are used:

S7 type Integer type Real type

S7-1500

LINT (64 bit)

LREAL (64 bit)

S7-1200

DINT (32 bit)

LREAL (64 bit)

S7-400

DINT (32 bit)

REAL (32 bit)

S7-300

DINT (32 bit)

REAL (32 bit)

The PLC task name, PLC task cycle time, PLC task priority, PLC project name, PLC configuration name, and PLC resource name options have no effect for this output type.

Standard compliance

In general, the CIF PLC code generator follows the IEC 61131-3 PLC standard and does not use vendor-specific extensions. For the Siemens S7 targets however, the persistent variables are stored in a separate database file, named DB. All references to persistent variables are prefixed with "DB".. Global variables and constants are stored in a tag table, instead of a global variable list. In those cases the output is not compliant with the IEC 61131-3 standard.

S7 usage

Follow these steps to create a project in TIA Portal, import PLC code in it, and use the PLC code to control the hardware:

  • Start TIA Portal.

  • Create a new S7 project:

    • In the Portal view, click Create new project.

    • In the Create new project window, choose a project name and enter it in the Project name box.

    • For Path, select the directory in which the directory for the project should be created.

    • Click Create to create the project.

    • Switch to the Project view.

  • Add the PLC device:

    • Unfold the project and select Add new device.

    • Select the device type (that is, S7-1500, S7-1200, S7-400 or S7-300).

    • Select the device with the correct article number.

    • Click OK.

  • Import the generated PLC code (PLC tags):

    • Open Default tag table inside the PLC tags folder.

    • Click the Import button.

    • Select the INPUTS.xml file. Make sure Tags is selected and click OK.

    • Click the Import button, again.

    • Select the CONSTS.xml file. Make sure Constants is selected and click OK.

  • Import the generated PLC code (Program blocks):

    • Unfold the External source files folder inside the device folder.

    • Click Add new external files.

    • Select all generated .scl, .udt and .db files (hold Shift) and click Open.

    • Select all imported files, right-click and select Generate blocks from source. Ignore any warnings or errors.

  • Compile the project:

    • Right-click Program blocks and select Compile  Software (rebuild all).

    • If there are warnings, compile again.

  • Import timers (optional):

    • Sometimes, timers are not imported correctly. In that case, compilation fails. To add the timers manually, do the following.

    • Open MAIN inside the Program blocks folder.

    • Type TON and click Enter. The Call options window pops up.

    • In the Call options window, for each timer, enter its name in the Name box and click btn[OK].

    • Delete the generated lines of code.

    • Compile the project again.

  • Configure the inputs and outputs:

    • Open Default tag table inside the PLC tags folder.

    • On the Tags tab, enter the addresses for all the inputs. The syntax of the addresses is outside the scope of this manual.

    • On the Tags tab, create new entries for the output variables.

    • Open MAIN inside the Program blocks folder.

  • Download PLC code to device:

    • Click the Download to device icon in the task bar. The Extended download to device window pops up.

    • Click Start search.

    • When a device has been found, click Load. The Load preview window pops up.

    • Click Load.

    • Change the Start modules action from No action to Start module.

    • Click Finish.

To debug the PLC code:

  • Click Go online in the task bar.

  • The values of various variables can now be inspected.

    • The values of input and output variables can be seen by opening Default tag table inside the PLC tags folder. Click the Monitor all icon. The actual values appear in the Monitor value column.

    • The values of state variables can be seen by opening DB under Program blocks. Click the Monitor all icon. Unfold the state0 variable. The actual values appear in the Monitor value column.

To stop the PLC:

  • While online, click STOP in the CPU operation panel in the Testing tab.

  • Click Go offline in the task bar.

To reset the PLC and start from the initial state, with the same code and the same configuration:

  • While online, click MRES in the CPU operation panel in the Testing tab. The Online & diagnostics window appears.

  • Click Yes.

  • If the PLC was in run mode, a new Online & diagnostics window appears. Click Yes.

  • Click Go online in the task bar.

  • Start the PLC by clicking RUN in the CPU operation panel in the Testing tab.

  • The PLC is now running, and you can use the system.