CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Fri Jun 23, 2017 4:30 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Wed Apr 20, 2016 1:31 pm 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
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?

Code:
    proj = projects.open(proj_path, update_flags = (VersionUpdateFlags.SilentMode | VersionUpdateFlags.UpdateAll));


Code:
    proj = projects.open(proj_path, update_flags = (VersionUpdateFlags.SilentMode | VersionUpdateFlags.UpdateAll | VersionUpdateFlags.UpdateCompiler | VersionUpdateFlags.UpdateDevices));


Code:
    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


Top
   
PostPosted: Wed Apr 20, 2016 2:47 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, etamgul,

etamgul wrote:
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.

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Apr 21, 2016 6:15 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
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?)


Top
   
PostPosted: Thu Apr 21, 2016 7:58 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

At the beginning of the script:
Code:
import System


Then, later, after loading the project (but before saving it)
Code:
System.Windows.Forms.Application.RaiseIdle(System.EventArgs.Empty)


If that does not work, try the following instead:
Code:
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.

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Apr 21, 2016 8:35 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
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
Code:
'namespace#' object attribute 'Forms' is read-only


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


Top
   
PostPosted: Thu Apr 21, 2016 9:51 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, etamgul,

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


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

etamgul wrote:
I have tried to execute the suggested codepieces but Codesys throws me an exception
Code:
'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:

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


Sorry for the trouble...

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Apr 21, 2016 11:35 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
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).


Top
   
PostPosted: Fri Apr 22, 2016 7:00 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
Does this work on your side?


Top
   
PostPosted: Fri Apr 22, 2016 8:32 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
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):

Code:
    # 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.


Top
   
PostPosted: Fri Apr 22, 2016 9:20 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, etamgul,

etamgul wrote:
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 so we will fix this functionality in the script engine, to make it work as expected.

HTH,
Markus

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Wed Apr 05, 2017 8:53 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
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.


Top
   
PostPosted: Wed Apr 05, 2017 4:12 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
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

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 12 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited