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 Formal function invocation (arguments based) option must be set to For all functions or For functions with more than one argument.

  • The Formal function invocation (function kind based) option must be set to For all functions.

  • 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 number bits option. If Automatic is selected, the following data types are used:

S7 type Integer type Bits integer type Real type Bits real type

S7-1500

LInt

64

LReal

64

S7-1200

DInt

32

LReal

64

S7-400

DInt

32

Real

32

S7-300

DInt

32

Real

32

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.

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, enter timer0 in the Name box and click btn[OK].

    • Delete the generated lines of code.

    • Similarly, create timer1.

    • 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.

    • At the end of the program, after END_WHILE, assign values to the output variables. The values may originate from variables part of "DB".state0, variables and constants part of Default tag table, functions for algebraic variables and regular functions.

  • 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.