CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Mon Dec 09, 2019 10:44 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Dec 12, 2012 1:29 pm 
Offline

Joined: Wed Oct 24, 2012 9:57 am
Posts: 3
I have one given project, which keeps 3 applications for 3 different plc-types. ( I have no influence to this project structure, so I can not change it)

For downloading them by script I am guessing I have to change the active application. How can I get to the application to set active?
Or how can I change the active application at all?


Top
   
PostPosted: Wed Dec 12, 2012 2:08 pm 
Offline
Frequent User
Frequent User
User avatar

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

Projects have a property active_application, which you can use to query or set the active application.

Code:
proj = projects.primary

app = proj.find('Application', recursive = True)[0]

proj.active_application = app

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

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


Last edited by M.Schaber on Wed Dec 12, 2012 3:11 pm, edited 1 time in total.

Top
   
PostPosted: Wed Dec 12, 2012 2:54 pm 
Offline

Joined: Wed Oct 24, 2012 9:57 am
Posts: 3
Hi, thanks for this quick answer!
Unfortunatelly I found 3 appplication objects. The given project structure:

Project
-PLC_A
--SPS-Logik
---Application
-PLC_B
--SPS-Logik
---Application
-PLC_C
--SPS-Logik
---Application


Is there an easy way to detect the right application via parents property? Something like app.parent.parent ?
Code:
print( "findApplicationResult.Count ", findApplicationResult.Count) 
for far in findApplicationResult:
    appPlcFound = far.parent.parent.find( "PLC_A", False )
    print( "appPlcFound.Count ", appPlcFound.Count )
    if appPlcFound.Count > 0:
        print( "appPlcFound" )
        proj.active_application = appPlcFound[1]
        break

Does not work, appPlcFound.Count = 0 three times. I am also not so much into Python so I am just guessing and trying...


Top
   
PostPosted: Wed Dec 12, 2012 3:10 pm 
Offline
Frequent User
Frequent User
User avatar

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

There are several possibilities to solve your problem: The first one is to search from the device upwards:

Code:
proj = projects.primary

dev = proj.find('PLC_A')[0]

app = dev.find('Application', recursive = True)[0]

proj.active_application = app


The second one is to search the application by path:

Code:
proj = projects.primary

dev = proj.find('PLC_A', 'SPS-Logik', 'Application')[0]

proj.active_application = app


A third way is to check the name of the parent:

Code:
for far in findApplicationResult:
    if far.parent.parent.get_name() == 'PLC_A':
        # do something here...


In your code, the problem was the following line:
Quote:
Code:
     appPlcFound = far.parent.parent.find( "PLC_A", False )


Here, you're going down 2 steps from the application object (far.parent.parent points to the device in your project), and then you search for a child of that device with the name "PLC_A" non-recursively, which none exists.


Note that the find() methods always return a list of objects, because each search could return more than one result.

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 Dec 12, 2012 3:50 pm 
Offline

Joined: Wed Oct 24, 2012 9:57 am
Posts: 3
Thank you Markus!
Your first solution runs perfect.
Now the next problem is knocking on the door :shock: To create the gateway and set the device active.
But if I need help I'll open a new thread with a fitting topic.
Alfred


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

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


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