SP8 - New scriptengine feature - open:VersionUpdateFlags

etamgul
2016-04-20
2023-11-24
  • etamgul - 2016-04-20

    I found some interesting new features with SP8, example the title mentioned flags among the arguments of the open.
    Though it looks well documented, I'm not sure if it is working.

    I have tried the followings and (opening and saving, closing the project) with the below examples, none of them worked for me. (means after reaopening the project with the GUI, it asked me to update for compiler version and showed my old settings -> no update actually happened)
    Any idea why?

        proj = projects.open(proj_path, update_flags = (VersionUpdateFlags.SilentMode | VersionUpdateFlags.UpdateAll));
    
        proj = projects.open(proj_path, update_flags = (VersionUpdateFlags.SilentMode | VersionUpdateFlags.UpdateAll | VersionUpdateFlags.UpdateCompiler | VersionUpdateFlags.UpdateDevices));
    
        proj = projects.open(proj_path,
                             encryption_password = None,
                             session_user = None,
                             session_password = None,
                             primary = True,
                             update_flags = (VersionUpdateFlags.SilentMode | VersionUpdateFlags.UpdateAll | VersionUpdateFlags.UpdateCompiler | VersionUpdateFlags.UpdateDevices));
    

    Thanks

     
  • Anonymous - 2016-04-20

    Originally created by: M.Schaber

    Hi, etamgul,

    etamgul hat geschrieben:
    I found some interesting new features with SP8, example the title mentioned flags among the arguments of the open.
    Though it looks well documented, I'm not sure if it is working.
    I have tried the followings and (opening and saving, closing the project) with the below examples, none of them worked for me. (means after reaopening the project with the GUI, it asked me to update for compiler version and showed my old settings -> no update actually happened)
    Any idea why?
    [...]

    One guess: Your script loads and then directly saves the project. However, the "Update Environment" mechanism only kicks in when CODESYS gets idle after the project is loaded.

    I guess artificially raising the idle event by calling the .NET API System.Windows.Forms.Application.RaiseIdle() could fix the problem.

     
  • etamgul - 2016-04-21

    Thanks, could you give me an example how to do that?
    Also how to wait till the process finishes? (is there a feedback or delay with <random> s?)</random>

     
  • Anonymous - 2016-04-21

    Originally created by: M.Schaber

    Hi,

    At the beginning of the script:

    import System
    

    Then, later, after loading the project (but before saving it)

    System.Windows.Forms.Application.RaiseIdle(System.EventArgs.Empty)
    

    If that does not work, try the following instead:

    for i in range(10):
        System.Windows.Forms.Application.DoEvents()
        System.Windows.Forms.Application.RaiseIdle(System.EventArgs.Empty)
    

    Please tell us whether it works or not. If it works, we'll include a similar code in the ScriptEngine eventually. If it doesn't work, I'll file a bug report so we can investigate the problem and provide a bug fix.

     
  • etamgul - 2016-04-21

    Are you sure that we are still talking about codesys scriptengine?

    I have tried to execute the suggested codepieces but Codesys throws me an exception

    'namespace#' object attribute 'Forms' is read-only
    

    Has anybody ever tried testing this or is there something I missed in codesys setup?

     
  • Anonymous - 2016-04-21

    Originally created by: M.Schaber

    Hi, etamgul,

    etamgul hat geschrieben:
    Are you sure that we are still talking about codesys scriptengine?

    Yes, as the CODESYS ScriptEngine allows access to most .NET Framework APIs.

    etamgul hat geschrieben:
    I have tried to execute the suggested codepieces but Codesys throws me an exception

    'namespace#' object attribute 'Forms' is read-only
    

    Has anybody ever tried testing this or is there something I missed in codesys setup?

    It was a mistake in my example code (I simplified to much during copy-paste). The import line needs to be replaced with:

    import System, clr
    clr.AddReference("System.Windows.Forms")
    

    Sorry for the trouble...

     
  • etamgul - 2016-04-21

    I only tried to import the 'System' based on some quick google search.

    Unfortunately none of the above examples work (they get executed though, it just seem that the compiler update does not happen).

     
  • etamgul - 2016-04-22

    Does this work on your side?

     
  • etamgul - 2016-04-22

    Okay I gave up experimenting with the RaiseIdle:
    But you gave me an idea (I basically only wanted to update the projects when the compiler or any other version changes).

    So instead of trying to raise the event that executes the update I used the SendKey .net method to navigate and do 'semi-manually' the keystrokes..

    This one works on my side, though it will not necessarly work every time (depends how fast the IDE processes the sent keys):

        # navigate to "Set all to newest" button
        System.Windows.Forms.SendKeys.Send("{TAB}");
        System.Windows.Forms.SendKeys.Send("{TAB}");
        System.Windows.Forms.SendKeys.Send("{TAB}");
        # Hit and confirm
        System.Windows.Forms.SendKeys.Send("{ENTER}");
        System.Windows.Forms.SendKeys.Send("{ENTER}");
        # Navigate to OK
        System.Windows.Forms.SendKeys.Send("{TAB}");
        # confirm
        System.Windows.Forms.SendKeys.Send("{ENTER}");
         
        # raise a project update window
        system.commands[("project", "checkavailableversions")].execute();
    

    Would be cool to access the buttons with some guid or other method, the problem is that execute() is a blocking call.. so workarounds for workaround.

     
  • Anonymous - 2016-04-22

    Originally created by: M.Schaber

    Hi, etamgul,

    etamgul hat geschrieben:
    Does this work on your side?

    The second script worked for me on a small toy project, but it failed on a bigger project.

    My mistake was to believe that the version compatibility manager kicks in on the Application.Idle() event. While this is true, it only happens after both the project background loading and the loading of all libraries is finished, and this needs more time (more Idle() events) for bigger projects.

    Currently, there's no direct way to force this to happen.

    As a workaround, using clean_all() or check_all_pool_objects() on the project, or a build on the application should also trigger those events, so issuing one of them followed by a few rounds of DoEvents() and RaiseIdle() should update the project.

    I filed the bug report CDS-48995

    HTH,
    Markus

     
  • etamgul - 2017-04-05

    Could you please re-check if it is working or not?

    Link is not available to the public and this issue was reported with SP8,
    now I checked it with SP10 and none of the above examples are working.

    Update: jira is running now, issue is still not addressed (Bug is in OPEN, Fix Version/s: Not Planned). Good to see.

     
  • Anonymous - 2017-04-05

    Originally created by: M.Schaber

    Hi, Etamgul,

    Sorry that the issue is not fixed yet. As there's a workaround, it was priorized rather low, so higher priority issues were fixed first.

    I triggered our product management to boost the priority a little bit, so the issue will now most likely be fixed with one of the next service packs. (It's already too late for the upcoming V3.5 SP11, which is already fully planned, but there's rather good chances for SP12.)

    Regards,
    M.Schaber

     
  • srigan1986 - 2023-11-24

    Is this issue of idling before loading libraries resolved in Codesys 3.5.18.40 ?

     
  • srigan1986 - 2023-11-24

    Is this issue of idling before loading libraries resolved in Codesys 3.5.18.40 ? I am also curious about this version as there seem to be huge difference in the compiler versions which don't recognize the versions with older storage format.

     

    Last edit: srigan1986 2023-11-24

Log in to post a comment.