Unity Pro Soft PLC through Modbus TCP/IP


  • Modbus & OPC Client DA Edition or Ultimate Edition
  • Schneider Unity Pro

This tutorial gives you step-by-step instructions on how to use Schneider Unity Pro SoftPLC to control FACTORY I/O through Modbus TCP/IP. We will be using Unity Pro simulation mode, which simulates an M340 PLC with a Modbus server. FACTORY I/O will be running as a Modbus TCP/IP client.

Setting up FACTORY I/O Modbus TCP/IP Client

  1. Download the zip archive (top of this page), extract it and open the project in Schneider Unity Pro.

  2. Start FACTORY I/O and open the Sorting by Height (Advanced) scene.

    open scene

  3. Press F4 to open the Driver Window. Note that I/O points are already setup with 17 digital inputs (sensors), 13 digital outputs (actuators) adn 1 input register (number shown by the display: Counter).

    i/o point mapping

    Modbus TCP/IP clients can only write to Coils. Read operations can be performed on Coils or Inputs according to settings chosen in the CONFIGURATION panel.

    In Schneider Unity Pro, both Coils and Inputs are stored in internal Boolean memories (%M) and share the same memory space. We are setting an Offset of 17 to Outputs in order to have the first 17 addresses available for Coils (sensors). Also, in Schneider Unity pro, both Discrete Inputs and Holding Registers are stored in internal Word memories (%MW).

    On this sample, digital input I/O points (sensors) are written to %M0 up to %M16, and digital outputs (actuators) are read from %M17 up to %M29. The discrete output point used by the display (Counter) is read from %MW0.

    digital output offset

Setting up Unity Pro

  1. Start Unity Pro and create a new project (FILE > New). Then select a M340 PLC.

    create new project for m340 plc

  2. The project has been created and you are now ready to start writing the PLC program. But first, you must define the I/O variables that will be used.

  3. Double Left-click on Elementary Variables and create 17 EBOOL variables named Sensor0 up to Sensor16. These will be the variables used for sensor values. On the Comment fields type in the name of the FACTORY I/O points they represent so you can easily relate one to another.

  4. Next, create 13 EBOOL variables named Actuator0 up to Actuator12. These will be the variables used for actuators. As you did previously, fill the Comments fields with the name of the FACTORY I/O points they represent. At last, create 1 INT variable named Counter0 (which is to be used by the counter display).

    variable definition in unitypro

  5. Create a section for the PLC code by Right-clicking on Program > Tasks > MAST > Sections and selecting New section...

    create section for code

  6. Give a name to the section (e.g. Prg) and choose a programming language (e.g. ST).

    assign name and language to section

  7. You can now start writing the PLC program using the programming language selected above. The next image shows an example of a program written in Structured Text.

    example program in stuctured text

  8. For FACTORY I/O to work together with Unity Pro you must assign memory values to internal variables. You do this by creating a new section called Inputs_FIO_Reading where values of memories %M0 up to %M16 are assigned to Sensor0 up to Sensor16 variables. You must do the same for actuator variables by creating an Outputs_FIO_Writing section and assigning the 13 actuators (%M17 up to %M29) and the Counter0 variable to an Int memory %MW. Note that Inputs_FIO_Reading should be placed first on the section tree so the latest sensor values are available when the program is executed. On the other hand, Outputs_FIO_Writing should be placed last, so actuator values are assigned to memories after the program is executed.

    binding sensors

    binding actuators

  9. Build the project by clicking on Build > Rebuild All Project.

    build the project

  10. Select Simulation Mode by clicking on PLC > Simulation Mode. Next, connect to the soft PLC by clicking on PLC > Connect and download the program by clicking on PLC > Transfer Project to PLC. Click on Transfer.

    transfer the program

  11. Now, switch the PLC to Run mode by clicking on PLC > Run. Click on OK.

    switch to run mode

    soft plc running

  12. You should select a scan time of 10ms by Right-clicking on the soft PLC icon (taskbar) and selecting Timing...

    change scan time

  13. Go back to FACTORY I/O, click on CONNECT and close the driver window (Esc).


  14. Finally, switch to Run mode and select Auto by clicking on the selector.