Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

collection value from codesys to visual studio 2015

  • adam8888

    adam8888 - 2020-03-02

    Hi guys,

    currently i have trying to collecting value from global variable from codesys.
    1st time i have tried create script python to reading value and execute from codesys, result is value able to read.
    2nd time i have tried create 1 application from C#.Net visual studio 2015, have error coming, error is like on below :

    script on python:ReadVariable.py

    from future import print_function;

    close open project if necessary:

    if projects.primary:

    opens project

    proj = projects.open(r"C:\Testing Integration\Untitled1.project")

    set "Ampel.project" to active application

    app = proj.active_application
    onlineapp = online.create_online_application(app)

    login to device

    onlineapp.login(OnlineChangeOption.Try, True)

    set status of application to "run", if not in "run"

    if not onlineapp.application_state == ApplicationState.run:

    wait 1 second

    def TagsCall(*Tags):
    value1 = onlineapp.read_value(Tags[0])
    value2 = onlineapp.read_value(Tags[1])
    value3 = onlineapp.read_value(Tags[2])


    log out from device and close "Ampel.project"

    script on Visual Studio 2015 :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;

    using IronPython.Hosting;
    using Microsoft.Scripting.Hosting;
    using IronPython.Modules;
    using IronPython.Runtime;
    using IronPython.Compiler;
    using IronPython.Zlib;
    using IronPython.SQLite;

    namespace Codesys_Adapter
    static class Program

    /// The main entry point for the application.
    /// </summary>
    static void Main(string[] args)
    var ipy = Python.CreateRuntime();
    dynamic test = ipy.UseFile(@"..\..\ReadVariable.py");
    can you help me to suggestion best practice or step by step document to integrated to Visual Studio 2015.



    Talk.ru: 1
    Talk.ru: 2

    • mkeller

      mkeller - 2020-03-03


      The python script you created will only work inside the CODESYS IDE or any other software which is based on the CODESYS Automation Platform because the modules used for accessing the IDE and the PLC are only available there.

      What is your use case for running the python script inside your own C# application?


      • adam8888

        adam8888 - 2020-03-09

        Hi Mkeller,

        yes, i just calling the py script from C#.Net.

        • mkeller

          mkeller - 2020-03-10

          Hi adam8888.

          As I said before you can use our Scripting API only inside the CODESYS IDE or any other software which is based on the CODESYS Automation Platform.

          So again, what is your use case for running the python script inside your own C# application?


  • i-campbell

    i-campbell - 2020-03-04

    PLC handler would be the default works with all CODESYS communication API. Details at Link

    OPC UA is available in many runtimes, so I would find a C# OPC UA client if your controller supports this. Eg Link 2

    Also, you can use one of the fieldbusses that your controller supports, and find a corresponding library for C#.

    Alternatively, there are some communication libraries that may be appropriate for your use cases. Net Based Services library can send some TCP or UDP packets, you can also purchase the MQTT library for CODESYS for a more IIoT approach, and find an MQTT library for C#, and find an MQTT broker.

    My answer is quite generic, but if you answer Martin, you may get a more tailored response from him.


    Last edit: i-campbell 2020-03-04

Log in to post a comment.