Redirect Codesys compiler output

DBe
2016-11-17
2016-12-07
  • DBe - 2016-11-17

    Hello,

    I would like to set up an automated software build system on a scripting base.
    Therefore I start a batch file containing the "codesys --runscript" commands for a python script to compile a codesys project with the option --enablescripttracing.
    This works fine, but the trace output is not redirected into a file completely.
    On cmd prompt the batch file output ist redirected via "build.bat >> log1.dat" - ok
    Within build.bat the python "print()" script commands are redirected via "> log2.dat Codesys --runscript ..." - ok
    But the codesys compiler messages are displayed within cmd prompt

    How can I redirect the messages that come out of codesys during e.g. the python command "app.create_boot_application(bootapppath)" ?

    Best regards
    Dirk

     
  • mkeller - 2016-11-17

    Hi DBe.

    DBe hat geschrieben:
    How can I redirect the messages that come out of codesys during e.g. the python command "app.create_boot_application(bootapppath)" ?

    Here some example code:

    CompileCategory = Guid("{97F48D64-A2A3-4856-B640-75C046E37EA9}")
    found = projects.primary.find("Application", True)
    app = found[0]
    \# Clear messages from Build category
    system.clear_messages(CompileCategory)
    app.create_boot_application(r"C:\Temp\App.app")
    \# Get message objects which contain all the data
    severities = {
       Severity.FatalError : "Fatal error", Severity.Error : "Error",
       Severity.Warning : "Warning", Severity.Information : "Information",
       Severity.Text : "Text"
       }
    msgs = system.get_message_objects(CompileCategory)
    for msg in msgs:
       sev = severities[msg.severity]
       print("{} {}{}: {}".format(sev, msg.prefix, msg.number, msg.text))
    \# Or: Get only the message text
    msgs = system.get_messages(CompileCategory)
    for msg in msgs:
       print(msg)
    

    BR
    Martin

     
  • DBe - 2016-11-18

    Hi Martin,

    thank you very much! The compile information is printed within cmd prompt AND log file now .
    During project creation I do a SVN checkout (via codesys addon). These reports are printed within cmd prompt only.
    Is there another GUID available for this too?

    BR
    Dirk

     
  • mkeller - 2016-11-18

    Hi DBe.

    DBe hat geschrieben:
    Is there another GUID available for this too?

    Use the following code to get a list of all available message categories:

    guids = system.get_message_categories(False)
    for guid in guids:
       print("GUID: {} Description: {}".format(guid, system.get_message_category_description(guid)))
    

    If you replace "False" with "True" in "get_message_categories()" you only get the active message categories.

    BR
    Martin

     
  • DBe - 2016-11-18

    Hi Martin,

    works fine - thank you!
    Only one small remark:
    "HMI Meldungen" has no constructor? Therefore you algo fails.
    But a try-catch filters this.

    BR
    Dirk

     
  • mkeller - 2016-11-21

    Hi DBe.

    DBe hat geschrieben:
    "HMI Meldungen" has no constructor? Therefore you algo fails.

    Which version of CODESYS do you use when this error happened?

    BR
    Martin

     
  • DBe - 2016-12-06

    Hi Martin,

    I use Codesys 3.5 SP5 Patch 7 with a build profile 3.5 SP3.
    Using these commands:

    for guid in guids:
    print("GUID: {} Description: {}".format(guid, system.get_message_category_description(guid)))
    

    I get these errors:

    Skript Meldungen: Information: Build.py(23): Ausnahmefehler (<type 'exceptions.A
    ttributeError'>, AttributeError(u'F\xfcr dieses Objekt wurde kein parameterloser
     Konstruktor definiert.',), <traceback object at 0x000000000000002B>)
    Skript Meldungen: Information: Build.py(23):       print("GUID: {} Description:
    {}".format(guid, system.get_message_category_description(guid)))
    Skript Meldungen: Information: Build.py(23): Ausnahmefehler (<type 'exceptions.A
    ttributeError'>, AttributeError(u'F\xfcr dieses Objekt wurde kein parameterloser
     Konstruktor definiert.',), <traceback object at 0x000000000000002C>)
    

    Kind regards
    Dirk

     
  • mkeller - 2016-12-07

    Hi Dirk.

    DBe hat geschrieben:
    I use Codesys 3.5 SP5 Patch 7 with a build profile 3.5 SP3.

    The problem is not the HMI category. It's only the last working category before the error.

    I tried it with two newer versions. With CODESYS V3.5 SP6 the problem still exists. With CODESYS V3.5 SP7 there is no error.

    BR
    Martin

     

Log in to post a comment.