CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Mon May 22, 2017 10:33 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Oct 19, 2016 6:06 pm 
Offline

Joined: Mon Jan 31, 2011 1:45 pm
Posts: 1
Hello team.

I need a script to insert a POU below of Application object.

I need too a script to edit a specific POU (MainPrg, for example), i.e., add new variables and modify code of POU.

Finally is necessary deletar a specific POU.

Thanks.
Émerson Butzen
Software Developer
Unisinos/Altus


Top
   
PostPosted: Thu Oct 20, 2016 8:20 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 192
Hi butzen.

butzen wrote:
I need a script to insert a POU below of Application object.

The Scripting API was extended with the necessary features with CODESYS V3.5 SP9. Look for IScriptIecLanguageObjectContainer and IScriptIecLanguageMemberContainer in the Scripting documentation.

butzen wrote:
I need too a script to edit a specific POU (MainPrg, for example), i.e., add new variables and modify code of POU.

We can only edit Structure Text directly. For the graphical languages you have to import the POU from PLCopenXML or our native format. See IScriptTextualObjectMarker, IScriptObjectWithTextualDeclaration, IScriptObjectWithTextualImplementation and IScriptTextDocument for the textual language and the methods import_xml() and import_native() from IScriptObject2 and IScriptProject2 for the import.

butzen wrote:
Finally is necessary deletar a specific POU.

Find the Scripting object, for example with find(), and use the method remove() to delete the object.

Here some example:
Code:
proj = projects.primary

found = proj.find("Application", True)
app = found[0]

# Create FB
mypou = app.create_pou("MyPou")

# Change declaration of the FB
implementation = mypou.textual_declaration.replace("""FUNCTION_BLOCK MyPou
VAR_INPUT
   iValue : INT;
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR""")

# Change implementation of the FB
mypou.textual_implementation.replace("""iValue := iValue + 1;""")

# Add method to FB
dosomething = mypou.create_method("DoSomething", "INT")

# Change declaration of the method
dosomething.textual_declaration.replace("""METHOD DoSomething : INT
VAR_INPUT
   iVal1 : INT;
   iVal2 : INT;
END_VAR""")

# Change implementation of the method
dosomething.textual_implementation.replace("""DoSomething := iVal1 + iVal2;""")

# Find the pou and delete it
found = app.find("MyPou")
if found and len(found) == 1:
   found[0].remove()
else:
   print("POU 'MyPou' was not found"

BR
Martin

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