r2k-in-the-vortex
OpenPLC editor doesn't explicitly offer importing/exporting POU-s, but there is copy paste functionality. Once you have copied a POU nobody is dictating you must paste it into another instance of OpenPLC editor, you can just as well paste it to whatever text editor and then you get something like below. Which you can edit or do whatever and later import via same copy paste functionality.

<pou name="IO_Sample" pouType="program">
  <interface>
    <inputVars>
      <variable name="in">
        <type>
          <DINT/>
        </type>
      </variable>
    </inputVars>
    <outputVars>
      <variable name="out">
        <type>
          <DINT/>
        </type>
      </variable>
    </outputVars>
  </interface>
  <body>
    <ST>
      <xhtml:p><![CDATA[out := in;
]]></xhtml:p>
    </ST>
  </body>
  <documentation>
    <xhtml:p><![CDATA[do nothing]]></xhtml:p>
  </documentation>
</pou>



But it's only a element of xml doc and when you try to parse it there is a difficulty with that xhtml: p tag because the namespaces are undefined. That can be remedied by copying the doc root from project file and wrapping it around this pasted code, then you have a complete and parseable xml doc. Of course it would be mighty nice if OpenPLC editor already did it itself and saved all the separate pous as separate files, in a folder structure under project..... Even better if at least for ST the xml monstrosity could be escaped from and the code could be just plaintext ST. Editor can certainly extract ST from that xml, I don't know if it can do it the other way - build editor suitable xml structure from plaintext ST, probably that feature does not yet exist. For etch a sketch languages of course it can't be that easy, but for ST it should be possible to implement.

<?xml version='1.0' encoding='utf-8'?>
<project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.plcopen.org/xml/tc6_0201">
{copied_data_goes_here}
</project>
Reply 1 0
dmirandax
@r2k-in-the-vortex

I'm using OpenPLC v4 and I need to import some .xml project files to run them.
First, I noticed that the plc.xml file does not appear in the project folder until I compile a blank project.
After that, I edit the OpenPLC code using an external tool and paste the modified code into the plc.xml file. Then, I reopen the project.
However, the changes are not applied.
Am I missing any steps? Is there anything else I should do to make OpenPLC recognize the updated plc.xml file?


Reply 0 0
thiagoralves
OpenPLC v4 does not import from PLCopen XML files. Modifying these files in your project folder won’t do anything. They are just artifacts of the compilation process.
Reply 1 0
dmirandax
OpenPLC v4 does not import from PLCopen XML files. Modifying these files in your project folder won’t do anything. They are just artifacts of the compilation process.
@thiagoralves thank you for your response.
I understand that OpenPLC v4 does not support direct import of PLCopen XML files. However, I would still like to simulate or test logic defined in this format.
Do you have any recommended approach to achieve this using OpenPLC? Is there any tools/workflows you would suggest to convert or adapt PLCopen XML projects for use in OpenPLC?
Any guidance on how to proceed with simulation would be greatly appreciated.
Thank you in advance.
Reply 0 0
thiagoralves
If what you want to import are text-based languages (like Structured Text or Instruction List) then you can simply copy/paste the code. Otherwise you’re out of luck. There is no importer for graphical languages for OpenPLC v4. We might bring that at some time if the community thinks it is valuable
Reply 0 0
Reply