Skip to main content

Getting Started in CODESYS 4

The following guide describes the procedure how to create your first minimal project and download it to the controller.

The guide includes the following steps:

  1. Starting CODESYS 4

  2. Creating a workspace

  3. Creating a device project

  4. Setting up communication to the controller

  5. Downloading and logging in to the application on the controller

Starting CODESYS 4

  1. In the file explorer, open the installation directory of CODESYS 4.

  2. Run the CODESYS-4.exe program.

    The programming interface of CODESYS 4 will open.

Creating a workspace

  1. Select the Menu → Create Workspace command or click the _c4_icon_create_workspace.png icon.

  2. In the Create Workspace dialog, choose the name and click the _c4_drei_Punkte_path_selection.png button to select the location.

  3. Click OK.

    The workspace will be created and opened.

    The Add Project to Workspace dialog will open.

Creating a device project

  1. In the Add Project to Workspace dialog, select the Create Device Project entry.

  2. In the next dialog, specify the data for your new project and then click OK.

    • Click the _c4_drei_Punkte_path_selection.png button to select the location.

    • Choose the project name, for example MyFirstProject.

    • Specify values for all other parameters.

      The version number must be a 3 or 4-part semver, for example 2.1.0 or 1.0.0.0.

  3. In the Add PLC dialog, select the CODESYS Control Win V3 x64 controller.

  4. Choose a name for the controller, for example MyPLC, and click OK.

  5. In the Add program dialog, select Structured Text (ST) as the implementation language and click Create.

    The wizard will close and the project items will be displayed in the workspace navigator.

    The Communication.settings.json, ProjectInfo.json, TaskConfiguration.json, and Libraries.json files will be automatically generated and displayed in the workspace navigator.

  6. Double-click the PLC_PRG item.

    The PLC_PRG program will be opened in the editor.

  7. Enter the following program into the editor:

    PROGRAM PLC_PRG
    VAR
        iCounter: INT := 0;
    END_VAR
    
    // implementation here...
    iCounter := iCounter + 1;
    END_PROGRAM
  8. Right-click the Libraries.json item and run the Resolve All Libraries command.

  9. Check if errors are displayed in the LIBRARY RESOLUTION and PROBLEMS:LIBRARIES views.

    Note: The PROBLEMS:LIBRARIES view will be displayed only if errors have actually occurred.

  10. Right-click the Application.iecapp item and select the Build Application command.

  11. In the BUILD output, check that the project has been compiled successfully.

Setting up communication to the controller

  1. Double-click the Communication.settings.json item.

    The Communication Settings wizard will open in the editor.

  2. Click the Configure Device button.

    The Device Browser dialog will open.

  3. Click the Add Gateway button.

    Important

    The controller must be running in order to set up the gateway.

  4. In the Add Gateway dialog, choose a name for your gateway and click Add.

    Note: The values for IP address and Port remain unchanged.

    The gateway will be displayed in the Device Browser.

    The available controllers will be displayed.

  5. Click your controller to select it and click the Connect Device button.

    Because a user management has not been set up on your device yet, the Create Initial User for Device dialog will open.

  6. Choose a user name and password. Confirm the password and click Apply.

    Note: The chosen password must be at least 8 characters long and contain at least one uppercase letter, one lowercase letter, one special character, and one digit.

  7. In the Log In to Device dialog, provide your new credentials and click Log In.

    The notification Connection successful will be displayed.

  8. In the Device Browser dialog, click Select.

For more information, see the following: Communication.settings.json

Downloading and logging in to the application on the controller

  1. Right-click the Application.iecapp application and select the Download Application command.

    A notification will be displayed to indicate that existing applications on the controller will be overwritten. The application will be downloaded to the controller. The notification Download succeeded will be displayed.

  2. Click the _c4_icon_login.png icon (top right) or press the Alt+F8 shortcut to log in to the controller.

    The notification Login succeeded will be displayed.

  3. Open the PLC_PRG program in the editor.

  4. Click the _c4__start_application_play64px.svg icon (top right) to run the program.

    The inline monitoring in the editor will show the changing value of the iCounter variable.

  5. Open the WATCHLIST view. For Expression, specify the value PLC_PRG.iCounter.

    The changing value of the iCounter variable will be displayed under Value.

  6. Click the _c4_stop_application_stop64px.svg icon (top right) to stop the program.

  7. Click the _c4_icon_logout.png icon (top right) or press the Ctrl+F8 shortcut to log out of the controller.

    The notification Logout succeeded will be displayed.