tests/canopen_master/plc.xml
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 10 Aug 2018 17:45:33 +0300
changeset 2278 a3ac46366b86
parent 436 c926a8037adc
child 2346 ac16bad593cf
permissions -rw-r--r--
Dirty fix for error '_object_has_no_attribute_'getSlave' in EtherCAT extension

traceback:
File "/home/developer/WorkData/PLC/beremiz/beremiz/IDEFrame.py", line 1433, in OnPouSelectedChanged
window.RefreshView()
File "/home/developer/WorkData/PLC/beremiz/beremiz/etherlab/ConfigEditor.py", line 837, in RefreshView
self.RefreshProcessVariables()
File "/home/developer/WorkData/PLC/beremiz/beremiz/etherlab/ConfigEditor.py", line 886, in RefreshProcessVariables
slaves = self.Controler.GetSlaves(**self.CurrentNodesFilter)
File "/home/developer/WorkData/PLC/beremiz/beremiz/etherlab/EthercatMaster.py", line 341, in GetSlaves
for slave in self.Config.getConfig().getSlave():
<type 'exceptions.AttributeError'>:_'lxml.etree._Element'_object_has_no_attribute_'getSlave'

Steps to reproduce problem:

- Add new EtherCAT master
- Add new EthercatNode to the master
- double click on


this is looks like dirty hack to fix strange problem with initial[0]
changing its type after returning from _init_ method to lxml.etree._Element
As a result all methods generated by class factory are lost.

For example, in function initMethod initial[0].__class__ points to
xmlclass.xmlclass.Config. After map(self.append, initial)
self.Config.__class__ is 'xmlclass.xmlclass.Config' as well.
But after returning from initMethod (_init) in CreateElement
self.Config.__class__ has changed to lxml.etree._Element.


I've noticed similar behavior if copy/deepcopy is used for any child
of etree.ElementBase. See simple example below.
[-------------------------------------------------------------]
#!/usr/bin/python

from __future__ import print_function
from lxml import etree
import copy

class DefaultElementClass(etree.ElementBase):
def getLocalTag(self):
return etree.QName(self.tag).localname


def printInformation(x):
print(x, x.__class__, "getLocalTag" in dir(x))


a = DefaultElementClass()
printInformation(a)

#
printInformation(copy.copy(a))
printInformation(copy.deepcopy(a))
[-------------------------------------------------------------]
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://www.plcopen.org/xml/tc6.xsd"
         xmlns:xhtml="http://www.w3.org/1999/xhtml"
         xsi:schemaLocation="http://www.plcopen.org/xml/tc6.xsd">
  <fileHeader companyName="beremiz"
              productName="beremiz"
              productVersion="1"
              creationDateTime="2008-06-24T18:44:00"/>
  <contentHeader name="canopen_master"
                 modificationDateTime="2009-10-07T18:45:11"
                 language="en-US">
    <coordinateInfo>
      <fbd>
        <scaling x="0" y="0"/>
      </fbd>
      <ld>
        <scaling x="0" y="0"/>
      </ld>
      <sfc>
        <scaling x="0" y="0"/>
      </sfc>
    </coordinateInfo>
  </contentHeader>
  <types>
    <dataTypes/>
    <pous>
      <pou name="test_main" pouType="program">
        <interface>
          <localVars>
            <variable name="PLC_OUT" address="%QW0.0.2.8193.0">
              <type>
                <INT/>
              </type>
            </variable>
            <variable name="PLC_IN" address="%IW0.0.2.8192.0">
              <type>
                <INT/>
              </type>
            </variable>
          </localVars>
        </interface>
        <body>
          <FBD>
            <outVariable localId="1" height="29" width="80">
              <position x="362" y="140"/>
              <connectionPointIn>
                <relPosition x="0" y="14"/>
                <connection refLocalId="4" formalParameter="OUT">
                  <position x="362" y="154"/>
                  <position x="330" y="154"/>
                  <position x="330" y="153"/>
                  <position x="299" y="153"/>
                </connection>
              </connectionPointIn>
              <expression>PLC_OUT</expression>
            </outVariable>
            <inVariable localId="2" height="29" width="20">
              <position x="100" y="115"/>
              <connectionPointOut>
                <relPosition x="20" y="14"/>
              </connectionPointOut>
              <expression>1</expression>
            </inVariable>
            <block localId="4" width="75" height="60" typeName="ADD">
              <position x="224" y="123"/>
              <inputVariables>
                <variable formalParameter="IN1">
                  <connectionPointIn>
                    <relPosition x="0" y="30"/>
                    <connection refLocalId="2">
                      <position x="224" y="153"/>
                      <position x="183" y="153"/>
                      <position x="183" y="129"/>
                      <position x="120" y="129"/>
                    </connection>
                  </connectionPointIn>
                </variable>
                <variable formalParameter="IN2">
                  <connectionPointIn>
                    <relPosition x="0" y="50"/>
                    <connection refLocalId="5">
                      <position x="224" y="173"/>
                      <position x="199" y="173"/>
                      <position x="199" y="201"/>
                      <position x="174" y="201"/>
                    </connection>
                  </connectionPointIn>
                </variable>
              </inputVariables>
              <inOutVariables/>
              <outputVariables>
                <variable formalParameter="OUT">
                  <connectionPointOut>
                    <relPosition x="75" y="30"/>
                  </connectionPointOut>
                </variable>
              </outputVariables>
            </block>
            <inVariable localId="5" height="29" width="70">
              <position x="104" y="187"/>
              <connectionPointOut>
                <relPosition x="70" y="14"/>
              </connectionPointOut>
              <expression>PLC_IN</expression>
            </inVariable>
          </FBD>
        </body>
      </pou>
    </pous>
  </types>
  <instances>
    <configurations>
      <configuration name="conf">
        <resource name="res">
          <task name="tache" interval="t#50ms" priority="0">
            <pouInstance name="toto" typeName="test_main"/>
          </task>
        </resource>
      </configuration>
    </configurations>
  </instances>
</project>