author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Mon, 25 Nov 2019 08:26:55 +0100 | |
branch | ethercat_from_kosmos |
changeset 2642 | 65701f40d970 |
parent 2641 | c9deff128c37 |
child 2643 | b98d9e08231f |
permissions | -rw-r--r-- |
2165
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
1 |
#!/usr/bin/env python |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
3 |
|
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
4 |
# This file is part of Beremiz |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
5 |
# |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
6 |
# Copyright (C) 2011-2014: Laurent BESSARD, Edouard TISSERANT |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
7 |
# RTES Lab : CRKim, JBLee, youcu |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
8 |
# Higen Motor : Donggu Kang |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
9 |
# |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2160
diff
changeset
|
11 |
|
2111 | 12 |
import os |
13 |
import cPickle |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
14 |
from lxml import etree |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
15 |
from copy import deepcopy |
2111 | 16 |
|
17 |
import wx |
|
18 |
||
19 |
from xmlclass import * |
|
20 |
||
21 |
from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
|
22 |
from ConfigTreeNode import ConfigTreeNode |
|
23 |
from dialogs import BrowseValuesLibraryDialog |
|
24 |
from IDEFrame import TITLE, FILEMENU, PROJECTTREE |
|
25 |
||
2152
e6946c298a42
Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents:
2149
diff
changeset
|
26 |
from EthercatSlave import _EthercatSlaveCTN, ExtractHexDecValue, GenerateHexDecValue, TYPECONVERSION, VARCLASSCONVERSION, _CommonSlave |
2111 | 27 |
from EthercatCFileGenerator import _EthercatCFileGenerator |
28 |
from ConfigEditor import MasterEditor |
|
29 |
from POULibrary import POULibrary |
|
30 |
||
31 |
try: |
|
32 |
from EthercatCIA402Slave import _EthercatCIA402SlaveCTN |
|
33 |
HAS_MCL = True |
|
34 |
except: |
|
35 |
HAS_MCL = False |
|
36 |
||
37 |
#-------------------------------------------------- |
|
38 |
# Remote Exec Etherlab Commands |
|
39 |
#-------------------------------------------------- |
|
40 |
||
41 |
SCAN_COMMAND = """ |
|
42 |
import commands |
|
43 |
result = commands.getoutput("ethercat slaves") |
|
44 |
slaves = [] |
|
45 |
for slave_line in result.splitlines(): |
|
46 |
chunks = slave_line.split() |
|
47 |
idx, pos, state, flag = chunks[:4] |
|
48 |
name = " ".join(chunks[4:]) |
|
49 |
alias, position = pos.split(":") |
|
50 |
slave = {"idx": int(idx), |
|
51 |
"alias": int(alias), |
|
52 |
"position": int(position), |
|
53 |
"name": name} |
|
54 |
details = commands.getoutput("ethercat slaves -p %d -v" % slave["idx"]) |
|
55 |
for details_line in details.splitlines(): |
|
56 |
details_line = details_line.strip() |
|
57 |
for header, param in [("Vendor Id:", "vendor_id"), |
|
58 |
("Product code:", "product_code"), |
|
59 |
("Revision number:", "revision_number")]: |
|
60 |
if details_line.startswith(header): |
|
61 |
slave[param] = details_line.split()[-1] |
|
62 |
break |
|
63 |
slaves.append(slave) |
|
64 |
returnVal = slaves |
|
65 |
""" |
|
66 |
||
67 |
#-------------------------------------------------- |
|
68 |
# Etherlab Specific Blocks Library |
|
69 |
#-------------------------------------------------- |
|
70 |
||
71 |
def GetLocalPath(filename): |
|
72 |
return os.path.join(os.path.split(__file__)[0], filename) |
|
73 |
||
74 |
class EtherlabLibrary(POULibrary): |
|
75 |
def GetLibraryPath(self): |
|
76 |
return GetLocalPath("pous.xml") |
|
77 |
||
78 |
def Generate_C(self, buildpath, varlist, IECCFLAGS): |
|
79 |
etherlab_ext_file = open(GetLocalPath("etherlab_ext.c"), 'r') |
|
80 |
etherlab_ext_code = etherlab_ext_file.read() |
|
81 |
etherlab_ext_file.close() |
|
82 |
||
83 |
Gen_etherlabfile_path = os.path.join(buildpath, "etherlab_ext.c") |
|
84 |
ethelabfile = open(Gen_etherlabfile_path,'w') |
|
85 |
ethelabfile.write(etherlab_ext_code) |
|
86 |
ethelabfile.close() |
|
87 |
||
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
88 |
try: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
89 |
return ((["etherlab_ext"], [(Gen_etherlabfile_path, IECCFLAGS)], True), "", |
2111 | 90 |
("runtime_etherlab.py", file(GetLocalPath("runtime_etherlab.py")))) |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
91 |
except: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
92 |
return ((["etherlab_ext"], [(Gen_etherlabfile_path, IECCFLAGS)], True), "", |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
93 |
("runtime_etherlab.pyc", file(GetLocalPath("runtime_etherlab.pyc")))) |
2111 | 94 |
|
95 |
#-------------------------------------------------- |
|
96 |
# Ethercat MASTER |
|
97 |
#-------------------------------------------------- |
|
98 |
||
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
99 |
EtherCATConfigParser = GenerateParserFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATConfig.xsd")) |
2111 | 100 |
|
101 |
def sort_commands(x, y): |
|
102 |
if x["Index"] == y["Index"]: |
|
103 |
return cmp(x["Subindex"], y["Subindex"]) |
|
104 |
return cmp(x["Index"], y["Index"]) |
|
105 |
||
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
106 |
cls = EtherCATConfigParser.GetElementClass("Slave", "Config") |
2111 | 107 |
if cls: |
108 |
||
109 |
def getType(self): |
|
110 |
slave_info = self.getInfo() |
|
111 |
return {"device_type": slave_info.getName(), |
|
112 |
"vendor": GenerateHexDecValue(slave_info.getVendorId()), |
|
113 |
"product_code": GenerateHexDecValue(slave_info.getProductCode(), 16), |
|
114 |
"revision_number": GenerateHexDecValue(slave_info.getRevisionNo(), 16)} |
|
115 |
setattr(cls, "getType", getType) |
|
116 |
||
117 |
def setType(self, type_infos): |
|
118 |
slave_info = self.getInfo() |
|
119 |
slave_info.setName(type_infos["device_type"]) |
|
120 |
slave_info.setVendorId(ExtractHexDecValue(type_infos["vendor"])) |
|
121 |
slave_info.setProductCode(ExtractHexDecValue(type_infos["product_code"])) |
|
122 |
slave_info.setRevisionNo(ExtractHexDecValue(type_infos["revision_number"])) |
|
123 |
setattr(cls, "setType", setType) |
|
124 |
||
125 |
def getInitCmds(self, create_default=False): |
|
126 |
Mailbox = self.getMailbox() |
|
127 |
if Mailbox is None: |
|
128 |
if create_default: |
|
129 |
self.addMailbox() |
|
130 |
Mailbox = self.getMailbox() |
|
131 |
else: |
|
132 |
return None |
|
133 |
CoE = Mailbox.getCoE() |
|
134 |
if CoE is None: |
|
135 |
if create_default: |
|
136 |
Mailbox.addCoE() |
|
137 |
CoE = Mailbox.getCoE() |
|
138 |
else: |
|
139 |
return None |
|
140 |
InitCmds = CoE.getInitCmds() |
|
141 |
if InitCmds is None and create_default: |
|
142 |
CoE.addInitCmds() |
|
143 |
InitCmds = CoE.getInitCmds() |
|
144 |
return InitCmds |
|
145 |
setattr(cls, "getInitCmds", getInitCmds) |
|
146 |
||
147 |
def getStartupCommands(self): |
|
148 |
pos = self.getInfo().getPhysAddr() |
|
149 |
InitCmds = self.getInitCmds() |
|
150 |
if InitCmds is None: |
|
151 |
return [] |
|
152 |
commands = [] |
|
153 |
for idx, InitCmd in enumerate(InitCmds.getInitCmd()): |
|
154 |
comment = InitCmd.getComment() |
|
155 |
if comment is None: |
|
156 |
comment = "" |
|
157 |
commands.append({ |
|
158 |
"command_idx": idx, |
|
159 |
"Position": pos, |
|
160 |
"Index": InitCmd.getIndex(), |
|
161 |
"Subindex": InitCmd.getSubIndex(), |
|
162 |
"Value": InitCmd.getData(), |
|
163 |
"Description": comment}) |
|
164 |
commands.sort(sort_commands) |
|
165 |
return commands |
|
166 |
setattr(cls, "getStartupCommands", getStartupCommands) |
|
167 |
||
168 |
def appendStartupCommand(self, command_infos): |
|
169 |
InitCmds = self.getInitCmds(True) |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
170 |
command = EtherCATConfigParser.CreateElement("InitCmd", "InitCmds", 1) |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
171 |
InitCmds.appendInitCmd(command) |
2111 | 172 |
command.setIndex(command_infos["Index"]) |
173 |
command.setSubIndex(command_infos["Subindex"]) |
|
174 |
command.setData(command_infos["Value"]) |
|
175 |
command.setComment(command_infos["Description"]) |
|
176 |
return len(InitCmds.getInitCmd()) - 1 |
|
177 |
setattr(cls, "appendStartupCommand", appendStartupCommand) |
|
178 |
||
179 |
def setStartupCommand(self, command_infos): |
|
180 |
InitCmds = self.getInitCmds() |
|
181 |
if InitCmds is not None: |
|
182 |
commands = InitCmds.getInitCmd() |
|
183 |
if command_infos["command_idx"] < len(commands): |
|
184 |
command = commands[command_infos["command_idx"]] |
|
185 |
command.setIndex(command_infos["Index"]) |
|
186 |
command.setSubIndex(command_infos["Subindex"]) |
|
187 |
command.setData(command_infos["Value"]) |
|
188 |
command.setComment(command_infos["Description"]) |
|
189 |
setattr(cls, "setStartupCommand", setStartupCommand) |
|
190 |
||
191 |
def removeStartupCommand(self, command_idx): |
|
192 |
InitCmds = self.getInitCmds() |
|
193 |
if InitCmds is not None: |
|
194 |
if command_idx < len(InitCmds.getInitCmd()): |
|
195 |
InitCmds.removeInitCmd(command_idx) |
|
196 |
setattr(cls, "removeStartupCommand", removeStartupCommand) |
|
197 |
||
198 |
ProcessVariablesXSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
199 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
200 |
<xsd:element name="ProcessVariables"> |
|
201 |
<xsd:complexType> |
|
202 |
<xsd:sequence> |
|
203 |
<xsd:element name="variable" minOccurs="0" maxOccurs="unbounded"> |
|
204 |
<xsd:complexType> |
|
205 |
<xsd:sequence> |
|
206 |
<xsd:element name="ReadFrom" type="LocationDesc" minOccurs="0"/> |
|
207 |
<xsd:element name="WriteTo" type="LocationDesc" minOccurs="0"/> |
|
208 |
</xsd:sequence> |
|
209 |
<xsd:attribute name="Name" type="xsd:string" use="required"/> |
|
210 |
<xsd:attribute name="Comment" type="xsd:string" use="required"/> |
|
211 |
</xsd:complexType> |
|
212 |
</xsd:element> |
|
213 |
</xsd:sequence> |
|
214 |
</xsd:complexType> |
|
215 |
</xsd:element> |
|
216 |
<xsd:complexType name="LocationDesc"> |
|
217 |
<xsd:attribute name="Position" type="xsd:integer" use="required"/> |
|
218 |
<xsd:attribute name="Index" type="xsd:integer" use="required"/> |
|
219 |
<xsd:attribute name="SubIndex" type="xsd:integer" use="required"/> |
|
220 |
</xsd:complexType> |
|
221 |
</xsd:schema> |
|
222 |
""" |
|
223 |
||
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
224 |
ProcessVariablesParser = GenerateParserFromXSDstring(ProcessVariablesXSD) |
2111 | 225 |
|
226 |
class _EthercatCTN: |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
227 |
|
2111 | 228 |
CTNChildrenTypes = [("EthercatSlave", _EthercatSlaveCTN, "Ethercat Slave")] |
229 |
if HAS_MCL: |
|
230 |
CTNChildrenTypes.append(("EthercatCIA402Slave", _EthercatCIA402SlaveCTN, "Ethercat CIA402 Slave")) |
|
231 |
EditorType = MasterEditor |
|
232 |
||
233 |
def __init__(self): |
|
234 |
config_filepath = self.ConfigFileName() |
|
235 |
config_is_saved = False |
|
2160
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
236 |
self.Config = None |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
237 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
238 |
#if os.path.isfile(config_filepath): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
239 |
# config_xmlfile = open(config_filepath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
240 |
# try: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
241 |
# self.Config, error = \ |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
242 |
# EtherCATConfigParser.LoadXMLString(config_xmlfile.read()) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
243 |
# if error is None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
244 |
# config_is_saved = True |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
245 |
# except Exception, e: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
246 |
# error = e.message |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
247 |
# config_xmlfile.close() |
2160
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
248 |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
249 |
# if error is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
250 |
# self.GetCTRoot().logger.write_error( |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
251 |
# _("Couldn't load %s network configuration file.") % CTNName) |
2160
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
252 |
|
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
253 |
if self.Config is None: |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
254 |
self.Config = EtherCATConfigParser.CreateElement("EtherCATConfig") |
2111 | 255 |
|
256 |
process_filepath = self.ProcessVariablesFileName() |
|
257 |
process_is_saved = False |
|
2160
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
258 |
self.ProcessVariables = None |
2111 | 259 |
if os.path.isfile(process_filepath): |
260 |
process_xmlfile = open(process_filepath, 'r') |
|
2160
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
261 |
try: |
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
262 |
self.ProcessVariables, error = \ |
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
263 |
ProcessVariablesParser.LoadXMLString(process_xmlfile.read()) |
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
264 |
if error is None: |
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
265 |
process_is_saved = True |
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
266 |
except Exception, e: |
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
267 |
error = e.message |
2111 | 268 |
process_xmlfile.close() |
269 |
||
2160
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
270 |
if error is not None: |
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
271 |
self.GetCTRoot().logger.write_error( |
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
272 |
_("Couldn't load %s network process variables file.") % CTNName) |
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
273 |
|
75349c51a34b
Added support for loading XML file even if not following XSD schema (but still following XML syntax), warning user of errors in XML file
Laurent Bessard
parents:
2157
diff
changeset
|
274 |
if self.ProcessVariables is None: |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
275 |
self.ProcessVariables = ProcessVariablesParser.CreateElement("ProcessVariables") |
2111 | 276 |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
277 |
#if config_is_saved and process_is_saved: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
278 |
if process_is_saved: |
2111 | 279 |
self.CreateBuffer(True) |
280 |
else: |
|
281 |
self.CreateBuffer(False) |
|
282 |
self.OnCTNSave() |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
283 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
284 |
if os.path.isfile(config_filepath): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
285 |
config_xmlfile = open(config_filepath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
286 |
try: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
287 |
self.Config, error = \ |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
288 |
EtherCATConfigParser.LoadXMLString(config_xmlfile.read()) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
289 |
if error is None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
290 |
config_is_saved = True |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
291 |
except Exception, e: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
292 |
error = e.message |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
293 |
config_xmlfile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
294 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
295 |
if error is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
296 |
self.GetCTRoot().logger.write_error( |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
297 |
_("Couldn't load %s network configuration file.") % CTNName) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
298 |
|
2152
e6946c298a42
Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents:
2149
diff
changeset
|
299 |
# ----------- call ethercat mng. function -------------- |
e6946c298a42
Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents:
2149
diff
changeset
|
300 |
self.CommonMethod = _CommonSlave(self) |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
301 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
302 |
###################################### Test Section ######################################### |
2111 | 303 |
|
2149
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2147
diff
changeset
|
304 |
def GetIconName(self): |
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2147
diff
changeset
|
305 |
return "Ethercat" |
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2147
diff
changeset
|
306 |
|
2111 | 307 |
def GetContextualMenuItems(self): |
308 |
return [("Add Ethercat Slave", "Add Ethercat Slave to Master", self.OnAddEthercatSlave)] |
|
309 |
||
310 |
def OnAddEthercatSlave(self, event): |
|
311 |
app_frame = self.GetCTRoot().AppFrame |
|
312 |
dialog = BrowseValuesLibraryDialog(app_frame, |
|
313 |
"Ethercat Slave Type", self.GetSlaveTypesLibrary()) |
|
314 |
if dialog.ShowModal() == wx.ID_OK: |
|
315 |
type_infos = dialog.GetValueInfos() |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
316 |
device, module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 317 |
if device is not None: |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
318 |
# device.GetProfileNumbers() return type is string |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
319 |
# _EthercatCIA402SlaveCTN.NODE_PROFILE change to string |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
320 |
# 151224 jblee |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
321 |
if HAS_MCL and str(_EthercatCIA402SlaveCTN.NODE_PROFILE) in device.GetProfileNumbers(): |
2111 | 322 |
ConfNodeType = "EthercatCIA402Slave" |
323 |
else: |
|
324 |
ConfNodeType = "EthercatSlave" |
|
325 |
new_child = self.CTNAddChild("%s_0" % ConfNodeType, ConfNodeType) |
|
326 |
new_child.SetParamsAttribute("SlaveParams.Type", type_infos) |
|
327 |
self.CTNRequestSave() |
|
328 |
new_child._OpenView() |
|
329 |
app_frame._Refresh(TITLE, FILEMENU, PROJECTTREE) |
|
330 |
dialog.Destroy() |
|
331 |
||
332 |
def ExtractHexDecValue(self, value): |
|
333 |
return ExtractHexDecValue(value) |
|
334 |
||
335 |
def GetSizeOfType(self, type): |
|
336 |
return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) |
|
337 |
||
338 |
def ConfigFileName(self): |
|
339 |
return os.path.join(self.CTNPath(), "config.xml") |
|
340 |
||
341 |
def ProcessVariablesFileName(self): |
|
342 |
return os.path.join(self.CTNPath(), "process_variables.xml") |
|
343 |
||
344 |
def FilterSlave(self, slave, vendor=None, slave_pos=None, slave_profile=None): |
|
345 |
if slave_pos is not None and slave.getInfo().getPhysAddr() != slave_pos: |
|
346 |
return False |
|
347 |
type_infos = slave.getType() |
|
348 |
if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor: |
|
349 |
return False |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
350 |
device, module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 351 |
if slave_profile is not None and slave_profile not in device.GetProfileNumbers(): |
352 |
return False |
|
353 |
return True |
|
354 |
||
2124
1f2c3fdd70d0
Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents:
2113
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
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
|
359 |
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
|
360 |
|
2111 | 361 |
def GetSlaves(self, vendor=None, slave_pos=None, slave_profile=None): |
362 |
slaves = [] |
|
363 |
for slave in self.Config.getConfig().getSlave(): |
|
364 |
if self.FilterSlave(slave, vendor, slave_pos, slave_profile): |
|
365 |
slaves.append(slave.getInfo().getPhysAddr()) |
|
366 |
slaves.sort() |
|
367 |
return slaves |
|
368 |
||
369 |
def GetSlave(self, slave_pos): |
|
370 |
for slave in self.Config.getConfig().getSlave(): |
|
371 |
slave_info = slave.getInfo() |
|
372 |
if slave_info.getPhysAddr() == slave_pos: |
|
373 |
return slave |
|
374 |
return None |
|
375 |
||
376 |
def GetStartupCommands(self, vendor=None, slave_pos=None, slave_profile=None): |
|
377 |
commands = [] |
|
378 |
for slave in self.Config.getConfig().getSlave(): |
|
379 |
if self.FilterSlave(slave, vendor, slave_pos, slave_profile): |
|
380 |
commands.append((slave.getInfo().getPhysAddr(), slave.getStartupCommands())) |
|
381 |
commands.sort() |
|
382 |
return reduce(lambda x, y: x + y[1], commands, []) |
|
383 |
||
384 |
def AppendStartupCommand(self, command_infos): |
|
385 |
slave = self.GetSlave(command_infos["Position"]) |
|
386 |
if slave is not None: |
|
387 |
command_idx = slave.appendStartupCommand(command_infos) |
|
388 |
self.BufferModel() |
|
389 |
return command_idx |
|
390 |
return None |
|
391 |
||
392 |
def SetStartupCommandInfos(self, command_infos): |
|
393 |
slave = self.GetSlave(command_infos["Position"]) |
|
394 |
if slave is not None: |
|
395 |
slave.setStartupCommand(command_infos) |
|
396 |
self.BufferModel() |
|
397 |
||
398 |
def RemoveStartupCommand(self, slave_pos, command_idx, buffer=True): |
|
399 |
slave = self.GetSlave(slave_pos) |
|
400 |
if slave is not None: |
|
401 |
slave.removeStartupCommand(command_idx) |
|
402 |
if buffer: |
|
403 |
self.BufferModel() |
|
404 |
||
405 |
def SetProcessVariables(self, variables): |
|
406 |
vars = [] |
|
407 |
for var in variables: |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
408 |
variable = ProcessVariablesParser.CreateElement("variable", "ProcessVariables") |
2111 | 409 |
variable.setName(var["Name"]) |
410 |
variable.setComment(var["Description"]) |
|
411 |
if var["ReadFrom"] != "": |
|
412 |
position, index, subindex = var["ReadFrom"] |
|
413 |
if variable.getReadFrom() is None: |
|
414 |
variable.addReadFrom() |
|
415 |
read_from = variable.getReadFrom() |
|
416 |
read_from.setPosition(position) |
|
417 |
read_from.setIndex(index) |
|
418 |
read_from.setSubIndex(subindex) |
|
419 |
elif variable.getReadFrom() is not None: |
|
420 |
variable.deleteReadFrom() |
|
421 |
if var["WriteTo"] != "": |
|
422 |
position, index, subindex = var["WriteTo"] |
|
423 |
if variable.getWriteTo() is None: |
|
424 |
variable.addWriteTo() |
|
425 |
write_to = variable.getWriteTo() |
|
426 |
write_to.setPosition(position) |
|
427 |
write_to.setIndex(index) |
|
428 |
write_to.setSubIndex(subindex) |
|
429 |
elif variable.getWriteTo() is not None: |
|
430 |
variable.deleteWriteTo() |
|
431 |
vars.append(variable) |
|
432 |
self.ProcessVariables.setvariable(vars) |
|
433 |
self.BufferModel() |
|
434 |
||
435 |
def GetProcessVariables(self): |
|
436 |
variables = [] |
|
437 |
idx = 0 |
|
438 |
for variable in self.ProcessVariables.getvariable(): |
|
439 |
var = {"Name": variable.getName(), |
|
440 |
"Number": idx, |
|
441 |
"Description": variable.getComment()} |
|
442 |
read_from = variable.getReadFrom() |
|
443 |
if read_from is not None: |
|
444 |
var["ReadFrom"] = (read_from.getPosition(), |
|
445 |
read_from.getIndex(), |
|
446 |
read_from.getSubIndex()) |
|
447 |
else: |
|
448 |
var["ReadFrom"] = "" |
|
449 |
write_to = variable.getWriteTo() |
|
450 |
if write_to is not None: |
|
451 |
var["WriteTo"] = (write_to.getPosition(), |
|
452 |
write_to.getIndex(), |
|
453 |
write_to.getSubIndex()) |
|
454 |
else: |
|
455 |
var["WriteTo"] = "" |
|
456 |
variables.append(var) |
|
457 |
idx += 1 |
|
458 |
return variables |
|
459 |
||
460 |
def _ScanNetwork(self): |
|
461 |
app_frame = self.GetCTRoot().AppFrame |
|
462 |
||
463 |
execute = True |
|
464 |
if len(self.Children) > 0: |
|
465 |
dialog = wx.MessageDialog(app_frame, |
|
466 |
_("The current network configuration will be deleted.\nDo you want to continue?"), |
|
467 |
_("Scan Network"), |
|
468 |
wx.YES_NO|wx.ICON_QUESTION) |
|
469 |
execute = dialog.ShowModal() == wx.ID_YES |
|
470 |
dialog.Destroy() |
|
471 |
||
472 |
if execute: |
|
473 |
error, returnVal = self.RemoteExec(SCAN_COMMAND, returnVal = None) |
|
474 |
if error != 0: |
|
475 |
dialog = wx.MessageDialog(app_frame, returnVal, "Error", wx.OK|wx.ICON_ERROR) |
|
476 |
dialog.ShowModal() |
|
477 |
dialog.Destroy() |
|
478 |
elif returnVal is not None: |
|
479 |
for child in self.IECSortedChildren(): |
|
480 |
self._doRemoveChild(child) |
|
481 |
||
482 |
for slave in returnVal: |
|
483 |
type_infos = { |
|
484 |
"vendor": slave["vendor_id"], |
|
485 |
"product_code": slave["product_code"], |
|
486 |
"revision_number":slave["revision_number"], |
|
487 |
} |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
488 |
device, module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 489 |
if device is not None: |
490 |
if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers(): |
|
491 |
CTNType = "EthercatCIA402Slave" |
|
492 |
else: |
|
493 |
CTNType = "EthercatSlave" |
|
494 |
self.CTNAddChild("slave%s" % slave["idx"], CTNType, slave["idx"]) |
|
495 |
self.SetSlaveAlias(slave["idx"], slave["alias"]) |
|
496 |
type_infos["device_type"] = device.getType().getcontent() |
|
497 |
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
|
498 |
|
32255ca50fb0
Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents:
2124
diff
changeset
|
499 |
if app_frame: |
32255ca50fb0
Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents:
2124
diff
changeset
|
500 |
app_frame.RefreshProjectTree() |
32255ca50fb0
Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents:
2124
diff
changeset
|
501 |
|
2111 | 502 |
def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0): |
503 |
""" |
|
504 |
Create the confnodes that may be added as child to this node self |
|
505 |
@param CTNType: string desining the confnode class name (get name from CTNChildrenTypes) |
|
506 |
@param CTNName: string for the name of the confnode instance |
|
507 |
""" |
|
508 |
newConfNodeOpj = ConfigTreeNode.CTNAddChild(self, CTNName, CTNType, IEC_Channel) |
|
509 |
||
510 |
slave = self.GetSlave(newConfNodeOpj.BaseParams.getIEC_Channel()) |
|
511 |
if slave is None: |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
512 |
slave = EtherCATConfigParser.CreateElement("Slave", "Config") |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
513 |
self.Config.getConfig().appendSlave(slave) |
2111 | 514 |
slave_infos = slave.getInfo() |
515 |
slave_infos.setName("undefined") |
|
516 |
slave_infos.setPhysAddr(newConfNodeOpj.BaseParams.getIEC_Channel()) |
|
517 |
slave_infos.setAutoIncAddr(0) |
|
518 |
self.BufferModel() |
|
519 |
self.OnCTNSave() |
|
520 |
||
521 |
return newConfNodeOpj |
|
522 |
||
523 |
def _doRemoveChild(self, CTNInstance): |
|
524 |
slave_pos = CTNInstance.GetSlavePos() |
|
525 |
config = self.Config.getConfig() |
|
526 |
for idx, slave in enumerate(config.getSlave()): |
|
527 |
slave_infos = slave.getInfo() |
|
528 |
if slave_infos.getPhysAddr() == slave_pos: |
|
529 |
config.removeSlave(idx) |
|
530 |
self.BufferModel() |
|
531 |
self.OnCTNSave() |
|
532 |
ConfigTreeNode._doRemoveChild(self, CTNInstance) |
|
533 |
||
534 |
def SetSlavePosition(self, slave_pos, new_pos): |
|
535 |
slave = self.GetSlave(slave_pos) |
|
536 |
if slave is not None: |
|
537 |
slave_info = slave.getInfo() |
|
538 |
slave_info.setPhysAddr(new_pos) |
|
539 |
for variable in self.ProcessVariables.getvariable(): |
|
540 |
read_from = variable.getReadFrom() |
|
541 |
if read_from is not None and read_from.getPosition() == slave_pos: |
|
542 |
read_from.setPosition(new_pos) |
|
543 |
write_to = variable.getWriteTo() |
|
544 |
if write_to is not None and write_to.getPosition() == slave_pos: |
|
545 |
write_to.setPosition(new_pos) |
|
546 |
self.CreateBuffer(True) |
|
2147
a8b095de63e8
Fix bug in when moving Ethercat slaves fixed
Laurent Bessard
parents:
2141
diff
changeset
|
547 |
self.CTNRequestSave() |
2111 | 548 |
if self._View is not None: |
549 |
self._View.RefreshView() |
|
550 |
self._View.RefreshBuffer() |
|
551 |
||
552 |
def GetSlaveAlias(self, slave_pos): |
|
553 |
slave = self.GetSlave(slave_pos) |
|
554 |
if slave is not None: |
|
555 |
slave_info = slave.getInfo() |
|
556 |
return slave_info.getAutoIncAddr() |
|
557 |
return None |
|
558 |
||
559 |
def SetSlaveAlias(self, slave_pos, alias): |
|
560 |
slave = self.GetSlave(slave_pos) |
|
561 |
if slave is not None: |
|
562 |
slave_info = slave.getInfo() |
|
563 |
slave_info.setAutoIncAddr(alias) |
|
564 |
self.BufferModel() |
|
565 |
||
566 |
def GetSlaveType(self, slave_pos): |
|
567 |
slave = self.GetSlave(slave_pos) |
|
568 |
if slave is not None: |
|
569 |
return slave.getType() |
|
570 |
return None |
|
571 |
||
572 |
def SetSlaveType(self, slave_pos, type_infos): |
|
573 |
slave = self.GetSlave(slave_pos) |
|
574 |
if slave is not None: |
|
575 |
slave.setType(type_infos) |
|
576 |
self.BufferModel() |
|
577 |
||
578 |
def GetSlaveInfos(self, slave_pos): |
|
579 |
slave = self.GetSlave(slave_pos) |
|
580 |
if slave is not None: |
|
581 |
type_infos = slave.getType() |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
582 |
device, module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 583 |
if device is not None: |
584 |
infos = type_infos.copy() |
|
585 |
infos.update({"physics": device.getPhysics(), |
|
586 |
"sync_managers": device.GetSyncManagers(), |
|
587 |
"entries": self.GetSlaveVariables(device)}) |
|
588 |
return infos |
|
589 |
return None |
|
590 |
||
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
591 |
""" |
2111 | 592 |
def GetSlaveVariables(self, slave_pos=None, limits=None, device=None): |
593 |
if device is None and slave_pos is not None: |
|
594 |
slave = self.GetSlave(slave_pos) |
|
595 |
if slave is not None: |
|
596 |
type_infos = slave.getType() |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
597 |
device, module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 598 |
if device is not None: |
599 |
entries = device.GetEntriesList(limits) |
|
600 |
entries_list = entries.items() |
|
601 |
entries_list.sort() |
|
602 |
entries = [] |
|
603 |
current_index = None |
|
604 |
current_entry = None |
|
605 |
for (index, subindex), entry in entries_list: |
|
606 |
entry["children"] = [] |
|
607 |
if slave_pos is not None: |
|
608 |
entry["Position"] = str(slave_pos) |
|
609 |
entry |
|
610 |
if index != current_index: |
|
611 |
current_index = index |
|
612 |
current_entry = entry |
|
613 |
entries.append(entry) |
|
614 |
elif current_entry is not None: |
|
615 |
current_entry["children"].append(entry) |
|
616 |
else: |
|
617 |
entries.append(entry) |
|
618 |
return entries |
|
619 |
return [] |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
620 |
#""" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
621 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
622 |
def GetSlaveVariables(self, slave_pos=None, limits=None, device=None, module=None): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
623 |
# add jblee |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
624 |
files = os.listdir(self.CTNPath()) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
625 |
moduleNames = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
626 |
modulePos = 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
627 |
for file in files: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
628 |
filepath = os.path.join(self.CTNPath(), file) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
629 |
if os.path.isdir(filepath): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
630 |
MDPFilePath = os.path.join(filepath, "DataForMDP.txt") |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
631 |
CheckConfNodePath = os.path.join(filepath, "baseconfnode.xml") |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
632 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
633 |
try : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
634 |
moduleDataFile = open(MDPFilePath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
635 |
confNodeFile = open(CheckConfNodePath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
636 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
637 |
lines = moduleDataFile.readlines() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
638 |
checklines = confNodeFile.readlines() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
639 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
640 |
moduleDataFile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
641 |
confNodeFile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
642 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
643 |
module_info = self.GetModuleEntryList() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
644 |
# checklines(ex) : <BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="EthercatSlave_0"/> |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
645 |
# checklines[1].split() : [<BaseParams, xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
646 |
# IEC_Channel="0", Name="EthercatSlave_0"/>] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
647 |
# checklines[1].split()[2] : IEC_Channel="0" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
648 |
# checklines[1].split()[2].split("\"") = [IEC_Channel=, 0, ] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
649 |
pos_check = int(checklines[1].split()[2].split("\"")[1]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
650 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
651 |
if slave_pos != pos_check: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
652 |
continue |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
653 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
654 |
for line in lines: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
655 |
if line == "\n": |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
656 |
continue |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
657 |
# module_name : ST-1214, ST-2314, ... |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
658 |
# if user add module => ST-1214 3EA, ST-2314 3EA |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
659 |
# each result_module_name : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
660 |
# (ST-1214, Module 1), (ST-1214, Module 2), (ST-1214, Module 3) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
661 |
# (ST-2314, Module 4), (ST-2314, Module 5), (ST-2314, Module 6) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
662 |
module_name = line.split()[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
663 |
result_module_name = module_name + ", Module %d" % modulePos |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
664 |
moduleNames.append(result_module_name) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
665 |
modulePos += 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
666 |
except : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
667 |
pass |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
668 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
669 |
if device is None and slave_pos is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
670 |
slave = self.GetSlave(slave_pos) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
671 |
if slave is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
672 |
type_infos = slave.getType() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
673 |
device, module_extra_params = self.GetModuleInfos(type_infos) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
674 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
675 |
if device is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
676 |
# Test OD |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
677 |
entries = device.GetEntriesList(limits) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
678 |
#entries = self.CTNParent.GetEntriesList() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
679 |
entries_list = entries.items() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
680 |
entries_list.sort() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
681 |
entries = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
682 |
current_index = None |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
683 |
current_entry = None |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
684 |
for (index, subindex), entry in entries_list: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
685 |
entry["children"] = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
686 |
if slave_pos is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
687 |
entry["Position"] = str(slave_pos) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
688 |
entry |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
689 |
if index != current_index: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
690 |
current_index = index |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
691 |
current_entry = entry |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
692 |
entries.append(entry) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
693 |
elif current_entry is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
694 |
current_entry["children"].append(entry) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
695 |
else: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
696 |
entries.append(entry) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
697 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
698 |
increment = self.CTNParent.GetModuleIncrement()[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
699 |
count = 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
700 |
#print module_info |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
701 |
# moduleNameAndPos : (ST-1214, Module 1), (ST-1214, Module 2), ... , |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
702 |
# moduleNameAndPos.split(",") : ["ST-1214", " Module 1"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
703 |
# moduleNameAndPos.split(",")[0] : "ST-1214" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
704 |
for moduleNameAndPos in moduleNames: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
705 |
moduleName = moduleNameAndPos.split(",")[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
706 |
modulePosName = moduleNameAndPos.split(",")[1] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
707 |
idx_increment = int(increment) * count |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
708 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
709 |
for MDP_entry in module_info.get(moduleName): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
710 |
LocalMDPEntry = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
711 |
#print MDP_entry |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
712 |
local_idx = MDP_entry["Index"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
713 |
if ExtractHexDecValue(local_idx) == 0: #and local_idx[0] == "#": |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
714 |
temp_index = ExtractHexDecValue(local_idx) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
715 |
else : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
716 |
temp_index = ExtractHexDecValue(MDP_entry["Index"]) + idx_increment |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
717 |
#temp_index = ExtractHexDecValue(MDP_entry["Index"]) + idx_increment |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
718 |
entry_index = hex(temp_index) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
719 |
entry_subidx = MDP_entry["SubIndex"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
720 |
entry_name = MDP_entry["Name"] + ", " + " " + \ |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
721 |
moduleName + " - " + modulePosName |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
722 |
entry_type = MDP_entry["Type"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
723 |
entry_bitsize = MDP_entry["BitSize"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
724 |
entry_access = MDP_entry["Access"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
725 |
mapping_type = MDP_entry["PDOMapping"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
726 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
727 |
LocalMDPEntry.append({ |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
728 |
"Index": entry_index, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
729 |
"SubIndex": entry_subidx, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
730 |
"Name": entry_name, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
731 |
"Type": entry_type, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
732 |
"BitSize": entry_bitsize, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
733 |
"Access": entry_access, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
734 |
"PDOMapping": mapping_type, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
735 |
"children": ""}) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
736 |
entries.append(LocalMDPEntry[0]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
737 |
count += 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
738 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
739 |
#print entries |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
740 |
return entries |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
741 |
return [] |
2111 | 742 |
|
743 |
def GetSlaveVariableDataType(self, slave_pos, index, subindex): |
|
744 |
slave = self.GetSlave(slave_pos) |
|
745 |
if slave is not None: |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
746 |
device, module_extra_params = self.GetModuleInfos(slave.getType()) |
2111 | 747 |
if device is not None: |
748 |
entries = device.GetEntriesList() |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
749 |
#entries = self.CTNParent.GetEntriesList() |
2111 | 750 |
entry_infos = entries.get((index, subindex)) |
751 |
if entry_infos is not None: |
|
752 |
return entry_infos["Type"] |
|
753 |
return None |
|
754 |
||
755 |
def GetNodesVariables(self, vendor=None, slave_pos=None, slave_profile=None, limits=None): |
|
756 |
entries = [] |
|
757 |
for slave_position in self.GetSlaves(): |
|
758 |
if slave_pos is not None and slave_position != slave_pos: |
|
759 |
continue |
|
760 |
slave = self.GetSlave(slave_position) |
|
761 |
type_infos = slave.getType() |
|
762 |
if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor: |
|
763 |
continue |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
764 |
device, module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 765 |
if slave_profile is not None and slave_profile not in device.GetProfileNumbers(): |
766 |
continue |
|
767 |
entries.extend(self.GetSlaveVariables(slave_position, limits, device)) |
|
768 |
return entries |
|
769 |
||
770 |
def GetModuleInfos(self, type_infos): |
|
771 |
return self.CTNParent.GetModuleInfos(type_infos) |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
772 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
773 |
# add jblee |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
774 |
def GetModuleEntryList(self): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
775 |
return self.CTNParent.GetModuleEntryList() |
2111 | 776 |
|
777 |
def GetSlaveTypesLibrary(self, profile_filter=None): |
|
778 |
return self.CTNParent.GetModulesLibrary(profile_filter) |
|
779 |
||
780 |
def GetLibraryVendors(self): |
|
781 |
return self.CTNParent.GetVendors() |
|
782 |
||
783 |
def GetDeviceLocationTree(self, slave_pos, current_location, device_name): |
|
784 |
slave = self.GetSlave(slave_pos) |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
785 |
vars = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
786 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
787 |
# add jblee |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
788 |
files = os.listdir(self.CTNPath()) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
789 |
moduleNames = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
790 |
modulePos = 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
791 |
for file in files: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
792 |
filepath = os.path.join(self.CTNPath(), file) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
793 |
if os.path.isdir(filepath): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
794 |
MDPFilePath = os.path.join(filepath, "DataForMDP.txt") |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
795 |
CheckConfNodePath = os.path.join(filepath, "baseconfnode.xml") |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
796 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
797 |
try : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
798 |
moduleDataFile = open(MDPFilePath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
799 |
confNodeFile = open(CheckConfNodePath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
800 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
801 |
lines = moduleDataFile.readlines() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
802 |
checklines = confNodeFile.readlines() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
803 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
804 |
moduleDataFile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
805 |
confNodeFile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
806 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
807 |
module_info = self.GetModuleEntryList() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
808 |
# checklines(ex) : <BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="EthercatSlave_0"/> |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
809 |
# checklines[1].split() : [<BaseParams, xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
810 |
# IEC_Channel="0", Name="EthercatSlave_0"/>] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
811 |
# checklines[1].split()[2] : IEC_Channel="0" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
812 |
# checklines[1].split()[2].split("\"") = [IEC_Channel=, 0, ] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
813 |
pos_check = int(checklines[1].split()[2].split("\"")[1]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
814 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
815 |
if slave_pos != pos_check: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
816 |
continue |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
817 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
818 |
for line in lines: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
819 |
if line == "\n": |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
820 |
continue |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
821 |
# module_name : ST-1214, ST-2314, ... |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
822 |
# if user add module => ST-1214 3EA, ST-2314 3EA |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
823 |
# each result_module_name : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
824 |
# (ST-1214, Module 1), (ST-1214, Module 2), (ST-1214, Module 3) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
825 |
# (ST-2314, Module 4), (ST-2314, Module 5), (ST-2314, Module 6) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
826 |
module_name = line.split()[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
827 |
result_module_name = module_name + ", Module %d" % modulePos |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
828 |
moduleNames.append(result_module_name) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
829 |
modulePos += 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
830 |
except : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
831 |
pass |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
832 |
|
2111 | 833 |
if slave is not None: |
834 |
type_infos = slave.getType() |
|
835 |
||
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
836 |
device, module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 837 |
if device is not None: |
838 |
sync_managers = [] |
|
839 |
for sync_manager in device.getSm(): |
|
840 |
sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte()) |
|
841 |
sync_manager_direction = sync_manager_control_byte & 0x0c |
|
842 |
if sync_manager_direction: |
|
843 |
sync_managers.append(LOCATION_VAR_OUTPUT) |
|
844 |
else: |
|
845 |
sync_managers.append(LOCATION_VAR_INPUT) |
|
846 |
||
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
847 |
# Test OD |
2111 | 848 |
entries = device.GetEntriesList().items() |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
849 |
#entries = self.CTNParent.GetEntriesList().items() |
2111 | 850 |
entries.sort() |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
851 |
|
2111 | 852 |
for (index, subindex), entry in entries: |
853 |
var_size = self.GetSizeOfType(entry["Type"]) |
|
854 |
if var_size is not None: |
|
855 |
var_class = VARCLASSCONVERSION.get(entry["PDOMapping"], None) |
|
856 |
if var_class is not None: |
|
857 |
if var_class == LOCATION_VAR_INPUT: |
|
858 |
var_dir = "%I" |
|
859 |
else: |
|
860 |
var_dir = "%Q" |
|
861 |
||
862 |
vars.append({"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry["Name"]), |
|
863 |
"type": var_class, |
|
864 |
"size": var_size, |
|
865 |
"IEC_type": entry["Type"], |
|
866 |
"var_name": "%s_%4.4x_%2.2x" % ("_".join(device_name.split()), index, subindex), |
|
867 |
"location": "%s%s%s"%(var_dir, var_size, ".".join(map(str, current_location + |
|
868 |
(index, subindex)))), |
|
869 |
"description": "", |
|
870 |
"children": []}) |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
871 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
872 |
# add jblee for MDP |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
873 |
if not entries : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
874 |
increment = self.CTNParent.GetModuleIncrement()[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
875 |
count = 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
876 |
for moduleNameAndPos in moduleNames: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
877 |
moduleName = moduleNameAndPos.split(",")[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
878 |
idx_increment = int(increment) * count |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
879 |
for MDP_entry in module_info.get(moduleName): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
880 |
local_idx = MDP_entry["Index"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
881 |
if ExtractHexDecValue(local_idx) != 0 and local_idx[0] == "#": |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
882 |
index = ExtractHexDecValue(local_idx) + idx_increment |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
883 |
else : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
884 |
index = ExtractHexDecValue(MDP_entry["Index"]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
885 |
subindex = int(MDP_entry["SubIndex"]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
886 |
var_class = VARCLASSCONVERSION.get(MDP_entry["PDOMapping"], None) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
887 |
if var_class is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
888 |
if var_class == LOCATION_VAR_INPUT: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
889 |
var_dir = "%I" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
890 |
else: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
891 |
var_dir = "%Q" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
892 |
var_size = self.GetSizeOfType(MDP_entry["Type"]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
893 |
result_name = MDP_entry["Name"] + ", " + moduleNameAndPos |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
894 |
vars.append({"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, result_name), |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
895 |
"type": var_class, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
896 |
"size": var_size, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
897 |
"IEC_type": MDP_entry["Type"], |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
898 |
"var_name": "%s_%4.4x_%2.2x" % ("_".join(moduleName.split()), index, subindex), |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
899 |
"location": "%s%s%s"%(var_dir, var_size, ".".join(map(str, current_location + |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
900 |
(index, subindex)))), |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
901 |
"description": "", |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
902 |
"children": []}) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
903 |
count += 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
904 |
|
2111 | 905 |
return vars |
906 |
||
907 |
def CTNTestModified(self): |
|
908 |
return self.ChangesToSave or not self.ModelIsSaved() |
|
909 |
||
2133 | 910 |
def OnCTNSave(self, from_project_path=None): |
2111 | 911 |
config_filepath = self.ConfigFileName() |
912 |
config_xmlfile = open(config_filepath,"w") |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
913 |
config_xmlfile.write(etree.tostring( |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
914 |
self.Config, |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
915 |
pretty_print=True, |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
916 |
xml_declaration=True, |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
917 |
encoding='utf-8')) |
2111 | 918 |
config_xmlfile.close() |
919 |
||
920 |
process_filepath = self.ProcessVariablesFileName() |
|
921 |
||
922 |
process_xmlfile = open(process_filepath,"w") |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
923 |
process_xmlfile.write(etree.tostring( |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
924 |
self.ProcessVariables, |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
925 |
pretty_print=True, |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
926 |
xml_declaration=True, |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
927 |
encoding='utf-8')) |
2111 | 928 |
process_xmlfile.close() |
929 |
||
930 |
self.Buffer.CurrentSaved() |
|
931 |
return True |
|
932 |
||
933 |
def GetProcessVariableName(self, location, var_type): |
|
934 |
return "__M%s_%s" % (self.GetSizeOfType(var_type), "_".join(map(str, location))) |
|
935 |
||
936 |
def _Generate_C(self, buildpath, locations): |
|
937 |
current_location = self.GetCurrentLocation() |
|
938 |
# define a unique name for the generated C file |
|
939 |
location_str = "_".join(map(lambda x:str(x), current_location)) |
|
940 |
||
941 |
Gen_Ethercatfile_path = os.path.join(buildpath, "ethercat_%s.c"%location_str) |
|
942 |
||
943 |
self.FileGenerator = _EthercatCFileGenerator(self) |
|
944 |
||
945 |
LocationCFilesAndCFLAGS, LDFLAGS, extra_files = ConfigTreeNode._Generate_C(self, buildpath, locations) |
|
946 |
||
947 |
for idx, variable in enumerate(self.ProcessVariables.getvariable()): |
|
948 |
name = None |
|
949 |
var_type = None |
|
950 |
read_from = variable.getReadFrom() |
|
951 |
write_to = variable.getWriteTo() |
|
952 |
if read_from is not None: |
|
953 |
pos = read_from.getPosition() |
|
954 |
index = read_from.getIndex() |
|
955 |
subindex = read_from.getSubIndex() |
|
956 |
location = current_location + (idx, ) |
|
957 |
var_type = self.GetSlaveVariableDataType(pos, index, subindex) |
|
958 |
name = self.FileGenerator.DeclareVariable( |
|
959 |
pos, index, subindex, var_type, "I", |
|
960 |
self.GetProcessVariableName(location, var_type)) |
|
961 |
if write_to is not None: |
|
962 |
pos = write_to.getPosition() |
|
963 |
index = write_to.getIndex() |
|
964 |
subindex = write_to.getSubIndex() |
|
965 |
if name is None: |
|
966 |
location = current_location + (idx, ) |
|
967 |
var_type = self.GetSlaveVariableDataType(pos, index, subindex) |
|
968 |
name = self.GetProcessVariableName(location, var_type) |
|
969 |
self.FileGenerator.DeclareVariable( |
|
970 |
pos, index, subindex, var_type, "Q", name, True) |
|
971 |
||
972 |
self.FileGenerator.GenerateCFile(Gen_Ethercatfile_path, location_str, self.BaseParams.getIEC_Channel()) |
|
973 |
||
2135
ca1c34ff6c10
Fixed order of LocationCFilesAndCFLAGS, master was called after slaves in PLC init and retrieve functions
Laurent Bessard
parents:
2133
diff
changeset
|
974 |
LocationCFilesAndCFLAGS.insert(0, |
2111 | 975 |
(current_location, |
976 |
[(Gen_Ethercatfile_path, '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()))], |
|
977 |
True)) |
|
2112
e88cd6ff885e
Fixed linking with non RTDM etherlab lib. Now with rtdm...
Edouard Tisserant
parents:
2111
diff
changeset
|
978 |
LDFLAGS.append("-lethercat_rtdm -lrtdm") |
2111 | 979 |
|
980 |
return LocationCFilesAndCFLAGS, LDFLAGS, extra_files |
|
981 |
||
982 |
ConfNodeMethods = [ |
|
983 |
{"bitmap" : "ScanNetwork", |
|
984 |
"name" : _("Scan Network"), |
|
985 |
"tooltip" : _("Scan Network"), |
|
986 |
"method" : "_ScanNetwork"}, |
|
987 |
] |
|
988 |
||
989 |
def CTNGenerate_C(self, buildpath, locations): |
|
990 |
current_location = self.GetCurrentLocation() |
|
991 |
||
992 |
slaves = self.GetSlaves() |
|
993 |
for slave_pos in slaves: |
|
994 |
slave = self.GetSlave(slave_pos) |
|
995 |
if slave is not None: |
|
996 |
self.FileGenerator.DeclareSlave(slave_pos, slave) |
|
997 |
||
998 |
for location in locations: |
|
999 |
loc = location["LOC"][len(current_location):] |
|
1000 |
slave_pos = loc[0] |
|
1001 |
if slave_pos in slaves and len(loc) == 3 and location["DIR"] != "M": |
|
1002 |
self.FileGenerator.DeclareVariable( |
|
1003 |
slave_pos, loc[1], loc[2], location["IEC_TYPE"], location["DIR"], location["NAME"]) |
|
1004 |
||
1005 |
return [],"",False |
|
1006 |
||
1007 |
#------------------------------------------------------------------------------- |
|
1008 |
# Current Buffering Management Functions |
|
1009 |
#------------------------------------------------------------------------------- |
|
1010 |
||
1011 |
""" |
|
1012 |
Return a copy of the config |
|
1013 |
""" |
|
1014 |
def Copy(self, model): |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1015 |
return deepcopy(model) |
2111 | 1016 |
|
1017 |
def CreateBuffer(self, saved): |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1018 |
self.Buffer = UndoBuffer( |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1019 |
(EtherCATConfigParser.Dumps(self.Config), |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1020 |
ProcessVariablesParser.Dumps(self.ProcessVariables)), |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1021 |
saved) |
2111 | 1022 |
|
1023 |
def BufferModel(self): |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1024 |
self.Buffer.Buffering( |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1025 |
(EtherCATConfigParser.Dumps(self.Config), |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1026 |
ProcessVariablesParser.Dumps(self.ProcessVariables))) |
2111 | 1027 |
|
1028 |
def ModelIsSaved(self): |
|
1029 |
if self.Buffer is not None: |
|
1030 |
return self.Buffer.IsCurrentSaved() |
|
1031 |
else: |
|
1032 |
return True |
|
1033 |
||
1034 |
def LoadPrevious(self): |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1035 |
config, process_variables = self.Buffer.Previous() |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1036 |
self.Config = EtherCATConfigParser.Loads(config) |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1037 |
self.ProcessVariables = ProcessVariablesParser.Loads(process_variables) |
2111 | 1038 |
|
1039 |
def LoadNext(self): |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1040 |
config, process_variables = self.Buffer.Next() |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1041 |
self.Config = EtherCATConfigParser.Loads(config) |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1042 |
self.ProcessVariables = ProcessVariablesParser.Loads(process_variables) |
2111 | 1043 |
|
1044 |
def GetBufferState(self): |
|
1045 |
first = self.Buffer.IsFirst() |
|
1046 |
last = self.Buffer.IsLast() |
|
1047 |
return not first, not last |
|
1048 |