How to Connect a CODESYS PLC to Factory IO Using Modbus TCP

Simulating PLC code in a 3D environment before field commissioning cuts troubleshooting time and prevents equipment damage. This guide details how to link CODESYS with Factory I/O through Modbus TCP/IP, running both the logic and the virtual mechanical process locally on a PC.

Core Components

  • CODESYS: An IEC 61131-3 compliant development suite with an integrated SoftPLC runtime (CODESYS Control Win V3), allowing local testing without physical hardware.
  • Factory I/O: A 3D physics-driven industrial simulation platform designed to build and control virtual automated cells, packaging lines, and conveyor systems.
  • Modbus TCP/IP: An Ethernet-adapted fieldbus protocol where CODESYS functions as the Modbus Server (Slave) and Factory I/O acts as the Modbus Client (Master) reading and writing registers in real time.

Step 1: Defining Global Variables (GVL)

After launching your CODESYS project, define the signals that will exchange data with sensors and actuators in Factory I/O:
1.In the project tree, right-click on the Application node and select Add Object > Global Variable List (GVL) to create the IO list.

2.Add two variables of type BOOL:
BOOL_IN_0: The digital sensor input signal coming from Factory I/O.
BOOL_OUT_0: The digital PLC output signal controlling the conveyor motor in Factory I/O.

STEP 1

Step 2: Creating the Control Logic (Ladder Diagram)

Open PLC_PRG to build the verification logic:
In Network 1 of the Ladder diagram, place a normally open (NO) contact mapped to
IO.BOOL_IN_0 in series with an output coil mapped to
IO.BOOL_OUT_0. When the sensor signal becomes TRUE, the output energizes and activates the conveyor.

STEP 2

Step 3: Configuring the Symbol Table (Symbol Configuration)

Compile the symbol configuration so CODESYS can expose these tags to external drivers:
Right-click Application, add a Symbol Configuration object, and click the Build button on the top toolbar once the window opens.
Under the compiled IO node, check the boxes next to both BOOL_IN_0 and BOOL_OUT_0.

STEP 3

Step 4: Adding the Ethernet Adapter

Integrate the virtual network interface into your device tree to establish the communication layer:
Right-click Device (CODESYS Control Win V3 x64) and select Add Device.
Navigate to Fieldbuses > Ethernet Adapter > Ethernet, then click Add Device to attach Ethernet_1 to the project tree.

STEP 4

Step 5: Configuring the Modbus TCP Server Device

Set up the slave service that will listen on the Ethernet network:
Right-click Ethernet_1 and select Add Device.
Navigate to Fieldbuses > Modbus > Modbus TCP Server Device and add it to the device tree.
Double-click ModbusTCP_Server_Device to access the
General tab:Double-click ModbusTCP_Server_Device to access the General tab:

Server port: 502
Holding registers / Input registers: 10
Discrete Bit Areas: Check this box to enable it.
Coils: 8 (%IX)
Discrete Inputs: 8 (%QX)
Data Model: Leave the starting address for Coils at 0, Discrete inputs at 0, and register offsets at 10.

STEP 5

Step 6: Modbus I/O Variable Mapping

The Factory I/O Modbus TCP Client driver writes sensor data into the server’s Coils area and reads actuator commands from the Discrete Inputs area. Map the variables accordingly:

Navigate to the Modbus TCP Server Device I/O Mapping tab.

Under Coils > Coils[0] > Bit0 (%IX20.0), double-click the Variable column and assign Application.IO.BOOL_IN_0.

Under Discrete Inputs > Discrete Inputs[0] > Bit0 (%QX20.0), double-click the Variable column and assign Application.IO.BOOL_OUT_0.

STEP 6

Step 7: Connecting to the Local Runtime and Downloading

Right-click the CODESYS Control Win V3 x64 icon in the Windows taskbar tray and choose Start PLC to spin up the local SoftPLC service.

In the CODESYS editor, double-click Device and open the Communication Settings tab. Select your local gateway (Gateway-1 / localhost:1217) and confirm an active target connection (DEVICE (active) indicated by solid green nodes).

Go to Online > Login (Alt+F8) to compile and download the application, then hit Debug > Start (F5) to switch the PLC to RUN mode.

STEP 7

Step 8: Configuring the Factory I/O Modbus Client Connection

Open Factory I/O and load the corresponding workstation scene.

Go to File > Drivers and pick Modbus TCP/IP Client from the dropdown menu.

In the driver configuration panel, verify that the host is set to 127.0.0.1:502 and the Slave ID is set to 1.

In the I/O mapping table:

Drag the Sensor tag into the Coil 0 slot.

Drag the Conveyor motor tag into the Input 0 slot.

Click Connect (a green checkmark next to the driver confirms an active handshake).

Return to the main 3D viewport, click Play, and test if triggering the optical sensor drives the conveyor motor as programmed.

STEP 8

Step 9: Configuring Factory I/O and Running the Simulation

Open the Scene: Launch Factory I/O, click Open, and select the default 1 – From A to B material handling scene.
Select Modbus Driver: Go to File > Drivers and choose Modbus TCP/IP Client from the driver dropdown list.
Verify Connection Settings: Click Configuration and confirm the local target parameters:
Host: 127.0.0.1 (localhost loopback)
Port: 502
Slave ID: 1
Assign I/O Tags: Return to the driver window and map the scene elements to the Modbus addresses configured in CODESYS:
Drag Sensor into the Coil 0 slot (transfers photo-eye states to CODESYS %IX20.0).
Drag Conveyor into the Input 0 slot (receives motor run commands from CODESYS %QX20.0).
(Optional) Map FACTORY I/O (Running) to Coil 1 to track simulation status inside the PLC.
Establish Online Link: Click Connect. A solid green circle confirms active Modbus polling with the CODESYS SoftPLC runtime.
Run the Simulation: Close the Driver view, switch to the 3D viewport, and press Play (or Spacebar) to verify real-time sensor detection and conveyor response.

STEP 9

Conclusion

Connecting CODESYS to Factory I/O over Modbus TCP/IP provides a risk-free virtual commissioning workflow directly on a PC. By mapping discrete coils and inputs across the 127.0.0.1:502 loopback address, you can thoroughly test sequencing, interlocks, and sensor logic before executing code on physical machinery.

References & Resources

  • CODESYS: CODESYS Development System V3 & CODESYS Control Win V3 Runtime — codesys.com
  • Factory I/O: 3D Factory Simulation for PLC Training — Real Games — factoryio.com
  • RealPars: Industrial Automation Learning Platform & PLC Training Resources — realpars.com
Yukarı Çık