author | Edouard Tisserant |
Tue, 19 Feb 2019 11:27:29 +0100 | |
changeset 2490 | 2d72d8a8d7e5 |
parent 2456 | 7373e3048167 |
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 |
|
2405
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
12 |
from __future__ import absolute_import |
2111 | 13 |
import os |
2390
81116c5db60f
clean etherlab: pylint, C0411 # (wrong-import-order) standard import "import x" comes before "import y"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2381
diff
changeset
|
14 |
from copy import deepcopy |
2456
7373e3048167
python3 support: pylint,W1610 # (reduce-builtin) reduce built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2447
diff
changeset
|
15 |
from functools import reduce |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
16 |
from lxml import etree |
2111 | 17 |
|
18 |
import wx |
|
19 |
||
20 |
from xmlclass import * |
|
21 |
||
2396
41adf1dfc7a7
clean etherlab: pylint, W0611 # (unused-import) Unused import X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2394
diff
changeset
|
22 |
from PLCControler import UndoBuffer, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT |
2111 | 23 |
from ConfigTreeNode import ConfigTreeNode |
24 |
from dialogs import BrowseValuesLibraryDialog |
|
25 |
from IDEFrame import TITLE, FILEMENU, PROJECTTREE |
|
2392
aad985da14f7
clean etherlab: pylint, C0412 # (ungrouped-imports) Imports from package X are not grouped
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2391
diff
changeset
|
26 |
from POULibrary import POULibrary |
aad985da14f7
clean etherlab: pylint, C0412 # (ungrouped-imports) Imports from package X are not grouped
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2391
diff
changeset
|
27 |
|
2405
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
28 |
from etherlab.ConfigEditor import MasterEditor |
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
29 |
from etherlab.EthercatCFileGenerator import _EthercatCFileGenerator |
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
30 |
from etherlab.EthercatSlave import \ |
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
31 |
_EthercatSlaveCTN, \ |
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
32 |
ExtractHexDecValue, \ |
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
33 |
GenerateHexDecValue, \ |
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
34 |
TYPECONVERSION, \ |
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
35 |
VARCLASSCONVERSION, \ |
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
36 |
_CommonSlave |
2111 | 37 |
|
38 |
try: |
|
2405
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2404
diff
changeset
|
39 |
from etherlab.EthercatCIA402Slave import _EthercatCIA402SlaveCTN |
2111 | 40 |
HAS_MCL = True |
2353
8f1a2846b2f5
cleanup etherlab: pep8, E722 do not use bare except
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
41 |
except Exception: |
2111 | 42 |
HAS_MCL = False |
43 |
||
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
44 |
# -------------------------------------------------- |
2111 | 45 |
# Remote Exec Etherlab Commands |
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
46 |
# -------------------------------------------------- |
2111 | 47 |
|
48 |
SCAN_COMMAND = """ |
|
49 |
import commands |
|
50 |
result = commands.getoutput("ethercat slaves") |
|
51 |
slaves = [] |
|
52 |
for slave_line in result.splitlines(): |
|
53 |
chunks = slave_line.split() |
|
54 |
idx, pos, state, flag = chunks[:4] |
|
55 |
name = " ".join(chunks[4:]) |
|
56 |
alias, position = pos.split(":") |
|
57 |
slave = {"idx": int(idx), |
|
58 |
"alias": int(alias), |
|
59 |
"position": int(position), |
|
60 |
"name": name} |
|
61 |
details = commands.getoutput("ethercat slaves -p %d -v" % slave["idx"]) |
|
62 |
for details_line in details.splitlines(): |
|
63 |
details_line = details_line.strip() |
|
64 |
for header, param in [("Vendor Id:", "vendor_id"), |
|
65 |
("Product code:", "product_code"), |
|
66 |
("Revision number:", "revision_number")]: |
|
67 |
if details_line.startswith(header): |
|
68 |
slave[param] = details_line.split()[-1] |
|
69 |
break |
|
70 |
slaves.append(slave) |
|
71 |
returnVal = slaves |
|
72 |
""" |
|
73 |
||
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
74 |
# -------------------------------------------------- |
2111 | 75 |
# Etherlab Specific Blocks Library |
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
76 |
# -------------------------------------------------- |
2111 | 77 |
|
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2358
diff
changeset
|
78 |
|
2111 | 79 |
def GetLocalPath(filename): |
80 |
return os.path.join(os.path.split(__file__)[0], filename) |
|
81 |
||
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2358
diff
changeset
|
82 |
|
2111 | 83 |
class EtherlabLibrary(POULibrary): |
84 |
def GetLibraryPath(self): |
|
85 |
return GetLocalPath("pous.xml") |
|
86 |
||
87 |
def Generate_C(self, buildpath, varlist, IECCFLAGS): |
|
88 |
etherlab_ext_file = open(GetLocalPath("etherlab_ext.c"), 'r') |
|
89 |
etherlab_ext_code = etherlab_ext_file.read() |
|
90 |
etherlab_ext_file.close() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
91 |
|
2111 | 92 |
Gen_etherlabfile_path = os.path.join(buildpath, "etherlab_ext.c") |
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
93 |
ethelabfile = open(Gen_etherlabfile_path, 'w') |
2111 | 94 |
ethelabfile.write(etherlab_ext_code) |
95 |
ethelabfile.close() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
96 |
|
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
97 |
return ((["etherlab_ext"], [(Gen_etherlabfile_path, IECCFLAGS)], True), "", |
2442
b13f021c68a5
python3 support: pylint, W1607 # (file-builtin) file built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2423
diff
changeset
|
98 |
("runtime_etherlab.py", open(GetLocalPath("runtime_etherlab.py")))) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
99 |
|
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
100 |
# -------------------------------------------------- |
2111 | 101 |
# Ethercat MASTER |
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
102 |
# -------------------------------------------------- |
2111 | 103 |
|
2370
e40f3914e55f
cleanup etherlab: pep8, E305 expected 2 blank lines after class or function definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2367
diff
changeset
|
104 |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
105 |
EtherCATConfigParser = GenerateParserFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATConfig.xsd")) |
2111 | 106 |
|
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2358
diff
changeset
|
107 |
|
2111 | 108 |
def sort_commands(x, y): |
109 |
if x["Index"] == y["Index"]: |
|
110 |
return cmp(x["Subindex"], y["Subindex"]) |
|
111 |
return cmp(x["Index"], y["Index"]) |
|
112 |
||
2370
e40f3914e55f
cleanup etherlab: pep8, E305 expected 2 blank lines after class or function definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2367
diff
changeset
|
113 |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
114 |
cls = EtherCATConfigParser.GetElementClass("Slave", "Config") |
2111 | 115 |
if cls: |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
116 |
|
2111 | 117 |
def getType(self): |
118 |
slave_info = self.getInfo() |
|
119 |
return {"device_type": slave_info.getName(), |
|
120 |
"vendor": GenerateHexDecValue(slave_info.getVendorId()), |
|
121 |
"product_code": GenerateHexDecValue(slave_info.getProductCode(), 16), |
|
122 |
"revision_number": GenerateHexDecValue(slave_info.getRevisionNo(), 16)} |
|
123 |
setattr(cls, "getType", getType) |
|
124 |
||
125 |
def setType(self, type_infos): |
|
126 |
slave_info = self.getInfo() |
|
127 |
slave_info.setName(type_infos["device_type"]) |
|
128 |
slave_info.setVendorId(ExtractHexDecValue(type_infos["vendor"])) |
|
129 |
slave_info.setProductCode(ExtractHexDecValue(type_infos["product_code"])) |
|
130 |
slave_info.setRevisionNo(ExtractHexDecValue(type_infos["revision_number"])) |
|
131 |
setattr(cls, "setType", setType) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
132 |
|
2111 | 133 |
def getInitCmds(self, create_default=False): |
134 |
Mailbox = self.getMailbox() |
|
135 |
if Mailbox is None: |
|
136 |
if create_default: |
|
137 |
self.addMailbox() |
|
138 |
Mailbox = self.getMailbox() |
|
139 |
else: |
|
140 |
return None |
|
141 |
CoE = Mailbox.getCoE() |
|
142 |
if CoE is None: |
|
143 |
if create_default: |
|
144 |
Mailbox.addCoE() |
|
145 |
CoE = Mailbox.getCoE() |
|
146 |
else: |
|
147 |
return None |
|
148 |
InitCmds = CoE.getInitCmds() |
|
149 |
if InitCmds is None and create_default: |
|
150 |
CoE.addInitCmds() |
|
151 |
InitCmds = CoE.getInitCmds() |
|
152 |
return InitCmds |
|
153 |
setattr(cls, "getInitCmds", getInitCmds) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
154 |
|
2111 | 155 |
def getStartupCommands(self): |
156 |
pos = self.getInfo().getPhysAddr() |
|
157 |
InitCmds = self.getInitCmds() |
|
158 |
if InitCmds is None: |
|
159 |
return [] |
|
160 |
commands = [] |
|
161 |
for idx, InitCmd in enumerate(InitCmds.getInitCmd()): |
|
162 |
comment = InitCmd.getComment() |
|
163 |
if comment is None: |
|
164 |
comment = "" |
|
165 |
commands.append({ |
|
166 |
"command_idx": idx, |
|
167 |
"Position": pos, |
|
168 |
"Index": InitCmd.getIndex(), |
|
169 |
"Subindex": InitCmd.getSubIndex(), |
|
170 |
"Value": InitCmd.getData(), |
|
171 |
"Description": comment}) |
|
172 |
commands.sort(sort_commands) |
|
173 |
return commands |
|
174 |
setattr(cls, "getStartupCommands", getStartupCommands) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
175 |
|
2111 | 176 |
def appendStartupCommand(self, command_infos): |
177 |
InitCmds = self.getInitCmds(True) |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
178 |
command = EtherCATConfigParser.CreateElement("InitCmd", "InitCmds", 1) |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
179 |
InitCmds.appendInitCmd(command) |
2111 | 180 |
command.setIndex(command_infos["Index"]) |
181 |
command.setSubIndex(command_infos["Subindex"]) |
|
182 |
command.setData(command_infos["Value"]) |
|
183 |
command.setComment(command_infos["Description"]) |
|
184 |
return len(InitCmds.getInitCmd()) - 1 |
|
185 |
setattr(cls, "appendStartupCommand", appendStartupCommand) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
186 |
|
2111 | 187 |
def setStartupCommand(self, command_infos): |
188 |
InitCmds = self.getInitCmds() |
|
189 |
if InitCmds is not None: |
|
190 |
commands = InitCmds.getInitCmd() |
|
191 |
if command_infos["command_idx"] < len(commands): |
|
192 |
command = commands[command_infos["command_idx"]] |
|
193 |
command.setIndex(command_infos["Index"]) |
|
194 |
command.setSubIndex(command_infos["Subindex"]) |
|
195 |
command.setData(command_infos["Value"]) |
|
196 |
command.setComment(command_infos["Description"]) |
|
197 |
setattr(cls, "setStartupCommand", setStartupCommand) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
198 |
|
2111 | 199 |
def removeStartupCommand(self, command_idx): |
200 |
InitCmds = self.getInitCmds() |
|
201 |
if InitCmds is not None: |
|
202 |
if command_idx < len(InitCmds.getInitCmd()): |
|
203 |
InitCmds.removeInitCmd(command_idx) |
|
204 |
setattr(cls, "removeStartupCommand", removeStartupCommand) |
|
205 |
||
206 |
ProcessVariablesXSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
207 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
208 |
<xsd:element name="ProcessVariables"> |
|
209 |
<xsd:complexType> |
|
210 |
<xsd:sequence> |
|
211 |
<xsd:element name="variable" minOccurs="0" maxOccurs="unbounded"> |
|
212 |
<xsd:complexType> |
|
213 |
<xsd:sequence> |
|
214 |
<xsd:element name="ReadFrom" type="LocationDesc" minOccurs="0"/> |
|
215 |
<xsd:element name="WriteTo" type="LocationDesc" minOccurs="0"/> |
|
216 |
</xsd:sequence> |
|
217 |
<xsd:attribute name="Name" type="xsd:string" use="required"/> |
|
218 |
<xsd:attribute name="Comment" type="xsd:string" use="required"/> |
|
219 |
</xsd:complexType> |
|
220 |
</xsd:element> |
|
221 |
</xsd:sequence> |
|
222 |
</xsd:complexType> |
|
223 |
</xsd:element> |
|
224 |
<xsd:complexType name="LocationDesc"> |
|
225 |
<xsd:attribute name="Position" type="xsd:integer" use="required"/> |
|
226 |
<xsd:attribute name="Index" type="xsd:integer" use="required"/> |
|
227 |
<xsd:attribute name="SubIndex" type="xsd:integer" use="required"/> |
|
228 |
</xsd:complexType> |
|
229 |
</xsd:schema> |
|
230 |
""" |
|
231 |
||
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
232 |
ProcessVariablesParser = GenerateParserFromXSDstring(ProcessVariablesXSD) |
2111 | 233 |
|
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2358
diff
changeset
|
234 |
|
2397
25f16349644b
clean etherlab: pylint, C1001 # (old-style-class) Old-style class defined.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2396
diff
changeset
|
235 |
class _EthercatCTN(object): |
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
|
236 |
|
2111 | 237 |
CTNChildrenTypes = [("EthercatSlave", _EthercatSlaveCTN, "Ethercat Slave")] |
238 |
if HAS_MCL: |
|
239 |
CTNChildrenTypes.append(("EthercatCIA402Slave", _EthercatCIA402SlaveCTN, "Ethercat CIA402 Slave")) |
|
240 |
EditorType = MasterEditor |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
241 |
|
2111 | 242 |
def __init__(self): |
243 |
config_filepath = self.ConfigFileName() |
|
244 |
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
|
245 |
self.Config = None |
2111 | 246 |
if os.path.isfile(config_filepath): |
247 |
config_xmlfile = open(config_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
|
248 |
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
|
249 |
self.Config, 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
|
250 |
EtherCATConfigParser.LoadXMLString(config_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
|
251 |
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
|
252 |
config_is_saved = True |
2418
5587c490a070
Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2407
diff
changeset
|
253 |
except Exception as e: |
2447
1c04a50dc7ff
python3 support: pylint, W1645 # (exception-message-attribute) Exception.message removed in Python 3
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2442
diff
changeset
|
254 |
error = str(e) |
2111 | 255 |
config_xmlfile.close() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
256 |
|
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
|
257 |
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
|
258 |
self.GetCTRoot().logger.write_error( |
2404
87eb184414bd
clean etherlab: pylint,E0602 # (undefined-variable) Undefined variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2403
diff
changeset
|
259 |
_("Couldn't load %s network configuration file.") % self.CTNName()) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
260 |
|
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 |
if self.Config is None: |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
262 |
self.Config = EtherCATConfigParser.CreateElement("EtherCATConfig") |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
263 |
|
2111 | 264 |
process_filepath = self.ProcessVariablesFileName() |
265 |
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
|
266 |
self.ProcessVariables = None |
2111 | 267 |
if os.path.isfile(process_filepath): |
268 |
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
|
269 |
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
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
process_is_saved = True |
2418
5587c490a070
Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2407
diff
changeset
|
274 |
except Exception as e: |
2447
1c04a50dc7ff
python3 support: pylint, W1645 # (exception-message-attribute) Exception.message removed in Python 3
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2442
diff
changeset
|
275 |
error = str(e) |
2111 | 276 |
process_xmlfile.close() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
277 |
|
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
|
278 |
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
|
279 |
self.GetCTRoot().logger.write_error( |
2404
87eb184414bd
clean etherlab: pylint,E0602 # (undefined-variable) Undefined variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2403
diff
changeset
|
280 |
_("Couldn't load %s network process variables file.") % self.CTNName()) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
281 |
|
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
|
282 |
if self.ProcessVariables is None: |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
283 |
self.ProcessVariables = ProcessVariablesParser.CreateElement("ProcessVariables") |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
284 |
|
2111 | 285 |
if config_is_saved and process_is_saved: |
286 |
self.CreateBuffer(True) |
|
287 |
else: |
|
288 |
self.CreateBuffer(False) |
|
289 |
self.OnCTNSave() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
290 |
|
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
|
291 |
# ----------- 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
|
292 |
self.CommonMethod = _CommonSlave(self) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
293 |
|
2149
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2147
diff
changeset
|
294 |
def GetIconName(self): |
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2147
diff
changeset
|
295 |
return "Ethercat" |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
296 |
|
2111 | 297 |
def GetContextualMenuItems(self): |
2423
2c7b7ae24d57
Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2418
diff
changeset
|
298 |
return [(_("Add Ethercat Slave"), _("Add Ethercat Slave to Master"), self.OnAddEthercatSlave)] |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
299 |
|
2111 | 300 |
def OnAddEthercatSlave(self, event): |
301 |
app_frame = self.GetCTRoot().AppFrame |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
302 |
dialog = BrowseValuesLibraryDialog(app_frame, |
2423
2c7b7ae24d57
Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2418
diff
changeset
|
303 |
_("Ethercat Slave Type"), |
2381
1c40e3976cc2
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2380
diff
changeset
|
304 |
self.GetSlaveTypesLibrary()) |
2111 | 305 |
if dialog.ShowModal() == wx.ID_OK: |
306 |
type_infos = dialog.GetValueInfos() |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
307 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 308 |
if device is not None: |
309 |
if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers(): |
|
310 |
ConfNodeType = "EthercatCIA402Slave" |
|
311 |
else: |
|
312 |
ConfNodeType = "EthercatSlave" |
|
313 |
new_child = self.CTNAddChild("%s_0" % ConfNodeType, ConfNodeType) |
|
314 |
new_child.SetParamsAttribute("SlaveParams.Type", type_infos) |
|
315 |
self.CTNRequestSave() |
|
316 |
new_child._OpenView() |
|
317 |
app_frame._Refresh(TITLE, FILEMENU, PROJECTTREE) |
|
318 |
dialog.Destroy() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
319 |
|
2111 | 320 |
def ExtractHexDecValue(self, value): |
321 |
return ExtractHexDecValue(value) |
|
322 |
||
323 |
def GetSizeOfType(self, type): |
|
324 |
return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) |
|
325 |
||
326 |
def ConfigFileName(self): |
|
327 |
return os.path.join(self.CTNPath(), "config.xml") |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
328 |
|
2111 | 329 |
def ProcessVariablesFileName(self): |
330 |
return os.path.join(self.CTNPath(), "process_variables.xml") |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
331 |
|
2111 | 332 |
def FilterSlave(self, slave, vendor=None, slave_pos=None, slave_profile=None): |
333 |
if slave_pos is not None and slave.getInfo().getPhysAddr() != slave_pos: |
|
334 |
return False |
|
335 |
type_infos = slave.getType() |
|
336 |
if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor: |
|
337 |
return False |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
338 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 339 |
if slave_profile is not None and slave_profile not in device.GetProfileNumbers(): |
340 |
return False |
|
341 |
return True |
|
342 |
||
2124
1f2c3fdd70d0
Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents:
2113
diff
changeset
|
343 |
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
|
344 |
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
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
|
2111 | 349 |
def GetSlaves(self, vendor=None, slave_pos=None, slave_profile=None): |
350 |
slaves = [] |
|
351 |
for slave in self.Config.getConfig().getSlave(): |
|
352 |
if self.FilterSlave(slave, vendor, slave_pos, slave_profile): |
|
353 |
slaves.append(slave.getInfo().getPhysAddr()) |
|
354 |
slaves.sort() |
|
355 |
return slaves |
|
356 |
||
357 |
def GetSlave(self, slave_pos): |
|
358 |
for slave in self.Config.getConfig().getSlave(): |
|
359 |
slave_info = slave.getInfo() |
|
360 |
if slave_info.getPhysAddr() == slave_pos: |
|
361 |
return slave |
|
362 |
return None |
|
363 |
||
364 |
def GetStartupCommands(self, vendor=None, slave_pos=None, slave_profile=None): |
|
365 |
commands = [] |
|
366 |
for slave in self.Config.getConfig().getSlave(): |
|
367 |
if self.FilterSlave(slave, vendor, slave_pos, slave_profile): |
|
368 |
commands.append((slave.getInfo().getPhysAddr(), slave.getStartupCommands())) |
|
369 |
commands.sort() |
|
370 |
return reduce(lambda x, y: x + y[1], commands, []) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
371 |
|
2111 | 372 |
def AppendStartupCommand(self, command_infos): |
373 |
slave = self.GetSlave(command_infos["Position"]) |
|
374 |
if slave is not None: |
|
375 |
command_idx = slave.appendStartupCommand(command_infos) |
|
376 |
self.BufferModel() |
|
377 |
return command_idx |
|
378 |
return None |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
379 |
|
2111 | 380 |
def SetStartupCommandInfos(self, command_infos): |
381 |
slave = self.GetSlave(command_infos["Position"]) |
|
382 |
if slave is not None: |
|
383 |
slave.setStartupCommand(command_infos) |
|
384 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
385 |
|
2111 | 386 |
def RemoveStartupCommand(self, slave_pos, command_idx, buffer=True): |
387 |
slave = self.GetSlave(slave_pos) |
|
388 |
if slave is not None: |
|
389 |
slave.removeStartupCommand(command_idx) |
|
390 |
if buffer: |
|
391 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
392 |
|
2111 | 393 |
def SetProcessVariables(self, variables): |
394 |
vars = [] |
|
395 |
for var in variables: |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
396 |
variable = ProcessVariablesParser.CreateElement("variable", "ProcessVariables") |
2111 | 397 |
variable.setName(var["Name"]) |
398 |
variable.setComment(var["Description"]) |
|
399 |
if var["ReadFrom"] != "": |
|
400 |
position, index, subindex = var["ReadFrom"] |
|
401 |
if variable.getReadFrom() is None: |
|
402 |
variable.addReadFrom() |
|
403 |
read_from = variable.getReadFrom() |
|
404 |
read_from.setPosition(position) |
|
405 |
read_from.setIndex(index) |
|
406 |
read_from.setSubIndex(subindex) |
|
407 |
elif variable.getReadFrom() is not None: |
|
408 |
variable.deleteReadFrom() |
|
409 |
if var["WriteTo"] != "": |
|
410 |
position, index, subindex = var["WriteTo"] |
|
411 |
if variable.getWriteTo() is None: |
|
412 |
variable.addWriteTo() |
|
413 |
write_to = variable.getWriteTo() |
|
414 |
write_to.setPosition(position) |
|
415 |
write_to.setIndex(index) |
|
416 |
write_to.setSubIndex(subindex) |
|
417 |
elif variable.getWriteTo() is not None: |
|
418 |
variable.deleteWriteTo() |
|
419 |
vars.append(variable) |
|
420 |
self.ProcessVariables.setvariable(vars) |
|
421 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
422 |
|
2111 | 423 |
def GetProcessVariables(self): |
424 |
variables = [] |
|
425 |
idx = 0 |
|
426 |
for variable in self.ProcessVariables.getvariable(): |
|
427 |
var = {"Name": variable.getName(), |
|
428 |
"Number": idx, |
|
429 |
"Description": variable.getComment()} |
|
430 |
read_from = variable.getReadFrom() |
|
431 |
if read_from is not None: |
|
432 |
var["ReadFrom"] = (read_from.getPosition(), |
|
433 |
read_from.getIndex(), |
|
434 |
read_from.getSubIndex()) |
|
435 |
else: |
|
436 |
var["ReadFrom"] = "" |
|
437 |
write_to = variable.getWriteTo() |
|
438 |
if write_to is not None: |
|
439 |
var["WriteTo"] = (write_to.getPosition(), |
|
2380
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
440 |
write_to.getIndex(), |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
441 |
write_to.getSubIndex()) |
2111 | 442 |
else: |
443 |
var["WriteTo"] = "" |
|
444 |
variables.append(var) |
|
445 |
idx += 1 |
|
446 |
return variables |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
447 |
|
2111 | 448 |
def _ScanNetwork(self): |
449 |
app_frame = self.GetCTRoot().AppFrame |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
450 |
|
2111 | 451 |
execute = True |
452 |
if len(self.Children) > 0: |
|
2381
1c40e3976cc2
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2380
diff
changeset
|
453 |
dialog = wx.MessageDialog( |
1c40e3976cc2
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2380
diff
changeset
|
454 |
app_frame, |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
455 |
_("The current network configuration will be deleted.\nDo you want to continue?"), |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
456 |
_("Scan Network"), |
2367
0fb54172a18b
cleanup etherlab: pep8, E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2366
diff
changeset
|
457 |
wx.YES_NO | wx.ICON_QUESTION) |
2111 | 458 |
execute = dialog.ShowModal() == wx.ID_YES |
459 |
dialog.Destroy() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
460 |
|
2111 | 461 |
if execute: |
2366
d635680e4c2c
cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2363
diff
changeset
|
462 |
error, returnVal = self.RemoteExec(SCAN_COMMAND, returnVal=None) |
2111 | 463 |
if error != 0: |
2423
2c7b7ae24d57
Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2418
diff
changeset
|
464 |
dialog = wx.MessageDialog(app_frame, returnVal, _("Error"), wx.OK | wx.ICON_ERROR) |
2111 | 465 |
dialog.ShowModal() |
466 |
dialog.Destroy() |
|
467 |
elif returnVal is not None: |
|
468 |
for child in self.IECSortedChildren(): |
|
469 |
self._doRemoveChild(child) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
470 |
|
2111 | 471 |
for slave in returnVal: |
472 |
type_infos = { |
|
473 |
"vendor": slave["vendor_id"], |
|
474 |
"product_code": slave["product_code"], |
|
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
475 |
"revision_number": slave["revision_number"], |
2111 | 476 |
} |
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
477 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 478 |
if device is not None: |
479 |
if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers(): |
|
480 |
CTNType = "EthercatCIA402Slave" |
|
481 |
else: |
|
482 |
CTNType = "EthercatSlave" |
|
483 |
self.CTNAddChild("slave%s" % slave["idx"], CTNType, slave["idx"]) |
|
484 |
self.SetSlaveAlias(slave["idx"], slave["alias"]) |
|
485 |
type_infos["device_type"] = device.getType().getcontent() |
|
486 |
self.SetSlaveType(slave["idx"], type_infos) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
487 |
|
2127
32255ca50fb0
Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents:
2124
diff
changeset
|
488 |
if app_frame: |
32255ca50fb0
Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents:
2124
diff
changeset
|
489 |
app_frame.RefreshProjectTree() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
490 |
|
2111 | 491 |
def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0): |
492 |
""" |
|
493 |
Create the confnodes that may be added as child to this node self |
|
494 |
@param CTNType: string desining the confnode class name (get name from CTNChildrenTypes) |
|
495 |
@param CTNName: string for the name of the confnode instance |
|
496 |
""" |
|
497 |
newConfNodeOpj = ConfigTreeNode.CTNAddChild(self, CTNName, CTNType, IEC_Channel) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
498 |
|
2111 | 499 |
slave = self.GetSlave(newConfNodeOpj.BaseParams.getIEC_Channel()) |
500 |
if slave is None: |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
501 |
slave = EtherCATConfigParser.CreateElement("Slave", "Config") |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
502 |
self.Config.getConfig().appendSlave(slave) |
2111 | 503 |
slave_infos = slave.getInfo() |
504 |
slave_infos.setName("undefined") |
|
505 |
slave_infos.setPhysAddr(newConfNodeOpj.BaseParams.getIEC_Channel()) |
|
506 |
slave_infos.setAutoIncAddr(0) |
|
507 |
self.BufferModel() |
|
508 |
self.OnCTNSave() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
509 |
|
2111 | 510 |
return newConfNodeOpj |
511 |
||
512 |
def _doRemoveChild(self, CTNInstance): |
|
513 |
slave_pos = CTNInstance.GetSlavePos() |
|
514 |
config = self.Config.getConfig() |
|
515 |
for idx, slave in enumerate(config.getSlave()): |
|
516 |
slave_infos = slave.getInfo() |
|
517 |
if slave_infos.getPhysAddr() == slave_pos: |
|
518 |
config.removeSlave(idx) |
|
519 |
self.BufferModel() |
|
520 |
self.OnCTNSave() |
|
521 |
ConfigTreeNode._doRemoveChild(self, CTNInstance) |
|
522 |
||
523 |
def SetSlavePosition(self, slave_pos, new_pos): |
|
524 |
slave = self.GetSlave(slave_pos) |
|
525 |
if slave is not None: |
|
526 |
slave_info = slave.getInfo() |
|
527 |
slave_info.setPhysAddr(new_pos) |
|
528 |
for variable in self.ProcessVariables.getvariable(): |
|
529 |
read_from = variable.getReadFrom() |
|
530 |
if read_from is not None and read_from.getPosition() == slave_pos: |
|
531 |
read_from.setPosition(new_pos) |
|
532 |
write_to = variable.getWriteTo() |
|
533 |
if write_to is not None and write_to.getPosition() == slave_pos: |
|
534 |
write_to.setPosition(new_pos) |
|
535 |
self.CreateBuffer(True) |
|
2147
a8b095de63e8
Fix bug in when moving Ethercat slaves fixed
Laurent Bessard
parents:
2141
diff
changeset
|
536 |
self.CTNRequestSave() |
2111 | 537 |
if self._View is not None: |
538 |
self._View.RefreshView() |
|
539 |
self._View.RefreshBuffer() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
540 |
|
2111 | 541 |
def GetSlaveAlias(self, slave_pos): |
542 |
slave = self.GetSlave(slave_pos) |
|
543 |
if slave is not None: |
|
544 |
slave_info = slave.getInfo() |
|
545 |
return slave_info.getAutoIncAddr() |
|
546 |
return None |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
547 |
|
2111 | 548 |
def SetSlaveAlias(self, slave_pos, alias): |
549 |
slave = self.GetSlave(slave_pos) |
|
550 |
if slave is not None: |
|
551 |
slave_info = slave.getInfo() |
|
552 |
slave_info.setAutoIncAddr(alias) |
|
553 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
554 |
|
2111 | 555 |
def GetSlaveType(self, slave_pos): |
556 |
slave = self.GetSlave(slave_pos) |
|
557 |
if slave is not None: |
|
558 |
return slave.getType() |
|
559 |
return None |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
560 |
|
2111 | 561 |
def SetSlaveType(self, slave_pos, type_infos): |
562 |
slave = self.GetSlave(slave_pos) |
|
563 |
if slave is not None: |
|
564 |
slave.setType(type_infos) |
|
565 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
566 |
|
2111 | 567 |
def GetSlaveInfos(self, slave_pos): |
568 |
slave = self.GetSlave(slave_pos) |
|
569 |
if slave is not None: |
|
570 |
type_infos = slave.getType() |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
571 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 572 |
if device is not None: |
573 |
infos = type_infos.copy() |
|
574 |
infos.update({"physics": device.getPhysics(), |
|
575 |
"sync_managers": device.GetSyncManagers(), |
|
576 |
"entries": self.GetSlaveVariables(device)}) |
|
577 |
return infos |
|
578 |
return None |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
579 |
|
2111 | 580 |
def GetSlaveVariables(self, slave_pos=None, limits=None, device=None): |
581 |
if device is None and slave_pos is not None: |
|
582 |
slave = self.GetSlave(slave_pos) |
|
583 |
if slave is not None: |
|
584 |
type_infos = slave.getType() |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
585 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 586 |
if device is not None: |
587 |
entries = device.GetEntriesList(limits) |
|
588 |
entries_list = entries.items() |
|
589 |
entries_list.sort() |
|
590 |
entries = [] |
|
591 |
current_index = None |
|
2403
045df8ecc8b3
clean etherlab: pylint, E1136 # (unsubscriptable-object) Value 'X' is unsubscriptable
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2399
diff
changeset
|
592 |
current_entry = {} |
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
593 |
for (index, _subindex), entry in entries_list: |
2111 | 594 |
entry["children"] = [] |
595 |
if slave_pos is not None: |
|
596 |
entry["Position"] = str(slave_pos) |
|
597 |
if index != current_index: |
|
598 |
current_index = index |
|
599 |
current_entry = entry |
|
600 |
entries.append(entry) |
|
2403
045df8ecc8b3
clean etherlab: pylint, E1136 # (unsubscriptable-object) Value 'X' is unsubscriptable
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2399
diff
changeset
|
601 |
elif current_entry: |
2111 | 602 |
current_entry["children"].append(entry) |
603 |
else: |
|
604 |
entries.append(entry) |
|
605 |
return entries |
|
606 |
return [] |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
607 |
|
2111 | 608 |
def GetSlaveVariableDataType(self, slave_pos, index, subindex): |
609 |
slave = self.GetSlave(slave_pos) |
|
610 |
if slave is not None: |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
611 |
device, _module_extra_params = self.GetModuleInfos(slave.getType()) |
2111 | 612 |
if device is not None: |
613 |
entries = device.GetEntriesList() |
|
614 |
entry_infos = entries.get((index, subindex)) |
|
615 |
if entry_infos is not None: |
|
616 |
return entry_infos["Type"] |
|
617 |
return None |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
618 |
|
2111 | 619 |
def GetNodesVariables(self, vendor=None, slave_pos=None, slave_profile=None, limits=None): |
620 |
entries = [] |
|
621 |
for slave_position in self.GetSlaves(): |
|
622 |
if slave_pos is not None and slave_position != slave_pos: |
|
623 |
continue |
|
624 |
slave = self.GetSlave(slave_position) |
|
625 |
type_infos = slave.getType() |
|
626 |
if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor: |
|
627 |
continue |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
628 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 629 |
if slave_profile is not None and slave_profile not in device.GetProfileNumbers(): |
630 |
continue |
|
631 |
entries.extend(self.GetSlaveVariables(slave_position, limits, device)) |
|
632 |
return entries |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
633 |
|
2111 | 634 |
def GetModuleInfos(self, type_infos): |
635 |
return self.CTNParent.GetModuleInfos(type_infos) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
636 |
|
2111 | 637 |
def GetSlaveTypesLibrary(self, profile_filter=None): |
638 |
return self.CTNParent.GetModulesLibrary(profile_filter) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
639 |
|
2111 | 640 |
def GetLibraryVendors(self): |
641 |
return self.CTNParent.GetVendors() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
642 |
|
2111 | 643 |
def GetDeviceLocationTree(self, slave_pos, current_location, device_name): |
644 |
slave = self.GetSlave(slave_pos) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
645 |
vars = [] |
2111 | 646 |
if slave is not None: |
647 |
type_infos = slave.getType() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
648 |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
649 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 650 |
if device is not None: |
651 |
sync_managers = [] |
|
652 |
for sync_manager in device.getSm(): |
|
653 |
sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte()) |
|
654 |
sync_manager_direction = sync_manager_control_byte & 0x0c |
|
655 |
if sync_manager_direction: |
|
656 |
sync_managers.append(LOCATION_VAR_OUTPUT) |
|
657 |
else: |
|
658 |
sync_managers.append(LOCATION_VAR_INPUT) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
659 |
|
2111 | 660 |
entries = device.GetEntriesList().items() |
661 |
entries.sort() |
|
662 |
for (index, subindex), entry in entries: |
|
663 |
var_size = self.GetSizeOfType(entry["Type"]) |
|
664 |
if var_size is not None: |
|
665 |
var_class = VARCLASSCONVERSION.get(entry["PDOMapping"], None) |
|
666 |
if var_class is not None: |
|
667 |
if var_class == LOCATION_VAR_INPUT: |
|
668 |
var_dir = "%I" |
|
669 |
else: |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
670 |
var_dir = "%Q" |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
671 |
|
2380
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
672 |
vars.append({ |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
673 |
"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry["Name"]), |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
674 |
"type": var_class, |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
675 |
"size": var_size, |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
676 |
"IEC_type": entry["Type"], |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
677 |
"var_name": "%s_%4.4x_%2.2x" % ("_".join(device_name.split()), index, subindex), |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
678 |
"location": "%s%s%s" % (var_dir, var_size, ".".join(map(str, current_location + |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
679 |
(index, subindex)))), |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
680 |
"description": "", |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
681 |
"children": [], |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
682 |
}) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
683 |
|
2111 | 684 |
return vars |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
685 |
|
2111 | 686 |
def CTNTestModified(self): |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
687 |
return self.ChangesToSave or not self.ModelIsSaved() |
2111 | 688 |
|
2133 | 689 |
def OnCTNSave(self, from_project_path=None): |
2111 | 690 |
config_filepath = self.ConfigFileName() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
691 |
|
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
692 |
config_xmlfile = open(config_filepath, "w") |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
693 |
config_xmlfile.write(etree.tostring( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
694 |
self.Config, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
695 |
pretty_print=True, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
696 |
xml_declaration=True, |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
697 |
encoding='utf-8')) |
2111 | 698 |
config_xmlfile.close() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
699 |
|
2111 | 700 |
process_filepath = self.ProcessVariablesFileName() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
701 |
|
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
702 |
process_xmlfile = open(process_filepath, "w") |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
703 |
process_xmlfile.write(etree.tostring( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
704 |
self.ProcessVariables, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
705 |
pretty_print=True, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
706 |
xml_declaration=True, |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
707 |
encoding='utf-8')) |
2111 | 708 |
process_xmlfile.close() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
709 |
|
2111 | 710 |
self.Buffer.CurrentSaved() |
711 |
return True |
|
712 |
||
713 |
def GetProcessVariableName(self, location, var_type): |
|
714 |
return "__M%s_%s" % (self.GetSizeOfType(var_type), "_".join(map(str, location))) |
|
715 |
||
716 |
def _Generate_C(self, buildpath, locations): |
|
717 |
current_location = self.GetCurrentLocation() |
|
718 |
# define a unique name for the generated C file |
|
2391
3315e621d7fb
clean etherlab: pylint,W0108 # (unnecessary-lambda) Lambda may not be necessary
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2390
diff
changeset
|
719 |
location_str = "_".join(map(str, current_location)) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
720 |
|
2358
8e5a9830867e
cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2356
diff
changeset
|
721 |
Gen_Ethercatfile_path = os.path.join(buildpath, "ethercat_%s.c" % location_str) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
722 |
|
2111 | 723 |
self.FileGenerator = _EthercatCFileGenerator(self) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
724 |
|
2111 | 725 |
LocationCFilesAndCFLAGS, LDFLAGS, extra_files = ConfigTreeNode._Generate_C(self, buildpath, locations) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
726 |
|
2111 | 727 |
for idx, variable in enumerate(self.ProcessVariables.getvariable()): |
728 |
name = None |
|
729 |
var_type = None |
|
730 |
read_from = variable.getReadFrom() |
|
731 |
write_to = variable.getWriteTo() |
|
732 |
if read_from is not None: |
|
733 |
pos = read_from.getPosition() |
|
734 |
index = read_from.getIndex() |
|
735 |
subindex = read_from.getSubIndex() |
|
736 |
location = current_location + (idx, ) |
|
737 |
var_type = self.GetSlaveVariableDataType(pos, index, subindex) |
|
2407
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2406
diff
changeset
|
738 |
name = self.FileGenerator.DeclareVariable(pos, index, subindex, |
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2406
diff
changeset
|
739 |
var_type, "I", |
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2406
diff
changeset
|
740 |
self.GetProcessVariableName(location, var_type)) |
2111 | 741 |
if write_to is not None: |
742 |
pos = write_to.getPosition() |
|
743 |
index = write_to.getIndex() |
|
744 |
subindex = write_to.getSubIndex() |
|
745 |
if name is None: |
|
746 |
location = current_location + (idx, ) |
|
747 |
var_type = self.GetSlaveVariableDataType(pos, index, subindex) |
|
748 |
name = self.GetProcessVariableName(location, var_type) |
|
2407
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2406
diff
changeset
|
749 |
self.FileGenerator.DeclareVariable(pos, index, subindex, var_type, "Q", name, True) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
750 |
|
2111 | 751 |
self.FileGenerator.GenerateCFile(Gen_Ethercatfile_path, location_str, self.BaseParams.getIEC_Channel()) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
752 |
|
2381
1c40e3976cc2
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2380
diff
changeset
|
753 |
LocationCFilesAndCFLAGS.insert( |
1c40e3976cc2
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2380
diff
changeset
|
754 |
0, |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
755 |
(current_location, |
2358
8e5a9830867e
cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2356
diff
changeset
|
756 |
[(Gen_Ethercatfile_path, '"-I%s"' % os.path.abspath(self.GetCTRoot().GetIECLibPath()))], |
2111 | 757 |
True)) |
2112
e88cd6ff885e
Fixed linking with non RTDM etherlab lib. Now with rtdm...
Edouard Tisserant
parents:
2111
diff
changeset
|
758 |
LDFLAGS.append("-lethercat_rtdm -lrtdm") |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
759 |
|
2111 | 760 |
return LocationCFilesAndCFLAGS, LDFLAGS, extra_files |
761 |
||
762 |
ConfNodeMethods = [ |
|
2375
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
763 |
{ |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
764 |
"bitmap": "ScanNetwork", |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
765 |
"name": _("Scan Network"), |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
766 |
"tooltip": _("Scan Network"), |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
767 |
"method": "_ScanNetwork", |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
768 |
}, |
2111 | 769 |
] |
770 |
||
771 |
def CTNGenerate_C(self, buildpath, locations): |
|
772 |
current_location = self.GetCurrentLocation() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
773 |
|
2111 | 774 |
slaves = self.GetSlaves() |
775 |
for slave_pos in slaves: |
|
776 |
slave = self.GetSlave(slave_pos) |
|
777 |
if slave is not None: |
|
778 |
self.FileGenerator.DeclareSlave(slave_pos, slave) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
779 |
|
2111 | 780 |
for location in locations: |
781 |
loc = location["LOC"][len(current_location):] |
|
782 |
slave_pos = loc[0] |
|
783 |
if slave_pos in slaves and len(loc) == 3 and location["DIR"] != "M": |
|
784 |
self.FileGenerator.DeclareVariable( |
|
785 |
slave_pos, loc[1], loc[2], location["IEC_TYPE"], location["DIR"], location["NAME"]) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
786 |
|
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
787 |
return [], "", False |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
788 |
|
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
789 |
# ------------------------------------------------------------------------------- |
2111 | 790 |
# Current Buffering Management Functions |
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
791 |
# ------------------------------------------------------------------------------- |
2111 | 792 |
|
793 |
def Copy(self, model): |
|
2394
bbc3d3d93562
clean etherlab: pylint, W0105 # (pointless-string-statement) String statement has no effect
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2392
diff
changeset
|
794 |
"""Return a copy of the config""" |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
795 |
return deepcopy(model) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
796 |
|
2111 | 797 |
def CreateBuffer(self, saved): |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
798 |
self.Buffer = UndoBuffer( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
799 |
(EtherCATConfigParser.Dumps(self.Config), |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
800 |
ProcessVariablesParser.Dumps(self.ProcessVariables)), |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
801 |
saved) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
802 |
|
2111 | 803 |
def BufferModel(self): |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
804 |
self.Buffer.Buffering( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
805 |
(EtherCATConfigParser.Dumps(self.Config), |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
806 |
ProcessVariablesParser.Dumps(self.ProcessVariables))) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
807 |
|
2111 | 808 |
def ModelIsSaved(self): |
809 |
if self.Buffer is not None: |
|
810 |
return self.Buffer.IsCurrentSaved() |
|
811 |
else: |
|
812 |
return True |
|
813 |
||
814 |
def LoadPrevious(self): |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
815 |
config, process_variables = self.Buffer.Previous() |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
816 |
self.Config = EtherCATConfigParser.Loads(config) |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
817 |
self.ProcessVariables = ProcessVariablesParser.Loads(process_variables) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
818 |
|
2111 | 819 |
def LoadNext(self): |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
820 |
config, process_variables = self.Buffer.Next() |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
821 |
self.Config = EtherCATConfigParser.Loads(config) |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
822 |
self.ProcessVariables = ProcessVariablesParser.Loads(process_variables) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
823 |
|
2111 | 824 |
def GetBufferState(self): |
825 |
first = self.Buffer.IsFirst() |
|
826 |
last = self.Buffer.IsLast() |
|
827 |
return not first, not last |