Connecting and preparing Codesys for PLC operation for the first time


From this article you will learn, among other things:

  • what are "targets" for Codesys software,
  • how to install the targets,
  • how to configure your computer's network card,
  • how to create the first program for a PLC in Codesys.

This article is dedicated to preparing the Codesys universal environment for PLC. As you probably know, Codesys gives you the ability to program PLCs from many vendors.

To prepare Codesys to work with a particular PLC, you need to follow a few simple steps. In this article, we will work with the Astraada One ECC2200 controller.

However, if you don't have access to a PLC, nothing lost. You will be able to do everything on both the PLC and the simulator.

What are "targets" for Codesys software?

Targets are the common name for the hardware file that allows the Codesys environment to work with a given PLC. Installing targets makes the Codesys environment, compatible with a PLC that has a given unique set of CPU, memory, interfaces, etc.

Astraada One controllers have one common target called "1.23.0_ECC_EC_SP15_Patch4". Its installation ensures that you can program the entire Astraada One PLC family. By default, the targets are paid.

Installing targets for Codesys software

Now that you're stocked with Targets for Astraada One PLC, there's nothing left to do but install them and move on to the next steps of getting to know Codesys.

To do so, after launching Codesys, select Tools -> Package Manager from the top ribbon:

In the Package Manager window, click Install:

Then select the hardware file from your disk (you will receive it in the starter kit, among other things). The file is named: Berghof_MX6_Target_1.23.0.0.package:"

In the next step, select the full installation option and go through the steps by clicking Next.

Once the installation is complete, the Package Manager window will show the installed targets for Astraada One controllers. That's it, the Codesys environment is now ready to work with Astraada One PLCs. You perform the steps described above only once, at the beginning of your PLC programming adventure in Codesys. Each time thereafter, connecting to the controller will only require you to make a few clicks.

Important: It's worth knowing that the version of the targets installed in Codesys should coincide with the firmware version the PLC has. In the Tips&Tricks section, you will learn in a few steps how to update the controller's firmware in case of a version mismatch. You will do this from the Astraada One PLC's administration panel.

The environment is fully ready to start your Codesys programming adventure!

IP address of the controller

What is worth knowing before you start working with the PLC? The first is the factory (default) IP address of the PLC. You will need it to connect to the controller from within Codesys or to access the controller's administration panel using a web browser.

Factory IP address of the controller:

169.254.255.XX

XX - the last two digits of the controller's serial number (marked in red)

For the above nameplate, the IP address of the controller will be:

169.254.255.7

Configuring the computer's network card

Before starting work, make sure that the network card of the computer you are working on has the correct IP address. It should have a static IP address set in the controller's subnet. To change the card's settings, choose Control Panel -> Network and Internet -> Network and Sharing Center -> Change network card settings . Then right-click on your network card and select Properties:

Similar to what is shown above, set the IP address of your computer's network card as 169.254.255.(any address between 0;255 except the address of your PLC) and set the default gateway 255.255.0.0.

In my case, the address of the controller is 169.254.255.15, so I gave the IP address of the network card 169.254.255.159.

Creating your first PLC program in Codesys

All the steps you have done so far, you will do only once. You will learn them in quite a bit of detail so that you can complete them as quickly as possible and move on to the actual part, that is, creating PLC applications in the Codesys environment. By default, you will start your work with Codesys right here.

The process of creating the first program for a PLC is analogous to the same process for the simulator built into Codesys. It differs only in a few details.

Step 1: Create a new project

To do this, click File -> New Project or from the Basic Operations section select New Project, then specify the project name and confirm with OK:

In the next step, make a selection of the language in which you will create your first application and select the device on which the application will run. In this section of the course we are working with a PLC, so choose the previously installed Target Berghof MX6 Control (suitable for the entire family of Astraada One controllers.) In section No. 1 you selected CODESYS Control Win V3 (Simulator mode).

Select Ladder language as the main language in our project. This is not an obligatory choice, as you can change the language in which you write your application at a later stage. Moreover, your application can be written in several languages simultaneously.

After performing these operations, your first project in the Codesys environment has been created. The view is as follows:

Legend:

1. Program tree

2. Variables window

3. Menu bar

4. Program Editor

5. Dialog Window

6. ToolBox

Step 2: Add PLC I/O to the project

The Astraada One ECC2200 controller, which is included in the ONE-START starter kit, has 16 digital inputs and 16 digital outputs. Now you will add them to the project so that you can use them in your application.

To do this, select Device -> Add Device from the project tree and select the Extension_Slots object by double-clicking on it:

Connect a target object that maps the I/O of the Astraada One PLC to the Extension_Slots object. To do this, click in the project tree and select Plug Device. Then select the XBIO Berghof IO object:

With this, you have gained access to the digital inputs and outputs of the controller. You can now give them symbolic names and start using them in the program.

To do this, double-click on the XBIO_Berghof_IO object and in the BGH Slot BUS I/O Mapping tab give symbolic names corresponding to the inputs and outputs of the controller. See the example below

Important: Remember to check Enabled 2 (always in bus cycle task) , which ensures that the I/O status will be read continuously during the controller's duty cycle.

Step 3: Create your first program

You have already created an empty project in Codesys, added the controller's I/O variables and assigned symbolic names to them.

Now write the simplest functionality in ladder language, i.e. the function to activate the coil with a contact. This time, assign a variable responsible for the physical output OUT1 to the coil, so that the work of the program can be observed on the PLC.

To do this, double-click on the PLC_PRG object, which is the main program of the application. Then go to the ToolBox window, which contains the basic elements of the ladder language.

Click and hold the contact element (Contact) and drop it in the program area. Then assign it a variable name. You can assign the name of the variable you assigned to the physical input (e.g. IN1) or any variable in the controller's memory.

For example, create a variable unmapped to a physical input:

Add a solenoid in a similar manner, and click on the variable assignment location:

This time assign the variable mapped earlier, which corresponds to the first digital output of the controller. In the Input Assistant window, in the variables tree, enter IoConfig_Globals_Mapping and select the variable OUT1:

With this, you have created the first rung of the ladder in Codesys. As you probably noticed, you can use the Auto Declare option (creating a variable bStart), where you automatically declare a variable, or you can use the Input Assistant window to select a previously created variable (assigning a variable to a coil).

Now move on to testing your mini-program and checking the operation of the PLC with an application written in Codesys.

Compiling the project and uploading the application to the PLC

In Codesys, you will compile your program by selecting Build -> Build arba from the context menu or using the keyboard shortcut F11. After compiling the program, any error or warning information will be displayed in the Messages dialog box:

Establishing communication with a PLC in Codesys

You have already created your first project in Codesys, the next step will be to upload it to the PLC. To do this, you need to establish communication with it. To do this, select Device -> Scan Network: from the project tree:

Assuming you properly configured the controller's network card at the beginning of this section, the Codesys software should find the Astraada One PLC connected to your computer. Select it as well as confirm:

As an alternative to scanning the network, you can enter the IP address of the PLC in the Device window that opens and confirm with the Enter key:

The Codesys environment indicates with green LEDs that successful communication with the PLC has been established:

Uploading the program to the PLC

There is nothing left for you to do but to upload the program and test its operation. To do so, select Login:

When you select Login, Codesys will display a window asking you in which mode you want to upload your application. Codesys gives you several options to choose from:

Login with online change: option to upload changes to your application while the controller is running. The PLC does not stop operation during this operation. Uploading changes is done "on the fly." This option is convenient if you want to upload changes/modifications to an application already running on the PLC.

Login with download: the entire application is uploaded to the controller's memory. The operation requires stopping the operation of the controller.

Login with download: The option to log into the controller without uploading changes to the application, even if they have already been made. This is a convenient action in case you make changes to the application, and there was a need to test its previous version.

Since there is no application running in the driver, select Login with download and confirm your choice. You will receive a message that the application has been correctly uploaded to the controller's memory and that it is in STOP mode:

Then switch to RUN mode by selecting Start from the context menu::

Preview the program's operation in Codesys

While the program is running, you can observe its status. You can preview the status of the program's variables in the main program editor and in the variables window:

You can also observe the operation of the program on the LEDs of your Astraada One controller, since the variable OUT1 corresponds to the digital output of the controller.