Get Codesys profile via batch

P-Groebner
2017-09-20
2017-09-21
  • P-Groebner - 2017-09-20

    Hello,

    I am trying to start CoDeSys with a batch file like this and execute a python script afterwards:

    start "" CoDeSys.exe --profile="CODESYS V3.5 SP10 Patch 4" --enablescripttracing --runscript=%PYTHON_PATH% --scriptargs=%XML_PATH%
    

    This works well so far but I need to pass the --profile argument more generic. So is there a way to read the installed CoDeSys profile from the used computer in a batch script?
    If not...is it possible to do some hack? I saw a folder called "Profiles" in the Codesys installation folder. Maybe I could scan the file names there to get the latest installed profile.

    Greetings

     
  • mkeller - 2017-09-21

    Hi P_Groebner.

    P_Groebner hat geschrieben:
    So is there a way to read the installed CoDeSys profile from the used computer in a batch script?

    You can find the profile name inside the content of .

    Here some example code:

    from __future__ import print_function
    import sys
    print("--- sys.version")
    print(sys.version)
    

    Output from CODESYS V3.5 SP11:

    --- sys.version
    2.7.7 (CODESYS.exe CODESYS V3.5 SP11, ScriptEngine.plugin 3.5.11.0)
    

    I think the best way to get the profile name is to match the executable name, which you can get from , and the plug-in name 'ScriptEngine.plugin' with the leading comma and extract what is between them.

    BR
    Martin

     
  • P-Groebner - 2017-09-21

    Hi M.Keller and thank you for your answer.

    okay I may not have expressed myself very well, sorry. I need to read the profile before I start CoDeSys and execute my python script. I need to read it in my batch file (outside of the CoDeSys IDE), where I start CoDeSys, so that I can do something like:

    start "" CoDeSys.exe --profile=%CODESYS_PROFILE% --enablescripttracing --runscript=%PYTHON_PATH%
    

    What I did now is to scan the Profiles folder (Default path: C:\Program Files (x86)\3S CODESYS\CODESYS\Profiles) and list all file names with a *profile extension. Afterwards I can choose the profile I want and store it in a variable. The batch script code looks like follows(you should be able to execute it, if CoDeSys is installed in the specified directory):

    @echo off
    cd C:\Program Files (x86)\3S CODESYS\CODESYS\Profiles
    echo List all installed CoDeSys profiles:
    setlocal enableextensions enabledelayedexpansion
    set /a count = 0
    for %%f in (*.profile) do  (
       set /a count += 1
       echo !count!: %%~nf
    )
    endlocal
    rem Choose profile
    echo(
    SET /p PROFILE_NUMB=Choose the profile you want to use by entering a number: 
    rem Get profile
    setlocal enableextensions enabledelayedexpansion
    set /a count = 0
    for %%f in (*.profile) do  (
       set /a count += 1
       if !count!==%PROFILE_NUMB% (
          SET CODESYSPROFILE=%%~nf
          goto commonExit
       )
    )
    endlocal
    :commonExit
    echo %CODESYSPROFILE%
    pause
    exit
    

    Can you give me a short feedback on this solution? I guess it is not guaranteed, that it will work in the future. Iam also grateful for further suggestions on how to solve this.

     

Log in to post a comment.