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 Wed Oct 23, 2019 11:16 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Import XML
PostPosted: Fri May 20, 2011 3:49 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Tue Jun 06, 2006 9:03 am
Posts: 410
I wanted to create a script which could import an XML file.
I first exported a GVL and wanted to import it, but I noticed it was placed in the POU pool.
With this example it places it "under" the application of the Device.

Create the .xml file, open a project with a device (PLC) and application and run the script.

Code:
# script example importXML.py

# current project
proj = projects.primary

# create the import reporter
class Reporter(ImportReporter):
    def error(self, message):
        system.write_message(Severity.Error, message)

    def warning(self, message):
        system.write_message(Severity.Warning, message)

    def resolve_conflict(self, obj):
        return ConflictResolve.Copy

    def added(self, obj):
        print("added: ", obj)

    def replaced(self, obj):
        print("replaced: ", obj)

    def skipped(self, obj):
        print("skipped: ", obj)
   
    @property
    def aborting(self):
        return False

# create the importer instance.
reporter = Reporter()   
 
# import xml

obj = proj.find("Application", True)
i = len(obj)
print("number of item Application: {0}".format(i))
if i > 0:
   obj[0].import_xml(reporter,r"C:\_d\Python\importXML\myXML.xml")
   print("add item")


Top
   
 Post subject: Re: Import XML
PostPosted: Wed Oct 19, 2011 8:12 am 
Offline

Joined: Tue Oct 04, 2011 9:21 am
Posts: 27
Hi TimvH,

I wrote a script, which imports a XML to CoDeSys. Than I saw here in the forum, that you had created a script for importing XML. You defined in your script a class "Reporter". Could you please explain the function of this class. Is it important to have this class in the script?

Thanks a lot.


Top
   
 Post subject: Re: Import XML
PostPosted: Wed Oct 19, 2011 8:29 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Tue Jun 06, 2006 9:03 am
Posts: 410
You can see that the import function uses the reporter class, therefore I added it.
The example is based on an example in the help and some addional help from 3S-Software.


Top
   
 Post subject: Re: Import XML
PostPosted: Wed Oct 19, 2011 8:31 am 
Offline
Frequent User
Frequent User
User avatar

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

The import and export process gives notifications about errors, warnings and progress. The purpose of the reporter is to process those notifications during the export or import process.

For native export, passing the reporters is optional. For PLCOpenXML, we're working on making them optional.

HTH,
Markus

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

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


Top
   
 Post subject: Re: Import XML
PostPosted: Tue Mar 20, 2012 10:22 am 
Offline

Joined: Wed Feb 22, 2012 2:29 pm
Posts: 7
I had exported some properties of a function block as XML-file using the menu function "Export PLCopen XML" and then wanted to import that with the function import_xml(). That worked fine, but all commentaries of the properties were not imported.

Example:

// P-0-0011 -READ- Last valid position command value <-- This was not imported !!!
PROPERTY P_0_0011 : DINT <-- This was imported !!!


Top
   
 Post subject: Re: Import XML
PostPosted: Tue Mar 20, 2012 10:53 am 
Offline
Frequent User
Frequent User
User avatar

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

Lohr_DCIA-EHE1 wrote:
I had exported some properties of a function block as XML-file using the menu function "Export PLCopen XML" and then wanted to import that with the function import_xml(). That worked fine, but all commentaries of the properties were not imported.

Example:

// P-0-0011 -READ- Last valid position command value <-- This was not imported !!!
PROPERTY P_0_0011 : DINT <-- This was imported !!!


Can check whether the comments are correctly imported when you do the import via the menu function?

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

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


Top
   
 Post subject: Re: Import XML
PostPosted: Tue Mar 20, 2012 11:15 am 
Offline

Joined: Wed Feb 22, 2012 2:29 pm
Posts: 7
The import of the commentaries of the properties via the menu function does not work either.

All commentaries above FUNCTION_BLOCK MX_DirectVarAxis are lost, too !!


// {attribute 'signature_flag' := '12345'} <-- lost
//{attribute 'hide'}//hide POU <-- lost
{attribute 'signature_flag' := '1275068416'} <-- lost
FUNCTION_BLOCK MX_DirectVarAxis <-- from here on everything is copied.
VAR
//{attribute 'hide'}//hide POU
{attribute 'noinit'}
usCmdAchse : UINT; // Achse fuer den Parameter-Zugriff
END_VAR


Top
   
 Post subject: Re: Import XML
PostPosted: Tue Mar 20, 2012 11:35 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Lohr_DCIA-EHE1 wrote:
The import of the commentaries of the properties via the menu function does not work either.

All commentaries above FUNCTION_BLOCK MX_DirectVarAxis are lost, too !!

// {attribute 'signature_flag' := '12345'} <-- lost
//{attribute 'hide'}//hide POU <-- lost
{attribute 'signature_flag' := '1275068416'} <-- lost
FUNCTION_BLOCK MX_DirectVarAxis <-- from here on everything is copied.
VAR
//{attribute 'hide'}//hide POU
{attribute 'noinit'}
usCmdAchse : UINT; // Achse fuer den Parameter-Zugriff
END_VAR


Then it's a general PLCOpenXML problem, and not specific to scripting. So I'm afraid I'm not in charge of it. :|

I think the best is that you file a bug report via our support department. Especially mention that the {attribute}s are lost, as that information is more important than "noarmal" comments.

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