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