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

Setting up the "Visual Studio Code" debugging environment (using .NET debugging) for use with the ScriptEngine API in Python.

jantje
2020-10-20
2023-09-12
  • jantje - 2020-10-20

    Dear reader,

    My goal is to speed up and automate some processes like importing code and alarm texts in an alarm group. To this end, I want to use the ScriptEngine API in Python and preferably not even open the CODESYS application. Now, to streamline the programming we need the debugging capabilities and Visual Studio Code sounded like the easy way to go (Although I am new to it).

    Now after some attempts I feel that I am stuck and need a clear guideline of how to set up the environment, I believe a manual does does not exist for CODESYS, am I right?

    Install Procedure


    Here is the procedure up to where I am now:
    (the numbering in brackets refers to the image.)

    1. Install programs as described in the Visual Studio Code (VS Code), "Hallo World" example.
      This gives you VS Code, some python distribution (mine is Anaconda) and a sense of what configurations can be done and how (e.g. settings.json and launch.json).
    2. Install the extension in VS Code (below (1)): Python (Python extension for Visual Studio Code)
      This should allow for remote debugging.
    3. Open and configure the launch.json file (as described in the 'Hallo World' link) for its debug configurations.
      (ps1: open launch.json by pressing the gear Icon above (2).)
      (ps2: note that the options in the debugger (1, 2) match the options in the launch.json (3).)

    Questions


    This is where I don't know how to proceed.
    1 - What preset should I start with in launch.json? (When I press "Add Configuration..." at the bottom right, I get among others:)
    -> Remote attach (Uses application Port number),
    -> Attach using Process ID.

    2 - Do I use "Attach" or "Lauch" as options in "request"?

    3 - Can I use the debug options when Codesys is already running, or do I need to launch it in a special way like:

    start /b /wait CODESYS.exe --profile="CoDeSys V3.5 SP10" --runscript="P:\halloworld\hello.py" --scriptdebugger {=".NET"}
    

    4 - Where do I run the actual python program when I want to debug?
    -> Using Codesys and run the script from there,
    -> Using VS Code and run the script from there,
    -> Always use the CMD line to launch Codesys AND the script.

    Thanks in advance for your time, let this topic be a help for anyone trying to setup the environment.

    Kind Regards,
    Jan

     
    πŸ‘
    3

    Last edit: jantje 2020-10-20
  • aguado - 2023-09-12

    Hi,

    did you ever get this to run?

    Best

    Till

     

    Last edit: aguado 2023-09-12

Log in to post a comment.