etherlab/EthercatCIA402Slave.py
author Edouard Tisserant
Wed, 02 Apr 2014 15:03:32 +0200
changeset 2152 e6946c298a42
parent 2148 2225494acbf2
child 2153 91c10856adaa
permissions -rw-r--r--
Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     1
import os
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     2
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     3
import wx
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     4
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     5
from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     6
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     7
from MotionLibrary import Headers, AxisXSD
2152
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
     8
from EthercatSlave import _EthercatSlaveCTN, _CommonSlave
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     9
from ConfigEditor import CIA402NodeEditor
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    10
2152
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
    11
#------------------------------------------
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
    12
#from CommonSlave import _CommonSlave 
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
    13
#------------------------------------------
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
    14
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    15
NODE_VARIABLES = [
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    16
    ("ControlWord", 0x6040, 0x00, "UINT", "Q"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    17
    ("TargetPosition", 0x607a, 0x00, "DINT", "Q"),
2136
71fdfd4a12a3 Added support for using CIA402 motion mode csp, csv and cst
Laurent Bessard
parents: 2118
diff changeset
    18
    ("TargetVelocity", 0x60ff, 0x00, "DINT", "Q"),
71fdfd4a12a3 Added support for using CIA402 motion mode csp, csv and cst
Laurent Bessard
parents: 2118
diff changeset
    19
    ("TargetTorque", 0x6071, 0x00, "INT", "Q"),
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    20
    ("ModesOfOperation", 0x06060, 0x00, "SINT", "Q"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    21
    ("StatusWord", 0x6041, 0x00, "UINT", "I"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    22
    ("ModesOfOperationDisplay", 0x06061, 0x00, "SINT", "I"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    23
    ("ActualPosition", 0x6064, 0x00, "DINT", "I"),
2136
71fdfd4a12a3 Added support for using CIA402 motion mode csp, csv and cst
Laurent Bessard
parents: 2118
diff changeset
    24
    ("ActualVelocity", 0x606c, 0x00, "DINT", "I"),
71fdfd4a12a3 Added support for using CIA402 motion mode csp, csv and cst
Laurent Bessard
parents: 2118
diff changeset
    25
    ("ActualTorque", 0x6077, 0x00, "INT", "I"),
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    26
]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    27
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    28
DEFAULT_RETRIEVE = "    __CIA402Node_%(location)s.axis->%(name)s = *(__CIA402Node_%(location)s.%(name)s);"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    29
DEFAULT_PUBLISH = "    *(__CIA402Node_%(location)s.%(name)s) = __CIA402Node_%(location)s.axis->%(name)s;"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    30
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    31
EXTRA_NODE_VARIABLES = [
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    32
    ("ErrorCode", [
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    33
        {"description": ("ErrorCode", 0x603F, 0x00, "UINT", "I"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    34
         "publish": None}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    35
        ]),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    36
    ("DigitalInputs", [
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    37
        {"description": ("DigitalInputs", 0x60FD, 0x00, "UDINT", "I"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    38
         "publish": None}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    39
        ]),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    40
    ("DigitalOutputs", [
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    41
        {"description": ("DigitalOutputs", 0x60FE, 0x00, "UDINT", "Q"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    42
         "retrieve": None}
2146
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    43
        ]),
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    44
    ("TouchProbe", [
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    45
        {"description": ("TouchProbeFunction", 0x60B8, 0x00, "UINT", "Q"),
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    46
         "retrieve": None},
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    47
        {"description": ("TouchProbeStatus", 0x60B9, 0x00, "UINT", "I"),
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    48
         "publish": None},
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    49
        {"description": ("TouchProbePos1PosValue", 0x60BA, 0x00, "DINT", "I"),
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    50
         "publish": None},
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    51
        {"description": ("TouchProbePos1NegValue", 0x60BB, 0x00, "DINT", "I"),
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    52
         "publish": None},
0c65c96a8379 Added mapping for TouchProbe function in CIA402 slave node
Laurent Bessard
parents: 2145
diff changeset
    53
        ]),
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    54
]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    55
EXTRA_NODE_VARIABLES_DICT = dict([("Enable" + name, value) for name, value in EXTRA_NODE_VARIABLES])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    56
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    57
BLOCK_INPUT_TEMPLATE = "    __SET_VAR(%(blockname)s->,%(input_name)s, %(input_value)s);"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    58
BLOCK_OUTPUT_TEMPLATE = "    __SET_VAR(data__->,%(output_name)s, __GET_VAR(%(blockname)s->%(output_name)s));"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    59
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    60
BLOCK_FUNCTION_TEMPLATE = """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    61
extern void ETHERLAB%(ucase_blocktype)s_body__(ETHERLAB%(ucase_blocktype)s* data__);
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    62
void __%(blocktype)s_%(location)s(MC_%(ucase_blocktype)s *data__) {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    63
__DECLARE_GLOBAL_PROTOTYPE(ETHERLAB%(ucase_blocktype)s, %(blockname)s);
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    64
ETHERLAB%(ucase_blocktype)s* %(blockname)s = __GET_GLOBAL_%(blockname)s();
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    65
%(extract_inputs)s
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    66
ETHERLAB%(ucase_blocktype)s_body__(%(blockname)s);
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    67
%(return_outputs)s
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    68
}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    69
"""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    70
2118
c317b1aaf920 Fixed bug when using real axis and simulated axis at the same time (got the same index)
Laurent Bessard
parents: 2111
diff changeset
    71
BLOCK_FUNTION_DEFINITION_TEMPLATE = "        __CIA402Node_%(location)s.axis->__mcl_func_MC_%(blocktype)s = __%(blocktype)s_%(location)s;"
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    72
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    73
GLOBAL_INSTANCES = [
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    74
    {"blocktype": "GetTorqueLimit", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    75
     "inputs": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    76
     "outputs": [{"name": "TorqueLimitPos", "type": "UINT"},
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    77
                 {"name": "TorqueLimitNeg", "type": "UINT"}]},
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    78
    {"blocktype": "SetTorqueLimit", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    79
     "inputs": [{"name": "TorqueLimitPos", "type": "UINT"},
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    80
                {"name": "TorqueLimitNeg", "type": "UINT"}],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    81
     "outputs": []},
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    82
]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    83
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    84
#--------------------------------------------------
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    85
#                 Ethercat CIA402 Node
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    86
#--------------------------------------------------
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    87
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    88
class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    89
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    90
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    91
      <xsd:element name="CIA402SlaveParams">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    92
        <xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    93
          %s
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    94
        </xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    95
      </xsd:element>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    96
    </xsd:schema>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    97
    """ % ("\n".join(['<xsd:attribute name="Enable%s" type="xsd:boolean" use="optional" default="false"/>' % category 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    98
                      for category, variables in EXTRA_NODE_VARIABLES]) + AxisXSD)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    99
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   100
    NODE_PROFILE = 402
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   101
    EditorType = CIA402NodeEditor
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   102
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   103
    ConfNodeMethods = [
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   104
        {"bitmap" : "CIA402AxisRef",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   105
         "name" : _("Axis Ref"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   106
         "tooltip" : _("Initiate Drag'n drop of Axis ref located variable"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   107
         "method" : "_getCIA402AxisRef",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   108
         "push": True},
2152
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   109
    ]
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   110
    
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   111
#--------------------------------------------------
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   112
#    class code
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   113
#--------------------------------------------------    
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   114
    
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   115
    def __init__(self):
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   116
        # ----------- call ethercat mng. function --------------
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   117
        self.CommonMethod = _CommonSlave(self)
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   118
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   119
    def GetIconName(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   120
        return "CIA402Slave"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   121
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   122
    def SetParamsAttribute(self, path, value):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   123
        if path == "CIA402SlaveParams.Type":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   124
            path = "SlaveParams.Type"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   125
        elif path == "CIA402SlaveParams.Alias":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   126
            path = "SlaveParams.Alias"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   127
        return _EthercatSlaveCTN.SetParamsAttribute(self, path, value)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   128
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   129
    def GetVariableLocationTree(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   130
        axis_name = self.CTNName()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   131
        current_location = self.GetCurrentLocation()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   132
        children = [{"name": "%s Axis Ref" % (axis_name),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   133
                     "type": LOCATION_VAR_INPUT,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   134
                     "size": "W",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   135
                     "IEC_type": "AXIS_REF",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   136
                     "var_name": axis_name,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   137
                     "location": "%%IW%s.0" % (".".join(map(str, current_location))),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   138
                     "description": "",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   139
                     "children": []}]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   140
        children.extend(self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), current_location, axis_name))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   141
        return  {"name": axis_name,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   142
                 "type": LOCATION_CONFNODE,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   143
                 "location": self.GetFullIEC_Channel(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   144
                 "children": children,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   145
        }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   146
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   147
    def CTNGlobalInstances(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   148
        current_location = self.GetCurrentLocation()
2148
2225494acbf2 Fixed bug with global instance declaration
Laurent Bessard
parents: 2147
diff changeset
   149
        return [("%s_%s" % (block_infos["blocktype"], "_".join(map(str, current_location))),
2147
a8b095de63e8 Fix bug in when moving Ethercat slaves fixed
Laurent Bessard
parents: 2146
diff changeset
   150
                 "EtherLab%s" % block_infos["blocktype"], "") for block_infos in GLOBAL_INSTANCES]
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   151
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   152
    def _getCIA402AxisRef(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   153
        data = wx.TextDataObject(str(("%%IW%s.0" % ".".join(map(str, self.GetCurrentLocation())), 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   154
                                      "location", "AXIS_REF", self.CTNName(), "")))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   155
        dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   156
        dragSource.SetData(data)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   157
        dragSource.DoDragDrop()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   158
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   159
    def CTNGenerate_C(self, buildpath, locations):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   160
        current_location = self.GetCurrentLocation()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   161
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   162
        location_str = "_".join(map(lambda x:str(x), current_location))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   163
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   164
        plc_cia402node_filepath = os.path.join(os.path.split(__file__)[0], "plc_cia402node.c")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   165
        plc_cia402node_file = open(plc_cia402node_filepath, 'r')
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   166
        plc_cia402node_code = plc_cia402node_file.read()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   167
        plc_cia402node_file.close()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   168
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   169
        str_completion = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   170
            "slave_pos": self.GetSlavePos(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   171
            "location": location_str,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   172
            "MCL_headers": Headers,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   173
            "extern_located_variables_declaration": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   174
            "fieldbus_interface_declaration": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   175
            "fieldbus_interface_definition": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   176
            "entry_variables": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   177
            "init_axis_params": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   178
            "init_entry_variables": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   179
            "extra_variables_retrieve": [],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   180
            "extra_variables_publish": []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   181
        }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   182
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   183
        for blocktype_infos in GLOBAL_INSTANCES:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   184
            texts = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   185
                "blocktype": blocktype_infos["blocktype"],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   186
                "ucase_blocktype": blocktype_infos["blocktype"].upper(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   187
                "location": "_".join(map(str, current_location))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   188
            }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   189
            texts["blockname"] = "%(ucase_blocktype)s_%(location)s" % texts
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   190
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   191
            inputs = [{"input_name": "POS", "input_value": str(self.GetSlavePos())},
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   192
                      {"input_name": "EXECUTE", "input_value": "__GET_VAR(data__->EXECUTE)"}] +\
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   193
                     [{"input_name": input["name"].upper(), 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   194
                       "input_value": "__GET_VAR(data__->%s)" % input["name"].upper()}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   195
                      for input in blocktype_infos["inputs"]]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   196
            input_texts = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   197
            for input_infos in inputs:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   198
                input_infos.update(texts)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   199
                input_texts.append(BLOCK_INPUT_TEMPLATE % input_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   200
            texts["extract_inputs"] = "\n".join(input_texts)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   201
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   202
            outputs = [{"output_name": output} for output in ["DONE", "BUSY", "ERROR"]] + \
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   203
                      [{"output_name": output["name"].upper()} for output in blocktype_infos["outputs"]]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   204
            output_texts = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   205
            for output_infos in outputs:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   206
                output_infos.update(texts)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   207
                output_texts.append(BLOCK_OUTPUT_TEMPLATE % output_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   208
            texts["return_outputs"] = "\n".join(output_texts)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   209
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   210
            str_completion["fieldbus_interface_declaration"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   211
                    BLOCK_FUNCTION_TEMPLATE % texts)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   212
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   213
            str_completion["fieldbus_interface_definition"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   214
                    BLOCK_FUNTION_DEFINITION_TEMPLATE % texts)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   215
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   216
        variables = NODE_VARIABLES[:]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   217
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   218
        params = self.CTNParams[1].getElementInfos(self.CTNParams[0])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   219
        for param in params["children"]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   220
            if param["name"] in EXTRA_NODE_VARIABLES_DICT:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   221
                if param["value"]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   222
                    extra_variables = EXTRA_NODE_VARIABLES_DICT.get(param["name"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   223
                    for variable_infos in extra_variables:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   224
                        var_infos = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   225
                            "location": location_str,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   226
                            "name": variable_infos["description"][0]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   227
                        }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   228
                        variables.append(variable_infos["description"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   229
                        retrieve_template = variable_infos.get("retrieve", DEFAULT_RETRIEVE)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   230
                        publish_template = variable_infos.get("publish", DEFAULT_PUBLISH)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   231
                        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   232
                        if retrieve_template is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   233
                            str_completion["extra_variables_retrieve"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   234
                                retrieve_template % var_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   235
                        if publish_template is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   236
                            str_completion["extra_variables_publish"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   237
                                publish_template % var_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   238
            elif param["value"] is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   239
                param_infos = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   240
                    "location": location_str,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   241
                    "param_name": param["name"],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   242
                }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   243
                if param["type"] == "boolean":
2145
65ed4f7c941b Fixed bug with axes boolean parameters value
Laurent Bessard
parents: 2136
diff changeset
   244
                    param_infos["param_value"] = {True: "1", False: "0"}[param["value"]]
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   245
                else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   246
                    param_infos["param_value"] = str(param["value"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   247
                str_completion["init_axis_params"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   248
                    "        __CIA402Node_%(location)s.axis->%(param_name)s = %(param_value)s;" % param_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   249
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   250
        for variable in variables:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   251
            var_infos = dict(zip(["name", "index", "subindex", "var_type", "dir"], variable))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   252
            var_infos["location"] = location_str
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   253
            var_infos["var_size"] = self.GetSizeOfType(var_infos["var_type"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   254
            var_infos["var_name"] = "__%(dir)s%(var_size)s%(location)s_%(index)d_%(subindex)d" % var_infos
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   255
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   256
            str_completion["extern_located_variables_declaration"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   257
                    "IEC_%(var_type)s *%(var_name)s;" % var_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   258
            str_completion["entry_variables"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   259
                    "    IEC_%(var_type)s *%(name)s;" % var_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   260
            str_completion["init_entry_variables"].append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   261
                    "    __CIA402Node_%(location)s.%(name)s = %(var_name)s;" % var_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   262
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   263
            self.CTNParent.FileGenerator.DeclareVariable(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   264
                    self.GetSlavePos(), var_infos["index"], var_infos["subindex"], 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   265
                    var_infos["var_type"], var_infos["dir"], var_infos["var_name"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   266
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   267
        for element in ["extern_located_variables_declaration", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   268
                        "fieldbus_interface_declaration",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   269
                        "fieldbus_interface_definition",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   270
                        "entry_variables", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   271
                        "init_axis_params", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   272
                        "init_entry_variables",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   273
                        "extra_variables_retrieve",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   274
                        "extra_variables_publish"]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   275
            str_completion[element] = "\n".join(str_completion[element])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   276
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   277
        Gen_CIA402Nodefile_path = os.path.join(buildpath, "cia402node_%s.c"%location_str)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   278
        cia402nodefile = open(Gen_CIA402Nodefile_path, 'w')
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   279
        cia402nodefile.write(plc_cia402node_code % str_completion)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   280
        cia402nodefile.close()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   281
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   282
        return [(Gen_CIA402Nodefile_path, '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()))],"",True
2152
e6946c298a42 Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents: 2148
diff changeset
   283