How to Turn the Digital I/O On and Off using CODESYS with an HMI and Remote I/O
This tutorial will demonstrate how to connect an iR-ETN40R Remote I/O and a cMT device using CODESYS to turn a digital input and output on and off utilizing both HMI and CODESYS programming software’s while communicating via Modbus.
Software Required
Hardware Required
- cMT3102Xv2 – Other cMT Devices can be used.
Wiring Design
WIRING
24V to Terminal I (CH0) on iR-ETN40R
0V to Terminal I (S0) on iR-ETN40R
CODESYS Tag Configuration and I/O Mapping
Add a POU object. POU programs are built for generating symbols to be read or written by the HMI.
Right click [Application] >> [Add Object] >> [POU].
Enter the code in the POU Program. Under VAR, type the code.
For example:
[DI_I_00 : BOOL; ] = DigitalInput_Terminal1_Channel0
[DQ_I_00 : BOOL; ] = DigitalOutput_Terminal1_Channel0
Add the Ladder Logic Code. Right Click in the Program Window >> Click [Insert Contact]
Click [the ellipsis] next to the three question marks.
Select BOOL [DI_I_00] >> Press [OK]
Right click in the program window >> Select [Insert Coil]
Click > [_DQ_I_00] BOOL >> Press [OK]
Complete Ladder Diagram Code
I/O Mapping. Adding the variables to the Modbus TCP Slave device (iR-ETN40R). Double click the Modbus TCP Slave device >> select the [ModbusTCPSlave I/O Mapping] tab >> Double click under the [Variable] column next to [Built-in ‘I’.Digital Input] Channel >> Click the ellipsis >> Click the [+] sign next to Application >> Click the [+] sign next to [POU] >> Select the [DI_I_00] BOOL.
Double click under the [Variable] column next to [Built-in ‘I’.Digital Output (W)] Channel >> Click the ellipsis >> Click the [+] sign next to Application >> Click the [+] sign next to [POU] >> Select the [DQ_I_00] BOOL.
Click [Task Configuration] then right click [Main Task] >>[Add Object] >> [Program Call]
Click the ellipsis
Select [POU Program] >> Click [OK]
CODESYS inserts the selected POU into the POU list on the Configuration tab and below the task object in the device tree.
When the application is executed from the PLC, CODESYS executes the selected POU in cyclical intervals of 300 ms.
Adding a Symbol Configuration. Right click on [Application] >> Click [Add Object] >> Click [Symbol Configuration]
Click [Build]. This compiles the program. CODESYS displays any error messages or warnings in the messages view.
Go to Build >> [Generate Code]
When generating code, CODESYS also generates a symbol file (*.xml) which includes the description of the symbols.
The symbol file is stored in the project directory. The name of the symbol file is composed as follows:
project name > device name > application name > .xml
CODESYS Online
The symbol configuration will be transfered to an .xml file with the next download or online change.
To go online in CODESYS go to [Online] >> [Login]
CODESYS is now online and displaying TRUE for Digital Input Channel 0 and TRUE for Digital Output Channel 0.
Adding CODESYS device/tags in HMI Programming Software
Add the Built-in CODESYS device into your EBPro Project
Go to [Home] >> [System Parameters] >> [New Device/Server] >> Choose the Weintek Built-in CODESYS device. Click [OK].
Click [Import Tags] and select the .xml file from the CODESYS projects file directory.
Once the tags are imported, you will receive this message. Then press [OK].
Download the project to the cMT device
cMT User Interface
Turn on Digital Input 0 (or whichever digital input you have configured.) to display on the cMT’s interface.
The Digital Input and Output are also turned ON in Easy Remote I/O.
Digital Input #0 displays an online value of 1 which means that it is ON.
Digital Output #0 displays an online value of 1 as well.
Sample Project
The project shown above was designed for the specific hardware mentioned at the beginning of the tutorial and is intended to provide you guidance when programming your unit. If you are using models other than the ones specified in this sample project, similar steps can be duplicated within your own project.
Download CODESYS Sample Project
Download EasyRemote IO Sample Project
Download EBPro Sample Project
Resources & Documentation
CODESYS Resources
- Connecting HMI & CODESYS to iR-ETN40R
- iR-ETN40R User Manual
- Activate CODESYS on cMT Models
- How to use Built-in CODESYS with later version of the CODESYS IDE
- CODESYS Quick Start Guide
- EasyRemote IO User Manual
- EBPro Quick Start Guide
More
See our Support Center for a complete list of Quick Start and Installation Guides