CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Thu Oct 19, 2017 7:19 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Mar 14, 2017 1:26 pm 
Offline

Joined: Thu Jan 26, 2017 3:04 pm
Posts: 5
Hello,

I have a project with two applications which are not at the same level in project tree.

How can I manage connexion in each of these two applications independently in Python script ?
Can I connect and force variables on both applications or do I need to use something like the command menu "define active application" ?
Can I set the active application using python script ? Which is the method to use ?
Thank you


Top
   
PostPosted: Tue Mar 14, 2017 2:46 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 217
Hi Nicolas233.

Nicolas233 wrote:
How can I manage connexion in each of these two applications independently in Python script ?
Can I connect and force variables on both applications or do I need to use something like the command menu "define active application" ?
Can I set the active application using python script ? Which is the method to use ?

The operations for connecting to an application and reading/forcing variables from it are part of the online application object which you get by using online.create_online_application(). You can call the method with the GUID of the application object or the application object itself to get the online application object for the specified application. See the attached python script.

If you want the online application object for the active application or if your project only contains one application you can call the method without a parameter.

BR
Martin


You do not have the required permissions to view the files attached to this post.

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

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


Top
   
PostPosted: Wed Mar 15, 2017 1:52 pm 
Offline

Joined: Thu Jan 26, 2017 3:04 pm
Posts: 5
Hi Martin,

Thank you for this example.It's helpful.
However, my script encounters an error when i use such scheme.
The error message is :
Quote:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


It seems to happen on the following lines :
Code:
app = found[0]


Do you know where i can found inputs and outputs définitions for methods such as proj.find or projects.primary ? I don't find any description and, or examples in Script Engine API reference and in Python documentation. Where should I search ?

I think the line :
Code:
found = proj.find("Device", "PLC Logic", "Application")
is used to get the application GUID, isn't it ?

How can i get GUID of an application from the application name in the Codesys project tree ?

Thank you


Top
   
PostPosted: Wed Mar 15, 2017 2:34 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 217
Hi Nicolas233.
Nicolas233 wrote:
However, my script encounters an error when i use such scheme.
The error message is :
Quote:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


It seems to happen on the following lines :
Code:
app = found[0]

If found[0] creates that error than you didn't find any objects with the specified name or the specified path (array of names). I used this variant of the method find(...) so I can specify the complete path of the object.

Nicolas233 wrote:
Do you know where i can found inputs and outputs définitions for methods such as proj.find or projects.primary ? I don't find any description and, or examples in Script Engine API reference and in Python documentation. Where should I search ?

The documentation of the Scripting API is in the file "ScriptEngine.chm" which is in the sub directory "Online Help" of the CODESYS directory. With CODESYS V3.5 SP11 we will add an introduction to the ScriptEngine/Scripting to our Online Help.

Nicolas233 wrote:
I think the line :
Code:
found = proj.find("Device", "PLC Logic", "Application")
is used to get the application GUID, isn't it ?

No, it is used to specify the complete path of an object. If you used proj.find("Application", True) and you have more than object with the name "Application" you get an array with more than one entry.

Nicolas233 wrote:
How can i get GUID of an application from the application name in the Codesys project tree ?

All script object of the project tree have a property guid which return the GUID of the object. But you don't need the GUID of the appliction to use online.create_online_application(...) because you can also use the script object of the application to get the corresponding online application object.

BR
Martin

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

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


Top
   
PostPosted: Wed Mar 29, 2017 12:28 pm 
Offline

Joined: Thu Jan 26, 2017 3:04 pm
Posts: 5
Thank you for these explanations. It helps me to correct my script.


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 2 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