Hi all,
I need to get the name of the variables from the GVL of my application in order to perform some check on the names. How can I get these informations?
Should I read the entire GVL file and parse the text line by line? In that case how can I do it?
I'm totally new in this field (execute Python script in Codesys) and I don't know which functions are available...do you have a guide or something similar?
Thank you very much,
Best regards.
Massimo
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Massimo.Milluzzo hat geschrieben:
I need to get the name of the variables from the GVL of my application in order to perform some check on the names. How can I get these informations?
Should I read the entire GVL file and parse the text line by line? In that case how can I do it?
You can export your GVL in PLCopenXML and look for the XML node "globalVars" which represents a GVL. You find the variables below that node.
Here some code for exporting a GVL as PLCopenXML:
classExportHandler(ExportReporter):Â Â
  deferror(self, object, message): Â
    system.write_message(Severity.Error, "Error exporting %s: %s"%(object, message))
  defwarning(self, object, message): Â
    system.write_message(Severity.Warning, "Warning exporting %s: %s"%(object, message))
  defnonexportable(self, object): Â
    system.write_message(Severity.Information, "Object not exportable: %s"%object)
  @property
  defaborting(self):
    returnFalse;
\#
\# Mainprogram
\#
proj=projects.primaryfound=proj.find('GVL', True)assert(found)gvl=found[0]
reporter=ExportHandler()print"exporting to string:"xmldata=gvl.export_xml(reporter)
\# orprint"exporting to file:"gvl.export_xml(reporter, r"c:\Temp\test_gvl.xml")print"script finished."
For the XML you can use one of the Python modules included in the standard library.
Massimo.Milluzzo hat geschrieben:
I'm totally new in this field (execute Python script in Codesys) and I don't know which functions are available...do you have a guide or something similar?
The documentation of the Scripting API is in the file "ScriptEngine.chm" which is in the sub directory "Online Help" of the CODESYS directory.
BR
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-01-16
Originally created by: Massimo.Milluzzo
Hi Martin,
Thank you very much for the reply, it is very useful
Best regards.
Massimo
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-01-30
Originally created by: Massimo.Milluzzo
Hi all,
I'm still in trouble with my project. I only recently tried to perform the operations you suggest but I always got an error (see attachments)
Here's my python code
classExportHandler(ExportReporter):Â Â
  deferror(self,object,message): Â
    system.write_message(Severity.Error,"Error exporting %s: %s"%(object,message))
  defwarning(self,object,message): Â
    system.write_message(Severity.Warning,"Warning exporting %s: %s"%(object,message))
  defnonexportable(self,object): Â
    system.write_message(Severity.Information,"Object not exportable: %s"%object)
  @property
  defaborting(self):
    returnFalse;
\#
\# Main program
\#proj=projects.primaryreporter=ExportHandler()importxml.etree.ElementTreeasETfound=proj.find('GVL',True)assert(found)gvl=found[0]
\#print "exporting GVL to string:"
\#xmldata = gvl.export_xml(reporter)print"exporting GVL to file:"gvl.export_xml(reporter,r"c:/temp/gvl.xml")print"Parse the file:"tree=ET.parse("c:/temp/gvl.xml")print"Get the root:"root=tree.getroot()print"Attribute: %s"%(root.attrib)
Every time I run the script I get an error on the parse function (see "XMLError.png"). I tried to modify the file "gvl.xml" removing the first line but the result is the same (see "XMLError2.png")
I checked the file with an XML validator and everything seems ok.
Do you have any suggestion?
Thank you in advance,
Regards.
Massimo
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-01-30
Originally created by: Massimo.Milluzzo
Update:
If I try to parse the following file with the same python code I have no problem.
<nodesatt="Root node">
  <node1att="First child">
    <node1Child1att="Attribute 1"></node1Child1>
    <node1Child2att="Attribute 2"></node1Child2>
    <node1Child3att="Attribute 3"></node1Child3>
  </node1>
  <node1att="Second child">
    <node1Child4att="Attribute 4"></node1Child4>
    <node1Child5att="Attribute 5"></node1Child5>
    <node1Child6att="Attribute 6"></node1Child6>
  </node1>
  <node2att="Third child">
    <node2Child1att="Attribute 1"></node2Child1>
    <node2Child2att="Attribute 2"></node2Child2>
    <node2Child3att="Attribute 3"></node2Child3>
  </node2></nodes>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-01-30
Originally created by: Massimo.Milluzzo
Another update.
It seems the problem lies in the "export_xml" function or in the "reporter" object. I cannot parse either any file or string created by the function. If I try to parse either a file or a string created manually I have no problems.
Furthermore I can parse the xml generated by the "export_xml" function if I create a new file and paste the code in it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Massimo.Milluzzo hat geschrieben:
Another update.
It seems the problem lies in the "export_xml" function or in the "reporter" object. I cannot parse either any file or string created by the function. If I try to parse either a file or a string created manually I have no problems.
Furthermore I can parse the xml generated by the "export_xml" function if I create a new file and paste the code in it.
The problem is the BOM (Byte Order Mark) which the XML writer of .Net automatically adds when writing XML files. You have to remove or skip it before parsing the XML content of the file. Or you can use .Net API which automatically skips the BOM when reading XML files if you run your python script in CODESYS Scripting and IronPython v2.7.x.
I used this workaround when I had to parse a PLCopenXML file generated by CODESYS:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-01-31
Originally created by: Massimo.Milluzzo
Hi Martin,
Thank you very much, I had no clue about that problem. Now I can read and parse the XML.
I will write soon for another problem
Regards,
Massimo
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-02-07
Originally created by: Massimo.Milluzzo
Hi all,
here I'm again. How can I export a visualization page? When I try I get the error:
[INFORMATION]Â Â Objectnotexportable:ScriptObject{NoDeviceObject,NoExplicitConnectorObject,NoSymbolConfigObject,NoLibManObject,ScriptNoProjectInfoMarker,NoScriptApplicationObject,ScriptNonTextualObject,NoTaskConfigObject,NoTaskObject,NoImagePoolObject,NoScriptApplicationComposerObject,NoScriptApplicationComposerObject}(Project=79,Name=VisualizationExportTest,guid=9c501cb8-67a5-4bd8-9172-f67c77d0a324)
Thank you in advance,
Regards.
Massimo
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Massimo.Milluzzo hat geschrieben:
How can I export a visualization page? When I try I get the error:
No PLCopenXML export for Visualization objecs. You can use the native export but the XML format is not documented.
You can call the method from a common object which allows to export the object and its children or you can call it from a project which allows you to provide a list of objects which you want to export.
BR
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-02-08
Originally created by: Massimo.Milluzzo
Thank you very much.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Originally created by: Massimo.Milluzzo
Hi all,
I need to get the name of the variables from the GVL of my application in order to perform some check on the names. How can I get these informations?
Should I read the entire GVL file and parse the text line by line? In that case how can I do it?
I'm totally new in this field (execute Python script in Codesys) and I don't know which functions are available...do you have a guide or something similar?
Thank you very much,
Best regards.
Massimo
Hi Massimo.
You can export your GVL in PLCopenXML and look for the XML node "globalVars" which represents a GVL. You find the variables below that node.
Here some code for exporting a GVL as PLCopenXML:
For the XML you can use one of the Python modules included in the standard library.
The documentation of the Scripting API is in the file "ScriptEngine.chm" which is in the sub directory "Online Help" of the CODESYS directory.
BR
Martin
Originally created by: Massimo.Milluzzo
Hi Martin,
Thank you very much for the reply, it is very useful
Best regards.
Massimo
Originally created by: Massimo.Milluzzo
Hi all,
I'm still in trouble with my project. I only recently tried to perform the operations you suggest but I always got an error (see attachments)
Here's my python code
Every time I run the script I get an error on the parse function (see "XMLError.png"). I tried to modify the file "gvl.xml" removing the first line but the result is the same (see "XMLError2.png")
I checked the file with an XML validator and everything seems ok.
Do you have any suggestion?
Thank you in advance,
Regards.
Massimo
Originally created by: Massimo.Milluzzo
Update:
If I try to parse the following file with the same python code I have no problem.
Originally created by: Massimo.Milluzzo
Another update.
It seems the problem lies in the "export_xml" function or in the "reporter" object. I cannot parse either any file or string created by the function. If I try to parse either a file or a string created manually I have no problems.
Furthermore I can parse the xml generated by the "export_xml" function if I create a new file and paste the code in it.
Hi Massimo.
The problem is the BOM (Byte Order Mark) which the XML writer of .Net automatically adds when writing XML files. You have to remove or skip it before parsing the XML content of the file. Or you can use .Net API which automatically skips the BOM when reading XML files if you run your python script in CODESYS Scripting and IronPython v2.7.x.
I used this workaround when I had to parse a PLCopenXML file generated by CODESYS:
BR
Martin
Originally created by: Massimo.Milluzzo
Hi Martin,
Thank you very much, I had no clue about that problem. Now I can read and parse the XML.
I will write soon for another problem
Regards,
Massimo
Originally created by: Massimo.Milluzzo
Hi all,
here I'm again. How can I export a visualization page? When I try I get the error:
Thank you in advance,
Regards.
Massimo
Hi Massimo.
No PLCopenXML export for Visualization objecs. You can use the native export but the XML format is not documented.
You can call the method from a common object which allows to export the object and its children or you can call it from a project which allows you to provide a list of objects which you want to export.
BR
Martin
Originally created by: Massimo.Milluzzo
Thank you very much.