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 Sun Nov 17, 2019 11:21 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Mon Mar 14, 2016 8:31 am 
Offline

Joined: Tue Jul 28, 2015 9:08 am
Posts: 12
Hi,

I would like to know if it is possible to modify a GVL constant variable via a python script?
If true how can I achieve this?
If false what should I use?

In the meantime, is there a list of all available global variables in python like projects, online... ?

Regards


Top
   
PostPosted: Mon Mar 14, 2016 9:30 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 254
Hi dam.
dam wrote:
I would like to know if it is possible to modify a GVL constant variable via a python script?

You have to find the GVL object, which contains the variable(s) you want to change, and then you can either export, edit the XML and re-import the object or you can use the interface IScriptTextDocument to modify the structured text (ST) of the declaration directly.

The interface IScriptTextDocument is documented in the CHM of the ScriptEngine, which you can find the OnlineHelp directory in the CODESYS base directory. All object which containt an ST based declaration and/or implementation, support the interface IScriptTextualObjectMarker so you can check for it.

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: Mon Mar 14, 2016 9:51 am 
Offline

Joined: Tue Jul 28, 2015 9:08 am
Posts: 12
I tried to do:
Code:
...
gvl = project.find('GVL', True)[0]
print(gvl.has_textual_declaration())

but it failed as gvl is a ScriptObject.
Any hint?

Regards


Top
   
PostPosted: Mon Mar 14, 2016 11:03 am 
Offline

Joined: Tue Jul 28, 2015 9:08 am
Posts: 12
To add more informations if I do:
Code:
gvl.export_native("my_file", True)

I got all the values of GVL but:
Code:
gvl.get_children(True)

returns an empty list.

Regards


Top
   
PostPosted: Mon Mar 14, 2016 1:55 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 254
Hi dam.

From your second post in this thread:
Code:
print(gvl.has_textual_declaration())

Please remove the brackets after has_textual_declaration because it is a property and not a method. This property is only to check if the object has an ST based declaration. You get the text with the property text, e.g. gvl.text, and modify it with one of the methods, e.g. gvl.replace(modifiedDeclaration).

From your third post:
Code:
gvl.get_children(True)

With get_children(bool) you can only get the children of the object in the project structure. But variables are not children of the GVL object. You can only read or modify the ST based declaration.

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: Mon Mar 14, 2016 3:27 pm 
Offline

Joined: Tue Jul 28, 2015 9:08 am
Posts: 12
Indeed gvl.has_textual_declaration returns True but I do not have the text property.
I am using SoMachine 4.1 so maybe the version of Codesys is too old?

Regards


Top
   
PostPosted: Mon Mar 14, 2016 3:39 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 254
Hi dam

Sorry, my fault.

dam wrote:
Indeed gvl.has_textual_declaration returns True but I do not have the text property.

First you have to get the IScriptTextDocument object through the property textual_declaration (see interface IScriptObjectWithTextualDeclaration ) and than you can use text or replace() on that 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: Mon Mar 14, 2016 4:27 pm 
Offline

Joined: Tue Jul 28, 2015 9:08 am
Posts: 12
Thank you for the information and I confirm that it works with Codesys 3.5.7 but it does not work with SoMachine 4.1

dam wrote:
Indeed gvl.has_textual_declaration returns True but I do not have the text property.
I am using SoMachine 4.1 so maybe the version of Codesys is too old?

In fact, I was confused and I tested on Codesys 3.5.7 not on SoMachine 4.1. With SoMachine I do not have has_textual_declaration (it usesScriptEngine v3.5.3).
Is it possible to update ScriptEngine to a newer version in SoMachine or use a different API?

Regards


Top
   
PostPosted: Mon Mar 14, 2016 4:59 pm 
Offline
Frequent User
Frequent User
User avatar

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

dam wrote:
Thank you for the information and I confirm that it works with Codesys 3.5.7 but it does not work with SoMachine 4.1

dam wrote:
Indeed gvl.has_textual_declaration returns True but I do not have the text property.
I am using SoMachine 4.1 so maybe the version of Codesys is too old?

In fact, I was confused and I tested on Codesys 3.5.7 not on SoMachine 4.1. With SoMachine I do not have has_textual_declaration (it usesScriptEngine v3.5.3).
Is it possible to update ScriptEngine to a newer version in SoMachine or use a different API?

Regards


Updating the ScriptEngine to a newer version cannot be done by a SoMachine enduser, this must be done by Schneider Electric.

As far as I remember, Schneider also added some of their own extensions to the ScriptEngine, but I'm not sure whether that was for SoMachine or SoMachine Motion, and which version. I guess you need to ask the Schneider Support contact...

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

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


Top
   
PostPosted: Mon Mar 14, 2016 5:08 pm 
Offline

Joined: Tue Jul 28, 2015 9:08 am
Posts: 12
Ok thank you M.Schaber and M.Keller.

Regards


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 10 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