etherlab/EthercatMaster.py
author Laurent Bessard
Thu, 25 Apr 2013 23:01:06 +0200
changeset 2136 71fdfd4a12a3
parent 2133 ba0b2ca7db26
child 2135 ca1c34ff6c10
child 2137 b65abacdbdf9
permissions -rw-r--r--
Added support for using CIA402 motion mode csp, csv and cst
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
import cPickle
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     3
from xml.dom import minidom
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
import wx
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 xmlclass import *
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     8
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
     9
from PLCControler import UndoBuffer, 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
    10
from ConfigTreeNode import ConfigTreeNode
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    11
from dialogs import BrowseValuesLibraryDialog
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    12
from IDEFrame import TITLE, FILEMENU, PROJECTTREE
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    13
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    14
from EthercatSlave import _EthercatSlaveCTN, ExtractHexDecValue, GenerateHexDecValue, TYPECONVERSION, VARCLASSCONVERSION
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    15
from EthercatCFileGenerator import _EthercatCFileGenerator
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    16
from ConfigEditor import MasterEditor
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    17
from POULibrary import POULibrary
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    18
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    19
try:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    20
    from EthercatCIA402Slave import _EthercatCIA402SlaveCTN
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    21
    HAS_MCL = True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    22
except:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    23
    HAS_MCL = False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    24
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    25
#--------------------------------------------------
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    26
#         Remote Exec Etherlab Commands
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
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    29
SCAN_COMMAND = """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    30
import commands
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    31
result = commands.getoutput("ethercat slaves")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    32
slaves = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    33
for slave_line in result.splitlines():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    34
    chunks = slave_line.split()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    35
    idx, pos, state, flag = chunks[:4]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    36
    name = " ".join(chunks[4:])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    37
    alias, position = pos.split(":")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    38
    slave = {"idx": int(idx),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    39
             "alias": int(alias),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    40
             "position": int(position),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    41
             "name": name}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    42
    details = commands.getoutput("ethercat slaves -p %d -v" % slave["idx"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    43
    for details_line in details.splitlines():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    44
        details_line = details_line.strip()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    45
        for header, param in [("Vendor Id:", "vendor_id"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    46
                              ("Product code:", "product_code"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    47
                              ("Revision number:", "revision_number")]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    48
            if details_line.startswith(header):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    49
                slave[param] = details_line.split()[-1]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    50
                break
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    51
    slaves.append(slave)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    52
returnVal = slaves
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    53
"""
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
#--------------------------------------------------
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    56
#      Etherlab Specific Blocks Library
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    57
#--------------------------------------------------
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    58
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    59
def GetLocalPath(filename):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    60
    return os.path.join(os.path.split(__file__)[0], filename)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    61
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    62
class EtherlabLibrary(POULibrary):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    63
    def GetLibraryPath(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    64
        return GetLocalPath("pous.xml")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    65
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    66
    def Generate_C(self, buildpath, varlist, IECCFLAGS):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    67
        etherlab_ext_file = open(GetLocalPath("etherlab_ext.c"), 'r')
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    68
        etherlab_ext_code = etherlab_ext_file.read()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    69
        etherlab_ext_file.close()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    70
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    71
        Gen_etherlabfile_path = os.path.join(buildpath, "etherlab_ext.c")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    72
        ethelabfile = open(Gen_etherlabfile_path,'w')
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    73
        ethelabfile.write(etherlab_ext_code)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    74
        ethelabfile.close()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    75
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    76
        return ((["etherlab_ext"], [(Gen_etherlabfile_path, IECCFLAGS)], True), "", 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    77
                ("runtime_etherlab.py", file(GetLocalPath("runtime_etherlab.py"))))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    78
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    79
#--------------------------------------------------
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    80
#                 Ethercat MASTER
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    81
#--------------------------------------------------
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
EtherCATConfigClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATConfig.xsd")) 
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
def sort_commands(x, y):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    86
    if x["Index"] == y["Index"]:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    87
        return cmp(x["Subindex"], y["Subindex"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    88
    return cmp(x["Index"], y["Index"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    89
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    90
cls = EtherCATConfigClasses.get("Config_Slave", None)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    91
if cls:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    92
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    93
    def getType(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    94
        slave_info = self.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    95
        return {"device_type": slave_info.getName(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    96
                "vendor": GenerateHexDecValue(slave_info.getVendorId()),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    97
                "product_code": GenerateHexDecValue(slave_info.getProductCode(), 16),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    98
                "revision_number": GenerateHexDecValue(slave_info.getRevisionNo(), 16)}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
    99
    setattr(cls, "getType", getType)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   100
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   101
    def setType(self, type_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   102
        slave_info = self.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   103
        slave_info.setName(type_infos["device_type"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   104
        slave_info.setVendorId(ExtractHexDecValue(type_infos["vendor"]))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   105
        slave_info.setProductCode(ExtractHexDecValue(type_infos["product_code"]))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   106
        slave_info.setRevisionNo(ExtractHexDecValue(type_infos["revision_number"]))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   107
    setattr(cls, "setType", setType)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   108
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   109
    def getInitCmds(self, create_default=False):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   110
        Mailbox = self.getMailbox()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   111
        if Mailbox is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   112
            if create_default:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   113
                self.addMailbox()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   114
                Mailbox = self.getMailbox()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   115
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   116
                return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   117
        CoE = Mailbox.getCoE()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   118
        if CoE is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   119
            if create_default:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   120
                Mailbox.addCoE()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   121
                CoE = Mailbox.getCoE()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   122
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   123
                return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   124
        InitCmds = CoE.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   125
        if InitCmds is None and create_default:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   126
            CoE.addInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   127
            InitCmds = CoE.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   128
        return InitCmds
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   129
    setattr(cls, "getInitCmds", getInitCmds)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   130
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   131
    def getStartupCommands(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   132
        pos = self.getInfo().getPhysAddr()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   133
        InitCmds = self.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   134
        if InitCmds is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   135
            return []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   136
        commands = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   137
        for idx, InitCmd in enumerate(InitCmds.getInitCmd()):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   138
            comment = InitCmd.getComment()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   139
            if comment is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   140
                comment = ""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   141
            commands.append({
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   142
                "command_idx": idx,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   143
                "Position": pos,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   144
                "Index": InitCmd.getIndex(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   145
                "Subindex": InitCmd.getSubIndex(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   146
                "Value": InitCmd.getData(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   147
                "Description": comment})
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   148
        commands.sort(sort_commands)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   149
        return commands
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   150
    setattr(cls, "getStartupCommands", getStartupCommands)
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 appendStartupCommand(self, command_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   153
        InitCmds = self.getInitCmds(True)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   154
        command = EtherCATConfigClasses["InitCmds_InitCmd"]()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   155
        command.setIndex(command_infos["Index"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   156
        command.setSubIndex(command_infos["Subindex"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   157
        command.setData(command_infos["Value"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   158
        command.setComment(command_infos["Description"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   159
        InitCmds.appendInitCmd(command)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   160
        return len(InitCmds.getInitCmd()) - 1
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   161
    setattr(cls, "appendStartupCommand", appendStartupCommand)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   162
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   163
    def setStartupCommand(self, command_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   164
        InitCmds = self.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   165
        if InitCmds is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   166
            commands = InitCmds.getInitCmd()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   167
            if command_infos["command_idx"] < len(commands):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   168
                command = commands[command_infos["command_idx"]]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   169
                command.setIndex(command_infos["Index"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   170
                command.setSubIndex(command_infos["Subindex"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   171
                command.setData(command_infos["Value"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   172
                command.setComment(command_infos["Description"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   173
    setattr(cls, "setStartupCommand", setStartupCommand)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   174
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   175
    def removeStartupCommand(self, command_idx):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   176
        InitCmds = self.getInitCmds()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   177
        if InitCmds is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   178
            if command_idx < len(InitCmds.getInitCmd()):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   179
                InitCmds.removeInitCmd(command_idx)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   180
    setattr(cls, "removeStartupCommand", removeStartupCommand)
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
ProcessVariablesXSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   183
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   184
      <xsd:element name="ProcessVariables">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   185
        <xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   186
          <xsd:sequence>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   187
            <xsd:element name="variable" minOccurs="0" maxOccurs="unbounded">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   188
              <xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   189
                <xsd:sequence>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   190
                  <xsd:element name="ReadFrom" type="LocationDesc" minOccurs="0"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   191
                  <xsd:element name="WriteTo" type="LocationDesc" minOccurs="0"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   192
                </xsd:sequence>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   193
                <xsd:attribute name="Name" type="xsd:string" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   194
                <xsd:attribute name="Comment" type="xsd:string" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   195
              </xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   196
            </xsd:element>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   197
          </xsd:sequence>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   198
        </xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   199
      </xsd:element>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   200
      <xsd:complexType name="LocationDesc">
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   201
        <xsd:attribute name="Position" type="xsd:integer" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   202
        <xsd:attribute name="Index" type="xsd:integer" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   203
        <xsd:attribute name="SubIndex" type="xsd:integer" use="required"/>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   204
      </xsd:complexType>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   205
    </xsd:schema>
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   206
"""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   207
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   208
ProcessVariablesClasses = GenerateClassesFromXSDstring(ProcessVariablesXSD) 
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
class _EthercatCTN:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   211
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   212
    CTNChildrenTypes = [("EthercatSlave", _EthercatSlaveCTN, "Ethercat Slave")]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   213
    if HAS_MCL:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   214
        CTNChildrenTypes.append(("EthercatCIA402Slave", _EthercatCIA402SlaveCTN, "Ethercat CIA402 Slave"))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   215
    EditorType = MasterEditor
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   216
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   217
    def __init__(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   218
        config_filepath = self.ConfigFileName()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   219
        config_is_saved = False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   220
        self.Config = EtherCATConfigClasses["EtherCATConfig"]()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   221
        if os.path.isfile(config_filepath):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   222
            config_xmlfile = open(config_filepath, 'r')
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   223
            config_tree = minidom.parse(config_xmlfile)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   224
            config_xmlfile.close()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   225
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   226
            for child in config_tree.childNodes:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   227
                if child.nodeType == config_tree.ELEMENT_NODE and child.nodeName == "EtherCATConfig":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   228
                    self.Config.loadXMLTree(child)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   229
                    config_is_saved = True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   230
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   231
        process_filepath = self.ProcessVariablesFileName()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   232
        process_is_saved = False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   233
        self.ProcessVariables = ProcessVariablesClasses["ProcessVariables"]()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   234
        if os.path.isfile(process_filepath):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   235
            process_xmlfile = open(process_filepath, 'r')
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   236
            process_tree = minidom.parse(process_xmlfile)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   237
            process_xmlfile.close()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   238
            
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   239
            for child in process_tree.childNodes:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   240
                if child.nodeType == process_tree.ELEMENT_NODE and child.nodeName == "ProcessVariables":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   241
                    self.ProcessVariables.loadXMLTree(child)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   242
                    process_is_saved = True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   243
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   244
        if config_is_saved and process_is_saved:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   245
            self.CreateBuffer(True)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   246
        else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   247
            self.CreateBuffer(False)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   248
            self.OnCTNSave()
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
    def GetContextualMenuItems(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   251
        return [("Add Ethercat Slave", "Add Ethercat Slave to Master", self.OnAddEthercatSlave)]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   252
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   253
    def OnAddEthercatSlave(self, event):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   254
        app_frame = self.GetCTRoot().AppFrame
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   255
        dialog = BrowseValuesLibraryDialog(app_frame, 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   256
            "Ethercat Slave Type", self.GetSlaveTypesLibrary())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   257
        if dialog.ShowModal() == wx.ID_OK:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   258
            type_infos = dialog.GetValueInfos()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   259
            device, alignment = self.GetModuleInfos(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   260
            if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   261
                if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   262
                    ConfNodeType = "EthercatCIA402Slave"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   263
                else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   264
                    ConfNodeType = "EthercatSlave"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   265
                new_child = self.CTNAddChild("%s_0" % ConfNodeType, ConfNodeType)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   266
                new_child.SetParamsAttribute("SlaveParams.Type", type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   267
                self.CTNRequestSave()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   268
                new_child._OpenView()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   269
                app_frame._Refresh(TITLE, FILEMENU, PROJECTTREE)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   270
        dialog.Destroy()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   271
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   272
    def ExtractHexDecValue(self, value):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   273
        return ExtractHexDecValue(value)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   274
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   275
    def GetSizeOfType(self, type):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   276
        return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   277
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   278
    def ConfigFileName(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   279
        return os.path.join(self.CTNPath(), "config.xml")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   280
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   281
    def ProcessVariablesFileName(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   282
        return os.path.join(self.CTNPath(), "process_variables.xml")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   283
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   284
    def FilterSlave(self, slave, vendor=None, slave_pos=None, slave_profile=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   285
        if slave_pos is not None and slave.getInfo().getPhysAddr() != slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   286
            return False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   287
        type_infos = slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   288
        if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   289
            return False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   290
        device, alignment = self.GetModuleInfos(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   291
        if slave_profile is not None and slave_profile not in device.GetProfileNumbers():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   292
            return False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   293
        return True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   294
2124
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   295
    def GetSlaveName(self, slave_pos):
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   296
        CTNChild = self.GetChildByIECLocation((slave_pos,))
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   297
        if CTNChild is not None:
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   298
            return CTNChild.CTNName()
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   299
        return self.CTNName()
1f2c3fdd70d0 Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents: 2113
diff changeset
   300
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   301
    def GetSlaves(self, vendor=None, slave_pos=None, slave_profile=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   302
        slaves = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   303
        for slave in self.Config.getConfig().getSlave():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   304
            if self.FilterSlave(slave, vendor, slave_pos, slave_profile):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   305
                slaves.append(slave.getInfo().getPhysAddr())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   306
        slaves.sort()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   307
        return slaves
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   308
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   309
    def GetSlave(self, slave_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   310
        for slave in self.Config.getConfig().getSlave():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   311
            slave_info = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   312
            if slave_info.getPhysAddr() == slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   313
                return slave
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   314
        return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   315
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   316
    def GetStartupCommands(self, vendor=None, slave_pos=None, slave_profile=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   317
        commands = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   318
        for slave in self.Config.getConfig().getSlave():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   319
            if self.FilterSlave(slave, vendor, slave_pos, slave_profile):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   320
                commands.append((slave.getInfo().getPhysAddr(), slave.getStartupCommands()))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   321
        commands.sort()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   322
        return reduce(lambda x, y: x + y[1], commands, [])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   323
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   324
    def AppendStartupCommand(self, command_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   325
        slave = self.GetSlave(command_infos["Position"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   326
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   327
            command_idx = slave.appendStartupCommand(command_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   328
            self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   329
            return command_idx
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   330
        return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   331
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   332
    def SetStartupCommandInfos(self, command_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   333
        slave = self.GetSlave(command_infos["Position"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   334
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   335
            slave.setStartupCommand(command_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   336
            self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   337
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   338
    def RemoveStartupCommand(self, slave_pos, command_idx, buffer=True):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   339
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   340
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   341
            slave.removeStartupCommand(command_idx)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   342
            if buffer:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   343
                self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   344
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   345
    def SetProcessVariables(self, variables):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   346
        vars = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   347
        for var in variables:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   348
            variable = ProcessVariablesClasses["ProcessVariables_variable"]()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   349
            variable.setName(var["Name"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   350
            variable.setComment(var["Description"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   351
            if var["ReadFrom"] != "":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   352
                position, index, subindex = var["ReadFrom"]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   353
                if variable.getReadFrom() is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   354
                    variable.addReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   355
                read_from = variable.getReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   356
                read_from.setPosition(position)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   357
                read_from.setIndex(index)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   358
                read_from.setSubIndex(subindex)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   359
            elif variable.getReadFrom() is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   360
                variable.deleteReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   361
            if var["WriteTo"] != "":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   362
                position, index, subindex = var["WriteTo"]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   363
                if variable.getWriteTo() is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   364
                    variable.addWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   365
                write_to = variable.getWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   366
                write_to.setPosition(position)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   367
                write_to.setIndex(index)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   368
                write_to.setSubIndex(subindex)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   369
            elif variable.getWriteTo() is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   370
                variable.deleteWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   371
            vars.append(variable)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   372
        self.ProcessVariables.setvariable(vars)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   373
        self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   374
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   375
    def GetProcessVariables(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   376
        variables = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   377
        idx = 0
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   378
        for variable in self.ProcessVariables.getvariable():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   379
            var = {"Name": variable.getName(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   380
                   "Number": idx,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   381
                   "Description": variable.getComment()}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   382
            read_from = variable.getReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   383
            if read_from is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   384
                var["ReadFrom"] = (read_from.getPosition(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   385
                                   read_from.getIndex(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   386
                                   read_from.getSubIndex())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   387
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   388
                var["ReadFrom"] = ""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   389
            write_to = variable.getWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   390
            if write_to is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   391
                var["WriteTo"] = (write_to.getPosition(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   392
                                   write_to.getIndex(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   393
                                   write_to.getSubIndex())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   394
            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   395
                var["WriteTo"] = ""
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   396
            variables.append(var)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   397
            idx += 1
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   398
        return variables
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   399
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   400
    def _ScanNetwork(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   401
        app_frame = self.GetCTRoot().AppFrame
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   402
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   403
        execute = True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   404
        if len(self.Children) > 0:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   405
            dialog = wx.MessageDialog(app_frame, 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   406
                _("The current network configuration will be deleted.\nDo you want to continue?"), 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   407
                _("Scan Network"), 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   408
                wx.YES_NO|wx.ICON_QUESTION)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   409
            execute = dialog.ShowModal() == wx.ID_YES
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   410
            dialog.Destroy()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   411
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   412
        if execute:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   413
            error, returnVal = self.RemoteExec(SCAN_COMMAND, returnVal = None)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   414
            if error != 0:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   415
                dialog = wx.MessageDialog(app_frame, returnVal, "Error", wx.OK|wx.ICON_ERROR)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   416
                dialog.ShowModal()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   417
                dialog.Destroy()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   418
            elif returnVal is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   419
                for child in self.IECSortedChildren():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   420
                    self._doRemoveChild(child)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   421
                
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   422
                for slave in returnVal:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   423
                    type_infos = {
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   424
                        "vendor": slave["vendor_id"],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   425
                        "product_code": slave["product_code"],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   426
                        "revision_number":slave["revision_number"],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   427
                    }
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   428
                    device, alignment = self.GetModuleInfos(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   429
                    if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   430
                        if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   431
                            CTNType = "EthercatCIA402Slave"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   432
                        else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   433
                            CTNType = "EthercatSlave"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   434
                        self.CTNAddChild("slave%s" % slave["idx"], CTNType, slave["idx"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   435
                        self.SetSlaveAlias(slave["idx"], slave["alias"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   436
                        type_infos["device_type"] = device.getType().getcontent()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   437
                        self.SetSlaveType(slave["idx"], type_infos)
2127
32255ca50fb0 Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents: 2124
diff changeset
   438
            
32255ca50fb0 Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents: 2124
diff changeset
   439
                if app_frame:
32255ca50fb0 Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents: 2124
diff changeset
   440
                    app_frame.RefreshProjectTree()
32255ca50fb0 Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents: 2124
diff changeset
   441
            
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   442
    def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   443
        """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   444
        Create the confnodes that may be added as child to this node self
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   445
        @param CTNType: string desining the confnode class name (get name from CTNChildrenTypes)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   446
        @param CTNName: string for the name of the confnode instance
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   447
        """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   448
        newConfNodeOpj = ConfigTreeNode.CTNAddChild(self, CTNName, CTNType, IEC_Channel)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   449
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   450
        slave = self.GetSlave(newConfNodeOpj.BaseParams.getIEC_Channel())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   451
        if slave is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   452
            slave = EtherCATConfigClasses["Config_Slave"]()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   453
            slave_infos = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   454
            slave_infos.setName("undefined")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   455
            slave_infos.setPhysAddr(newConfNodeOpj.BaseParams.getIEC_Channel())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   456
            slave_infos.setAutoIncAddr(0)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   457
            self.Config.getConfig().appendSlave(slave)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   458
            self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   459
            self.OnCTNSave()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   460
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   461
        return newConfNodeOpj
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   462
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   463
    def _doRemoveChild(self, CTNInstance):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   464
        slave_pos = CTNInstance.GetSlavePos()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   465
        config = self.Config.getConfig()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   466
        for idx, slave in enumerate(config.getSlave()):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   467
            slave_infos = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   468
            if slave_infos.getPhysAddr() == slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   469
                config.removeSlave(idx)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   470
                self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   471
                self.OnCTNSave()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   472
        ConfigTreeNode._doRemoveChild(self, CTNInstance)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   473
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   474
    def SetSlavePosition(self, slave_pos, new_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   475
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   476
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   477
            slave_info = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   478
            slave_info.setPhysAddr(new_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   479
            for variable in self.ProcessVariables.getvariable():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   480
                read_from = variable.getReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   481
                if read_from is not None and read_from.getPosition() == slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   482
                    read_from.setPosition(new_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   483
                write_to = variable.getWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   484
                if write_to is not None and write_to.getPosition() == slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   485
                    write_to.setPosition(new_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   486
            self.CreateBuffer(True)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   487
            self.OnCTNSave()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   488
            if self._View is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   489
                self._View.RefreshView()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   490
                self._View.RefreshBuffer()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   491
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   492
    def GetSlaveAlias(self, slave_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   493
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   494
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   495
            slave_info = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   496
            return slave_info.getAutoIncAddr()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   497
        return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   498
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   499
    def SetSlaveAlias(self, slave_pos, alias):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   500
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   501
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   502
            slave_info = slave.getInfo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   503
            slave_info.setAutoIncAddr(alias)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   504
            self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   505
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   506
    def GetSlaveType(self, slave_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   507
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   508
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   509
            return slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   510
        return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   511
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   512
    def SetSlaveType(self, slave_pos, type_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   513
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   514
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   515
            slave.setType(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   516
            self.BufferModel()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   517
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   518
    def GetSlaveInfos(self, slave_pos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   519
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   520
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   521
            type_infos = slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   522
            device, alignment = self.GetModuleInfos(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   523
            if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   524
                infos = type_infos.copy()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   525
                infos.update({"physics": device.getPhysics(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   526
                              "sync_managers": device.GetSyncManagers(),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   527
                              "entries": self.GetSlaveVariables(device)})
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   528
                return infos
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   529
        return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   530
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   531
    def GetSlaveVariables(self, slave_pos=None, limits=None, device=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   532
        if device is None and slave_pos is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   533
            slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   534
            if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   535
                type_infos = slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   536
                device, alignment = self.GetModuleInfos(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   537
        if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   538
            entries = device.GetEntriesList(limits)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   539
            entries_list = entries.items()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   540
            entries_list.sort()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   541
            entries = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   542
            current_index = None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   543
            current_entry = None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   544
            for (index, subindex), entry in entries_list:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   545
                entry["children"] = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   546
                if slave_pos is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   547
                    entry["Position"] = str(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   548
                entry
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   549
                if index != current_index:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   550
                    current_index = index
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   551
                    current_entry = entry
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   552
                    entries.append(entry)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   553
                elif current_entry is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   554
                    current_entry["children"].append(entry)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   555
                else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   556
                    entries.append(entry)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   557
            return entries
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   558
        return []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   559
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   560
    def GetSlaveVariableDataType(self, slave_pos, index, subindex):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   561
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   562
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   563
            device, alignment = self.GetModuleInfos(slave.getType())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   564
            if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   565
                entries = device.GetEntriesList()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   566
                entry_infos = entries.get((index, subindex))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   567
                if entry_infos is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   568
                    return entry_infos["Type"]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   569
        return None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   570
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   571
    def GetNodesVariables(self, vendor=None, slave_pos=None, slave_profile=None, limits=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   572
        entries = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   573
        for slave_position in self.GetSlaves():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   574
            if slave_pos is not None and slave_position != slave_pos:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   575
                continue
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   576
            slave = self.GetSlave(slave_position)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   577
            type_infos = slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   578
            if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   579
                continue
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   580
            device, alignment = self.GetModuleInfos(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   581
            if slave_profile is not None and slave_profile not in device.GetProfileNumbers():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   582
                continue
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   583
            entries.extend(self.GetSlaveVariables(slave_position, limits, device))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   584
        return entries
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   585
     
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   586
    def GetModuleInfos(self, type_infos):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   587
        return self.CTNParent.GetModuleInfos(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   588
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   589
    def GetSlaveTypesLibrary(self, profile_filter=None):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   590
        return self.CTNParent.GetModulesLibrary(profile_filter)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   591
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   592
    def GetLibraryVendors(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   593
        return self.CTNParent.GetVendors()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   594
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   595
    def GetDeviceLocationTree(self, slave_pos, current_location, device_name):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   596
        slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   597
        vars = []    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   598
        if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   599
            type_infos = slave.getType()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   600
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   601
            device, alignment = self.GetModuleInfos(type_infos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   602
            if device is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   603
                sync_managers = []
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   604
                for sync_manager in device.getSm():
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   605
                    sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   606
                    sync_manager_direction = sync_manager_control_byte & 0x0c
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   607
                    if sync_manager_direction:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   608
                        sync_managers.append(LOCATION_VAR_OUTPUT)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   609
                    else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   610
                        sync_managers.append(LOCATION_VAR_INPUT)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   611
                
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   612
                entries = device.GetEntriesList().items()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   613
                entries.sort()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   614
                for (index, subindex), entry in entries:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   615
                    var_size = self.GetSizeOfType(entry["Type"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   616
                    if var_size is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   617
                        var_class = VARCLASSCONVERSION.get(entry["PDOMapping"], None)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   618
                        if var_class is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   619
                            if var_class == LOCATION_VAR_INPUT:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   620
                                var_dir = "%I"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   621
                            else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   622
                                var_dir = "%Q"    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   623
                        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   624
                            vars.append({"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry["Name"]),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   625
                                         "type": var_class,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   626
                                         "size": var_size,
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   627
                                         "IEC_type": entry["Type"],
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   628
                                         "var_name": "%s_%4.4x_%2.2x" % ("_".join(device_name.split()), index, subindex),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   629
                                         "location": "%s%s%s"%(var_dir, var_size, ".".join(map(str, current_location + 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   630
                                                                                                    (index, subindex)))),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   631
                                         "description": "",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   632
                                         "children": []})
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   633
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   634
        return vars
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   635
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   636
    def CTNTestModified(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   637
        return self.ChangesToSave or not self.ModelIsSaved()    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   638
2133
ba0b2ca7db26 Fixed Save As... function in Beremiz
Laurent Bessard
parents: 2127
diff changeset
   639
    def OnCTNSave(self, from_project_path=None):
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   640
        config_filepath = self.ConfigFileName()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   641
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   642
        config_text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   643
        config_extras = {"xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   644
                  "xsi:noNamespaceSchemaLocation" : "EtherCATInfo.xsd"}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   645
        config_text += self.Config.generateXMLText("EtherCATConfig", 0, config_extras)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   646
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   647
        config_xmlfile = open(config_filepath,"w")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   648
        config_xmlfile.write(config_text.encode("utf-8"))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   649
        config_xmlfile.close()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   650
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   651
        process_filepath = self.ProcessVariablesFileName()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   652
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   653
        process_text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   654
        process_extras = {"xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance"}
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   655
        process_text += self.ProcessVariables.generateXMLText("ProcessVariables", 0, process_extras)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   656
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   657
        process_xmlfile = open(process_filepath,"w")
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   658
        process_xmlfile.write(process_text.encode("utf-8"))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   659
        process_xmlfile.close()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   660
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   661
        self.Buffer.CurrentSaved()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   662
        return True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   663
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   664
    def GetProcessVariableName(self, location, var_type):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   665
        return "__M%s_%s" % (self.GetSizeOfType(var_type), "_".join(map(str, location)))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   666
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   667
    def _Generate_C(self, buildpath, locations):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   668
        current_location = self.GetCurrentLocation()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   669
        # define a unique name for the generated C file
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   670
        location_str = "_".join(map(lambda x:str(x), current_location))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   671
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   672
        Gen_Ethercatfile_path = os.path.join(buildpath, "ethercat_%s.c"%location_str)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   673
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   674
        self.FileGenerator = _EthercatCFileGenerator(self)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   675
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   676
        LocationCFilesAndCFLAGS, LDFLAGS, extra_files = ConfigTreeNode._Generate_C(self, buildpath, locations)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   677
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   678
        for idx, variable in enumerate(self.ProcessVariables.getvariable()):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   679
            name = None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   680
            var_type = None
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   681
            read_from = variable.getReadFrom()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   682
            write_to = variable.getWriteTo()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   683
            if read_from is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   684
                pos = read_from.getPosition()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   685
                index = read_from.getIndex()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   686
                subindex = read_from.getSubIndex()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   687
                location = current_location + (idx, )
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   688
                var_type = self.GetSlaveVariableDataType(pos, index, subindex)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   689
                name = self.FileGenerator.DeclareVariable(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   690
                            pos, index, subindex, var_type, "I",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   691
                            self.GetProcessVariableName(location, var_type))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   692
            if write_to is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   693
                pos = write_to.getPosition()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   694
                index = write_to.getIndex()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   695
                subindex = write_to.getSubIndex()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   696
                if name is None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   697
                    location = current_location + (idx, )
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   698
                    var_type = self.GetSlaveVariableDataType(pos, index, subindex)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   699
                    name = self.GetProcessVariableName(location, var_type)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   700
                self.FileGenerator.DeclareVariable(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   701
                            pos, index, subindex, var_type, "Q", name, True)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   702
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   703
        self.FileGenerator.GenerateCFile(Gen_Ethercatfile_path, location_str, self.BaseParams.getIEC_Channel())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   704
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   705
        LocationCFilesAndCFLAGS.append(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   706
            (current_location, 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   707
             [(Gen_Ethercatfile_path, '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()))], 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   708
             True))
2112
e88cd6ff885e Fixed linking with non RTDM etherlab lib. Now with rtdm...
Edouard Tisserant
parents: 2111
diff changeset
   709
        LDFLAGS.append("-lethercat_rtdm -lrtdm")
2111
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   710
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   711
        return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   712
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   713
    ConfNodeMethods = [
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   714
        {"bitmap" : "ScanNetwork",
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   715
         "name" : _("Scan Network"), 
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   716
         "tooltip" : _("Scan Network"),
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   717
         "method" : "_ScanNetwork"},
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   718
    ]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   719
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   720
    def CTNGenerate_C(self, buildpath, locations):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   721
        current_location = self.GetCurrentLocation()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   722
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   723
        slaves = self.GetSlaves()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   724
        for slave_pos in slaves:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   725
            slave = self.GetSlave(slave_pos)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   726
            if slave is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   727
                self.FileGenerator.DeclareSlave(slave_pos, slave)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   728
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   729
        for location in locations:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   730
            loc = location["LOC"][len(current_location):]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   731
            slave_pos = loc[0]
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   732
            if slave_pos in slaves and len(loc) == 3 and location["DIR"] != "M":
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   733
                self.FileGenerator.DeclareVariable(
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   734
                    slave_pos, loc[1], loc[2], location["IEC_TYPE"], location["DIR"], location["NAME"])
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   735
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   736
        return [],"",False
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   737
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   738
#-------------------------------------------------------------------------------
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   739
#                      Current Buffering Management Functions
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   740
#-------------------------------------------------------------------------------
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   741
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   742
    """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   743
    Return a copy of the config
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   744
    """
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   745
    def Copy(self, model):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   746
        return cPickle.loads(cPickle.dumps(model))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   747
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   748
    def CreateBuffer(self, saved):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   749
        self.Buffer = UndoBuffer(cPickle.dumps((self.Config, self.ProcessVariables)), saved)
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   750
        
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   751
    def BufferModel(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   752
        self.Buffer.Buffering(cPickle.dumps((self.Config, self.ProcessVariables)))
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   753
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   754
    def ModelIsSaved(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   755
        if self.Buffer is not None:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   756
            return self.Buffer.IsCurrentSaved()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   757
        else:
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   758
            return True
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   759
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   760
    def LoadPrevious(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   761
        self.Config, self.ProcessVariables = cPickle.loads(self.Buffer.Previous())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   762
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   763
    def LoadNext(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   764
        self.Config, self.ProcessVariables = cPickle.loads(self.Buffer.Next())
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   765
    
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   766
    def GetBufferState(self):
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   767
        first = self.Buffer.IsFirst()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   768
        last = self.Buffer.IsLast()
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   769
        return not first, not last
f2cffda17d00 Split etherlab.py into multiple files
Laurent Bessard
parents:
diff changeset
   770