5 CODESYS Programming

This chapter introduces how to go about programming with the codesys IDE.

TIP

As the CODESYS license of the product is stored in the OS by default, it is not recommended for users to flash to eMMC by themselves, and re-flashing to eMMC will result in the loss of the CODESYS license and affect the use.

5.1 CODESYS software download and installation

TIP

The installed CODESYS IDE version needs to be 3.5.19 and above, and the PC operating system requires Windows 10 or Windows 11 (64-bit recommended).

Steps:

  1. Download the installation package from the official CODESYS website, download URL:https://store.codesys.com/de/.

TIP

The first time you enter the official website to download, you need to register and log in to your account.

  1. Right-click on the downloaded installation package and run it as administrator.

  2. Click "Install" in the installation page that opens, and just keep the default configuration during the installation process.

image-20241106160937966
  1. When the installation is complete, click "Finish" to close the installation page.
image-20241106161150401

5.2 Obtaining and Installing Device File

Before connecting the device via CODESYS, you need to download and install the device file.

5.2.1 Get device description file

TIP

The default IP address of Ethernet port is 192.168.0.100, and the IP address of EtherCAT port is 192.168.1.100, if you need to modify, please refer to Configuring Ethernet IP.

Preparation:

  • A CODESYS authorised device has been acquired.
  • A working network cable has been obtained.
  • A working PC has been acquired and is on the same network segment as the device.

Steps:

  1. Connect the Ethernet network port of the ED-PLC2010 to a PC computer via a network cable to power up the device.

  2. Enter the default IP address http://192.168.0.100:8100 of the Ethernet port of ED-PLC2010 into the browser and enter "PLC Setting".

  3. Click "[Download] Device Description File"in "Device Information" to download the corresponding device description file in ".xml" format.

90980921611

TIP

Also available directly in the document ED-PLC2010 Device Description File.

5.2.2 Installing the Device File

Preparation:

  • A PC with CODESYS software version V3.5 SP19 (64bit) and an IP address on the same network segment as the device.
  • A working network cable has been obtained.
  • One ED-PLC2010 has been licensed by CODESYS and the corresponding device file has been obtained.

Steps:

  1. Double-click the CODESYS icon on the PC desktop to open the CODESYS software. Select “Tools” → “Device Repository” in the menu bar.
1
  1. In the "Device Repository" pane, click "Install", select the device file and click "Open" to install it.
2
  1. After successful installation, you can see that the device file has been added successfully in the "Device Repository".
09po44489

5.3 Hardware configuration

Preparation:

  • A PC with CODESYS software version V3.5 SP19 (64bit) and an IP address on the same network segment as the device.

  • The device file has been installed.

  • Local I/O modules have been connected to the ED-PLC2010 via E-bus contacts.

  • The remote I/O module has been connected to the EtherCAT port of the ED-PLC2010 via a network cable.

5.3.1 Create a new project and connect the device

Steps:

  1. Power up the ED-PLC2010 and remote I/O module and open the CODESYS software on the PC. In the menu bar, select "File"-> "New Project", open the “New Project” pane, create a standard project.
3
  1. Select the device for which the device file has been installed and click OK.
09po45555589
  1. Double left-click the device, select “Scan for Networks” on the right, then select the scanned device, and finally click “OK”.
230e0137983121ca80f640f881b0ba2

TIP

If the device user login pop-up appears, you will need to log in with your username and password or follow the prompts to register.

  1. As shown in the following figure, it indicates that the device is connected.
09po44lkjq489

5.3.2 Adding Local I/O and Remote I/O Modules

Steps:

  1. Right-click “Device” and select “Add Device” in the menu to add the master EtherCAT Master.
71657
  1. Double-click on the EtherCAT master device to set the source address (the exact name can be seen in the pc network manager).
09po44lkwwwj489
  1. Click on the EtherCAT master device, select “Scan for Devices” in the right-click menu, and copy all devices to the project after scanning is completed.
09po44l089
  1. To set up the slave, double-click on the slave, enable "Expert settings", and enable " Select DC" and "Sync0".
09po44l080009
  1. Click Login and Run to connect successfully.
09po44l0po89

5.4 Programming

The following section describes specific programming with a specific programming example.

5.4.1 Programming Process

09po44l0liuo89

5.4.2 Programming Example

Complete the writing and debugging of a program to flash 1 LED at 0.5 second intervals, using an 8-port I/O output module (PNP type).

Preparation:

  • A new standard project has been completed.
  • Hardware configuration has been completed.
  • 1 x 24v compact LED has been connected to the local DO module.

Steps:

  1. Confirm the address of the output point of the DO module connected to the LED, click the DO output module connected to the LED, select “ModuleI/O Mapping->Output” in the right interface, you can check the address of each output point, in the example, we use the first output point, the address is %QX18.0.
5681246
  1. Click “PLC_PLG” to open the program writing interface, the upper side is the declaration variable area, the lower side is the main program writing area.

    oiuye2609
  2. Write the program code as follows.

    PROGRAM PLC_PRG
VAR	

TON_TIME : TON;
Light_Output : BOOL := FALSE; 

END_VAR
    TON_TIME(IN := NOT TON_TIME.Q, 
             PT := T#0.5S); 
    IF TON_TIME.Q THEN 
        Light_Output := NOT Light_Output; 
        TON_TIME(IN := FALSE); 
    END_IF

    %QX18.0:= Light_Output;   
  1. Once the program has been written, click Compile, and make sure the program reports no errors.
83244407
  1. Click Login and download the program to the device, then click Run, you can see the LED blinking every 0.5S.
890983640

5.5 Operation and Maintenance

5.5.1 Program operation and shutdown operation

After writing the program, perform the run and stop operations as shown in the following table.

StateOperation
Run the program1. Click the Login button in the software interface
2. After importing the program update from the USB flash drive, press and hold the hidden button “STOP START” on the device to run the program.
Stop the program1. Click on the Stop button in the software interface
2. Press and hold the hidden button “STOP START” of the device, the indicator “ERR” lights up and the program stops running.

5.5.2 Importing a USB flash drive user program

Preparation:

  • Completed writing the program and compiled it without errors.
  • Obtained a USB flash drive for normal use

Steps:

  1. To export the application, select “Online” -> “Create Boot Application” in the main menu.
90898336
  1. "Application.app" and "Application.crc" files are generated by default, choose to customize the path where they are stored.

  2. Format the USB flash drive and create a folder named “Application” in the root directory, copy the “Application.app” and “Application.crc” files to the “Application” folder.

  3. Insert the USB flash drive into the USB 3.0 port of the device, at this time, the indicator of “UDISK DETECT” and “UDISK BUSY” will be always on, indicating that the device has recognized the USB flash drive.

  4. Press and hold the hidden button “STOP START” of the device, if the device has a program running at this time, it will stop running and the indicator “ERR” will be always on. At this time, Press and hold the “IMP” button again, the indicator “UPDATE” will flash once, indicating that the program has been updated. Press and hold the button “STOP START” again, the indicator “ERR” will go out, and the program imported from the USB flash drive will start to run normally.

  5. To uninstall the USB flash drive, press and hold the “UDISK RM” button, wait for the “UDISK BUSY” indicator to go out, then unplug the USB flash drive from the device, and the USB flash drive import program will end.

TIP

The hardware configuration of the imported program and the hardware configuration of the device must be the same when importing a program from a USB flash drive, otherwise an error will occur during importing and the indicator “IO ERR” will be always on.