author | Edouard Tisserant |
Tue, 02 Feb 2021 11:20:54 +0100 | |
branch | svghmi |
changeset 3123 | f8cba959553f |
parent 2993 | b76f303ffce6 |
child 3750 | f62625418bff |
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 |
|
26 |
from POULibrary import POULibrary |
|
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 |
|
78 |
||
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 |
|
2993
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2643
diff
changeset
|
100 |
# TODO : rename to match runtime_{location}_extname.py format |
b76f303ffce6
Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents:
2643
diff
changeset
|
101 |
|
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
102 |
# -------------------------------------------------- |
2111 | 103 |
# Ethercat MASTER |
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
104 |
# -------------------------------------------------- |
2111 | 105 |
|
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
|
106 |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
107 |
EtherCATConfigParser = GenerateParserFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATConfig.xsd")) |
2111 | 108 |
|
109 |
||
110 |
def sort_commands(x, y): |
|
111 |
if x["Index"] == y["Index"]: |
|
112 |
return cmp(x["Subindex"], y["Subindex"]) |
|
113 |
return cmp(x["Index"], y["Index"]) |
|
114 |
||
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
|
115 |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
116 |
cls = EtherCATConfigParser.GetElementClass("Slave", "Config") |
2111 | 117 |
if cls: |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
118 |
|
2111 | 119 |
def getType(self): |
120 |
slave_info = self.getInfo() |
|
121 |
return {"device_type": slave_info.getName(), |
|
122 |
"vendor": GenerateHexDecValue(slave_info.getVendorId()), |
|
123 |
"product_code": GenerateHexDecValue(slave_info.getProductCode(), 16), |
|
124 |
"revision_number": GenerateHexDecValue(slave_info.getRevisionNo(), 16)} |
|
125 |
setattr(cls, "getType", getType) |
|
126 |
||
127 |
def setType(self, type_infos): |
|
128 |
slave_info = self.getInfo() |
|
129 |
slave_info.setName(type_infos["device_type"]) |
|
130 |
slave_info.setVendorId(ExtractHexDecValue(type_infos["vendor"])) |
|
131 |
slave_info.setProductCode(ExtractHexDecValue(type_infos["product_code"])) |
|
132 |
slave_info.setRevisionNo(ExtractHexDecValue(type_infos["revision_number"])) |
|
133 |
setattr(cls, "setType", setType) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
134 |
|
2111 | 135 |
def getInitCmds(self, create_default=False): |
136 |
Mailbox = self.getMailbox() |
|
137 |
if Mailbox is None: |
|
138 |
if create_default: |
|
139 |
self.addMailbox() |
|
140 |
Mailbox = self.getMailbox() |
|
141 |
else: |
|
142 |
return None |
|
143 |
CoE = Mailbox.getCoE() |
|
144 |
if CoE is None: |
|
145 |
if create_default: |
|
146 |
Mailbox.addCoE() |
|
147 |
CoE = Mailbox.getCoE() |
|
148 |
else: |
|
149 |
return None |
|
150 |
InitCmds = CoE.getInitCmds() |
|
151 |
if InitCmds is None and create_default: |
|
152 |
CoE.addInitCmds() |
|
153 |
InitCmds = CoE.getInitCmds() |
|
154 |
return InitCmds |
|
155 |
setattr(cls, "getInitCmds", getInitCmds) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
156 |
|
2111 | 157 |
def getStartupCommands(self): |
158 |
pos = self.getInfo().getPhysAddr() |
|
159 |
InitCmds = self.getInitCmds() |
|
160 |
if InitCmds is None: |
|
161 |
return [] |
|
162 |
commands = [] |
|
163 |
for idx, InitCmd in enumerate(InitCmds.getInitCmd()): |
|
164 |
comment = InitCmd.getComment() |
|
165 |
if comment is None: |
|
166 |
comment = "" |
|
167 |
commands.append({ |
|
168 |
"command_idx": idx, |
|
169 |
"Position": pos, |
|
170 |
"Index": InitCmd.getIndex(), |
|
171 |
"Subindex": InitCmd.getSubIndex(), |
|
172 |
"Value": InitCmd.getData(), |
|
173 |
"Description": comment}) |
|
174 |
commands.sort(sort_commands) |
|
175 |
return commands |
|
176 |
setattr(cls, "getStartupCommands", getStartupCommands) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
177 |
|
2111 | 178 |
def appendStartupCommand(self, command_infos): |
179 |
InitCmds = self.getInitCmds(True) |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
180 |
command = EtherCATConfigParser.CreateElement("InitCmd", "InitCmds", 1) |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
181 |
InitCmds.appendInitCmd(command) |
2111 | 182 |
command.setIndex(command_infos["Index"]) |
183 |
command.setSubIndex(command_infos["Subindex"]) |
|
184 |
command.setData(command_infos["Value"]) |
|
185 |
command.setComment(command_infos["Description"]) |
|
186 |
return len(InitCmds.getInitCmd()) - 1 |
|
187 |
setattr(cls, "appendStartupCommand", appendStartupCommand) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
188 |
|
2111 | 189 |
def setStartupCommand(self, command_infos): |
190 |
InitCmds = self.getInitCmds() |
|
191 |
if InitCmds is not None: |
|
192 |
commands = InitCmds.getInitCmd() |
|
193 |
if command_infos["command_idx"] < len(commands): |
|
194 |
command = commands[command_infos["command_idx"]] |
|
195 |
command.setIndex(command_infos["Index"]) |
|
196 |
command.setSubIndex(command_infos["Subindex"]) |
|
197 |
command.setData(command_infos["Value"]) |
|
198 |
command.setComment(command_infos["Description"]) |
|
199 |
setattr(cls, "setStartupCommand", setStartupCommand) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
200 |
|
2111 | 201 |
def removeStartupCommand(self, command_idx): |
202 |
InitCmds = self.getInitCmds() |
|
203 |
if InitCmds is not None: |
|
204 |
if command_idx < len(InitCmds.getInitCmd()): |
|
205 |
InitCmds.removeInitCmd(command_idx) |
|
206 |
setattr(cls, "removeStartupCommand", removeStartupCommand) |
|
207 |
||
208 |
ProcessVariablesXSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
|
209 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
210 |
<xsd:element name="ProcessVariables"> |
|
211 |
<xsd:complexType> |
|
212 |
<xsd:sequence> |
|
213 |
<xsd:element name="variable" minOccurs="0" maxOccurs="unbounded"> |
|
214 |
<xsd:complexType> |
|
215 |
<xsd:sequence> |
|
216 |
<xsd:element name="ReadFrom" type="LocationDesc" minOccurs="0"/> |
|
217 |
<xsd:element name="WriteTo" type="LocationDesc" minOccurs="0"/> |
|
218 |
</xsd:sequence> |
|
219 |
<xsd:attribute name="Name" type="xsd:string" use="required"/> |
|
220 |
<xsd:attribute name="Comment" type="xsd:string" use="required"/> |
|
221 |
</xsd:complexType> |
|
222 |
</xsd:element> |
|
223 |
</xsd:sequence> |
|
224 |
</xsd:complexType> |
|
225 |
</xsd:element> |
|
226 |
<xsd:complexType name="LocationDesc"> |
|
227 |
<xsd:attribute name="Position" type="xsd:integer" use="required"/> |
|
228 |
<xsd:attribute name="Index" type="xsd:integer" use="required"/> |
|
229 |
<xsd:attribute name="SubIndex" type="xsd:integer" use="required"/> |
|
230 |
</xsd:complexType> |
|
231 |
</xsd:schema> |
|
232 |
""" |
|
233 |
||
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
234 |
ProcessVariablesParser = GenerateParserFromXSDstring(ProcessVariablesXSD) |
2111 | 235 |
|
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2358
diff
changeset
|
236 |
|
2397
25f16349644b
clean etherlab: pylint, C1001 # (old-style-class) Old-style class defined.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2396
diff
changeset
|
237 |
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
|
238 |
|
2111 | 239 |
CTNChildrenTypes = [("EthercatSlave", _EthercatSlaveCTN, "Ethercat Slave")] |
240 |
if HAS_MCL: |
|
241 |
CTNChildrenTypes.append(("EthercatCIA402Slave", _EthercatCIA402SlaveCTN, "Ethercat CIA402 Slave")) |
|
242 |
EditorType = MasterEditor |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
243 |
|
2111 | 244 |
def __init__(self): |
245 |
config_filepath = self.ConfigFileName() |
|
246 |
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
|
247 |
self.Config = None |
2643
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
248 |
# if os.path.isfile(config_filepath): |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
249 |
# config_xmlfile = open(config_filepath, 'r') |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
250 |
# try: |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
251 |
# self.Config, error = \ |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
252 |
# EtherCATConfigParser.LoadXMLString(config_xmlfile.read()) |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
253 |
# if error is None: |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
254 |
# config_is_saved = True |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
255 |
# except Exception as e: |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
256 |
# error = str(e) |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
257 |
# config_xmlfile.close() |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
258 |
|
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
259 |
# if error is not None: |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
260 |
# self.GetCTRoot().logger.write_error( |
b98d9e08231f
Etherlab : Merged 2014-2018 changes from jblee and others
Edouard Tisserant <edouard.tisserant@gmail.com>
diff
changeset
|
261 |
# _("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
|
262 |
|
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
|
263 |
if self.Config is None: |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
264 |
self.Config = EtherCATConfigParser.CreateElement("EtherCATConfig") |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
265 |
|
2111 | 266 |
process_filepath = self.ProcessVariablesFileName() |
267 |
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
|
268 |
self.ProcessVariables = None |
2111 | 269 |
if os.path.isfile(process_filepath): |
270 |
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
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
process_is_saved = True |
2418
5587c490a070
Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2407
diff
changeset
|
276 |
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
|
277 |
error = str(e) |
2111 | 278 |
process_xmlfile.close() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
279 |
|
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
|
280 |
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
|
281 |
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
|
282 |
_("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
|
283 |
|
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
|
284 |
if self.ProcessVariables is None: |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
285 |
self.ProcessVariables = ProcessVariablesParser.CreateElement("ProcessVariables") |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
286 |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
287 |
#if config_is_saved and process_is_saved: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
288 |
if process_is_saved: |
2111 | 289 |
self.CreateBuffer(True) |
290 |
else: |
|
291 |
self.CreateBuffer(False) |
|
292 |
self.OnCTNSave() |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
293 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
294 |
if os.path.isfile(config_filepath): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
295 |
config_xmlfile = open(config_filepath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
296 |
try: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
297 |
self.Config, error = \ |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
298 |
EtherCATConfigParser.LoadXMLString(config_xmlfile.read()) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
299 |
if error is None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
300 |
config_is_saved = True |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
301 |
except Exception, e: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
302 |
error = e.message |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
303 |
config_xmlfile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
304 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
305 |
if error is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
306 |
self.GetCTRoot().logger.write_error( |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
307 |
_("Couldn't load %s network configuration file.") % CTNName) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
308 |
|
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
|
309 |
# ----------- 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
|
310 |
self.CommonMethod = _CommonSlave(self) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
311 |
|
2149
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2147
diff
changeset
|
312 |
def GetIconName(self): |
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2147
diff
changeset
|
313 |
return "Ethercat" |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
314 |
|
2111 | 315 |
def GetContextualMenuItems(self): |
2423
2c7b7ae24d57
Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2418
diff
changeset
|
316 |
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
|
317 |
|
2111 | 318 |
def OnAddEthercatSlave(self, event): |
319 |
app_frame = self.GetCTRoot().AppFrame |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
320 |
dialog = BrowseValuesLibraryDialog(app_frame, |
2423
2c7b7ae24d57
Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2418
diff
changeset
|
321 |
_("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
|
322 |
self.GetSlaveTypesLibrary()) |
2111 | 323 |
if dialog.ShowModal() == wx.ID_OK: |
324 |
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
|
325 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 326 |
if device is not None: |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
327 |
if HAS_MCL and str(_EthercatCIA402SlaveCTN.NODE_PROFILE) in device.GetProfileNumbers(): |
2111 | 328 |
ConfNodeType = "EthercatCIA402Slave" |
329 |
else: |
|
330 |
ConfNodeType = "EthercatSlave" |
|
331 |
new_child = self.CTNAddChild("%s_0" % ConfNodeType, ConfNodeType) |
|
332 |
new_child.SetParamsAttribute("SlaveParams.Type", type_infos) |
|
333 |
self.CTNRequestSave() |
|
334 |
new_child._OpenView() |
|
335 |
app_frame._Refresh(TITLE, FILEMENU, PROJECTTREE) |
|
336 |
dialog.Destroy() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
337 |
|
2111 | 338 |
def ExtractHexDecValue(self, value): |
339 |
return ExtractHexDecValue(value) |
|
340 |
||
341 |
def GetSizeOfType(self, type): |
|
342 |
return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) |
|
343 |
||
344 |
def ConfigFileName(self): |
|
345 |
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
|
346 |
|
2111 | 347 |
def ProcessVariablesFileName(self): |
348 |
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
|
349 |
|
2111 | 350 |
def FilterSlave(self, slave, vendor=None, slave_pos=None, slave_profile=None): |
351 |
if slave_pos is not None and slave.getInfo().getPhysAddr() != slave_pos: |
|
352 |
return False |
|
353 |
type_infos = slave.getType() |
|
354 |
if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor: |
|
355 |
return False |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
356 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 357 |
if slave_profile is not None and slave_profile not in device.GetProfileNumbers(): |
358 |
return False |
|
359 |
return True |
|
360 |
||
2124
1f2c3fdd70d0
Fixed bugs in drag'n drop from variables panel in master and slaves editor panel
Laurent Bessard
parents:
2113
diff
changeset
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
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
|
365 |
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
|
366 |
|
2111 | 367 |
def GetSlaves(self, vendor=None, slave_pos=None, slave_profile=None): |
368 |
slaves = [] |
|
369 |
for slave in self.Config.getConfig().getSlave(): |
|
370 |
if self.FilterSlave(slave, vendor, slave_pos, slave_profile): |
|
371 |
slaves.append(slave.getInfo().getPhysAddr()) |
|
372 |
slaves.sort() |
|
373 |
return slaves |
|
374 |
||
375 |
def GetSlave(self, slave_pos): |
|
376 |
for slave in self.Config.getConfig().getSlave(): |
|
377 |
slave_info = slave.getInfo() |
|
378 |
if slave_info.getPhysAddr() == slave_pos: |
|
379 |
return slave |
|
380 |
return None |
|
381 |
||
382 |
def GetStartupCommands(self, vendor=None, slave_pos=None, slave_profile=None): |
|
383 |
commands = [] |
|
384 |
for slave in self.Config.getConfig().getSlave(): |
|
385 |
if self.FilterSlave(slave, vendor, slave_pos, slave_profile): |
|
386 |
commands.append((slave.getInfo().getPhysAddr(), slave.getStartupCommands())) |
|
387 |
commands.sort() |
|
388 |
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
|
389 |
|
2111 | 390 |
def AppendStartupCommand(self, command_infos): |
391 |
slave = self.GetSlave(command_infos["Position"]) |
|
392 |
if slave is not None: |
|
393 |
command_idx = slave.appendStartupCommand(command_infos) |
|
394 |
self.BufferModel() |
|
395 |
return command_idx |
|
396 |
return None |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
397 |
|
2111 | 398 |
def SetStartupCommandInfos(self, command_infos): |
399 |
slave = self.GetSlave(command_infos["Position"]) |
|
400 |
if slave is not None: |
|
401 |
slave.setStartupCommand(command_infos) |
|
402 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
403 |
|
2111 | 404 |
def RemoveStartupCommand(self, slave_pos, command_idx, buffer=True): |
405 |
slave = self.GetSlave(slave_pos) |
|
406 |
if slave is not None: |
|
407 |
slave.removeStartupCommand(command_idx) |
|
408 |
if buffer: |
|
409 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
410 |
|
2111 | 411 |
def SetProcessVariables(self, variables): |
412 |
vars = [] |
|
413 |
for var in variables: |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
414 |
variable = ProcessVariablesParser.CreateElement("variable", "ProcessVariables") |
2111 | 415 |
variable.setName(var["Name"]) |
416 |
variable.setComment(var["Description"]) |
|
417 |
if var["ReadFrom"] != "": |
|
418 |
position, index, subindex = var["ReadFrom"] |
|
419 |
if variable.getReadFrom() is None: |
|
420 |
variable.addReadFrom() |
|
421 |
read_from = variable.getReadFrom() |
|
422 |
read_from.setPosition(position) |
|
423 |
read_from.setIndex(index) |
|
424 |
read_from.setSubIndex(subindex) |
|
425 |
elif variable.getReadFrom() is not None: |
|
426 |
variable.deleteReadFrom() |
|
427 |
if var["WriteTo"] != "": |
|
428 |
position, index, subindex = var["WriteTo"] |
|
429 |
if variable.getWriteTo() is None: |
|
430 |
variable.addWriteTo() |
|
431 |
write_to = variable.getWriteTo() |
|
432 |
write_to.setPosition(position) |
|
433 |
write_to.setIndex(index) |
|
434 |
write_to.setSubIndex(subindex) |
|
435 |
elif variable.getWriteTo() is not None: |
|
436 |
variable.deleteWriteTo() |
|
437 |
vars.append(variable) |
|
438 |
self.ProcessVariables.setvariable(vars) |
|
439 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
440 |
|
2111 | 441 |
def GetProcessVariables(self): |
442 |
variables = [] |
|
443 |
idx = 0 |
|
444 |
for variable in self.ProcessVariables.getvariable(): |
|
445 |
var = {"Name": variable.getName(), |
|
446 |
"Number": idx, |
|
447 |
"Description": variable.getComment()} |
|
448 |
read_from = variable.getReadFrom() |
|
449 |
if read_from is not None: |
|
450 |
var["ReadFrom"] = (read_from.getPosition(), |
|
451 |
read_from.getIndex(), |
|
452 |
read_from.getSubIndex()) |
|
453 |
else: |
|
454 |
var["ReadFrom"] = "" |
|
455 |
write_to = variable.getWriteTo() |
|
456 |
if write_to is not None: |
|
457 |
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
|
458 |
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
|
459 |
write_to.getSubIndex()) |
2111 | 460 |
else: |
461 |
var["WriteTo"] = "" |
|
462 |
variables.append(var) |
|
463 |
idx += 1 |
|
464 |
return variables |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
465 |
|
2111 | 466 |
def _ScanNetwork(self): |
467 |
app_frame = self.GetCTRoot().AppFrame |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
468 |
|
2111 | 469 |
execute = True |
470 |
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
|
471 |
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
|
472 |
app_frame, |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
473 |
_("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
|
474 |
_("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
|
475 |
wx.YES_NO | wx.ICON_QUESTION) |
2111 | 476 |
execute = dialog.ShowModal() == wx.ID_YES |
477 |
dialog.Destroy() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
478 |
|
2111 | 479 |
if execute: |
2366
d635680e4c2c
cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2363
diff
changeset
|
480 |
error, returnVal = self.RemoteExec(SCAN_COMMAND, returnVal=None) |
2111 | 481 |
if error != 0: |
2423
2c7b7ae24d57
Improve localization support in etherlab (mostly)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2418
diff
changeset
|
482 |
dialog = wx.MessageDialog(app_frame, returnVal, _("Error"), wx.OK | wx.ICON_ERROR) |
2111 | 483 |
dialog.ShowModal() |
484 |
dialog.Destroy() |
|
485 |
elif returnVal is not None: |
|
486 |
for child in self.IECSortedChildren(): |
|
487 |
self._doRemoveChild(child) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
488 |
|
2111 | 489 |
for slave in returnVal: |
490 |
type_infos = { |
|
491 |
"vendor": slave["vendor_id"], |
|
492 |
"product_code": slave["product_code"], |
|
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
493 |
"revision_number": slave["revision_number"], |
2111 | 494 |
} |
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
495 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 496 |
if device is not None: |
497 |
if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers(): |
|
498 |
CTNType = "EthercatCIA402Slave" |
|
499 |
else: |
|
500 |
CTNType = "EthercatSlave" |
|
501 |
self.CTNAddChild("slave%s" % slave["idx"], CTNType, slave["idx"]) |
|
502 |
self.SetSlaveAlias(slave["idx"], slave["alias"]) |
|
503 |
type_infos["device_type"] = device.getType().getcontent() |
|
504 |
self.SetSlaveType(slave["idx"], type_infos) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
505 |
|
2127
32255ca50fb0
Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents:
2124
diff
changeset
|
506 |
if app_frame: |
32255ca50fb0
Fix scan network functionality, project tree not refreshed after adding slaves
Laurent Bessard
parents:
2124
diff
changeset
|
507 |
app_frame.RefreshProjectTree() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
508 |
|
2111 | 509 |
def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0): |
510 |
""" |
|
511 |
Create the confnodes that may be added as child to this node self |
|
512 |
@param CTNType: string desining the confnode class name (get name from CTNChildrenTypes) |
|
513 |
@param CTNName: string for the name of the confnode instance |
|
514 |
""" |
|
515 |
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
|
516 |
|
2111 | 517 |
slave = self.GetSlave(newConfNodeOpj.BaseParams.getIEC_Channel()) |
518 |
if slave is None: |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
519 |
slave = EtherCATConfigParser.CreateElement("Slave", "Config") |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
520 |
self.Config.getConfig().appendSlave(slave) |
2111 | 521 |
slave_infos = slave.getInfo() |
522 |
slave_infos.setName("undefined") |
|
523 |
slave_infos.setPhysAddr(newConfNodeOpj.BaseParams.getIEC_Channel()) |
|
524 |
slave_infos.setAutoIncAddr(0) |
|
525 |
self.BufferModel() |
|
526 |
self.OnCTNSave() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
527 |
|
2111 | 528 |
return newConfNodeOpj |
529 |
||
530 |
def _doRemoveChild(self, CTNInstance): |
|
531 |
slave_pos = CTNInstance.GetSlavePos() |
|
532 |
config = self.Config.getConfig() |
|
533 |
for idx, slave in enumerate(config.getSlave()): |
|
534 |
slave_infos = slave.getInfo() |
|
535 |
if slave_infos.getPhysAddr() == slave_pos: |
|
536 |
config.removeSlave(idx) |
|
537 |
self.BufferModel() |
|
538 |
self.OnCTNSave() |
|
539 |
ConfigTreeNode._doRemoveChild(self, CTNInstance) |
|
540 |
||
541 |
def SetSlavePosition(self, slave_pos, new_pos): |
|
542 |
slave = self.GetSlave(slave_pos) |
|
543 |
if slave is not None: |
|
544 |
slave_info = slave.getInfo() |
|
545 |
slave_info.setPhysAddr(new_pos) |
|
546 |
for variable in self.ProcessVariables.getvariable(): |
|
547 |
read_from = variable.getReadFrom() |
|
548 |
if read_from is not None and read_from.getPosition() == slave_pos: |
|
549 |
read_from.setPosition(new_pos) |
|
550 |
write_to = variable.getWriteTo() |
|
551 |
if write_to is not None and write_to.getPosition() == slave_pos: |
|
552 |
write_to.setPosition(new_pos) |
|
553 |
self.CreateBuffer(True) |
|
2147
a8b095de63e8
Fix bug in when moving Ethercat slaves fixed
Laurent Bessard
parents:
2141
diff
changeset
|
554 |
self.CTNRequestSave() |
2111 | 555 |
if self._View is not None: |
556 |
self._View.RefreshView() |
|
557 |
self._View.RefreshBuffer() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
558 |
|
2111 | 559 |
def GetSlaveAlias(self, slave_pos): |
560 |
slave = self.GetSlave(slave_pos) |
|
561 |
if slave is not None: |
|
562 |
slave_info = slave.getInfo() |
|
563 |
return slave_info.getAutoIncAddr() |
|
564 |
return None |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
565 |
|
2111 | 566 |
def SetSlaveAlias(self, slave_pos, alias): |
567 |
slave = self.GetSlave(slave_pos) |
|
568 |
if slave is not None: |
|
569 |
slave_info = slave.getInfo() |
|
570 |
slave_info.setAutoIncAddr(alias) |
|
571 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
572 |
|
2111 | 573 |
def GetSlaveType(self, slave_pos): |
574 |
slave = self.GetSlave(slave_pos) |
|
575 |
if slave is not None: |
|
576 |
return slave.getType() |
|
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 SetSlaveType(self, slave_pos, type_infos): |
580 |
slave = self.GetSlave(slave_pos) |
|
581 |
if slave is not None: |
|
582 |
slave.setType(type_infos) |
|
583 |
self.BufferModel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
584 |
|
2111 | 585 |
def GetSlaveInfos(self, slave_pos): |
586 |
slave = self.GetSlave(slave_pos) |
|
587 |
if slave is not None: |
|
588 |
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
|
589 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 590 |
if device is not None: |
591 |
infos = type_infos.copy() |
|
592 |
infos.update({"physics": device.getPhysics(), |
|
593 |
"sync_managers": device.GetSyncManagers(), |
|
594 |
"entries": self.GetSlaveVariables(device)}) |
|
595 |
return infos |
|
596 |
return None |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
597 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
598 |
def GetSlaveVariables(self, slave_pos=None, limits=None, device=None, module=None): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
599 |
# add jblee |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
600 |
files = os.listdir(self.CTNPath()) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
601 |
moduleNames = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
602 |
modulePos = 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
603 |
for file in files: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
604 |
filepath = os.path.join(self.CTNPath(), file) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
605 |
if os.path.isdir(filepath): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
606 |
MDPFilePath = os.path.join(filepath, "DataForMDP.txt") |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
607 |
CheckConfNodePath = os.path.join(filepath, "baseconfnode.xml") |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
608 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
609 |
try : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
610 |
moduleDataFile = open(MDPFilePath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
611 |
confNodeFile = open(CheckConfNodePath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
612 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
613 |
lines = moduleDataFile.readlines() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
614 |
checklines = confNodeFile.readlines() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
615 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
616 |
moduleDataFile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
617 |
confNodeFile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
618 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
619 |
module_info = self.GetModuleEntryList() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
620 |
# checklines(ex) : <BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="EthercatSlave_0"/> |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
621 |
# checklines[1].split() : [<BaseParams, xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
622 |
# IEC_Channel="0", Name="EthercatSlave_0"/>] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
623 |
# checklines[1].split()[2] : IEC_Channel="0" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
624 |
# checklines[1].split()[2].split("\"") = [IEC_Channel=, 0, ] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
625 |
pos_check = int(checklines[1].split()[2].split("\"")[1]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
626 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
627 |
if slave_pos != pos_check: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
628 |
continue |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
629 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
630 |
for line in lines: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
631 |
if line == "\n": |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
632 |
continue |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
633 |
# module_name : ST-1214, ST-2314, ... |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
634 |
# if user add module => ST-1214 3EA, ST-2314 3EA |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
635 |
# each result_module_name : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
636 |
# (ST-1214, Module 1), (ST-1214, Module 2), (ST-1214, Module 3) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
637 |
# (ST-2314, Module 4), (ST-2314, Module 5), (ST-2314, Module 6) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
638 |
module_name = line.split()[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
639 |
result_module_name = module_name + ", Module %d" % modulePos |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
640 |
moduleNames.append(result_module_name) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
641 |
modulePos += 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
642 |
except : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
643 |
pass |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
644 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
645 |
if device is None and slave_pos is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
646 |
slave = self.GetSlave(slave_pos) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
647 |
if slave is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
648 |
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
|
649 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
650 |
if device is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
651 |
# Test OD |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
652 |
entries = device.GetEntriesList(limits) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
653 |
#entries = self.CTNParent.GetEntriesList() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
654 |
entries_list = entries.items() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
655 |
entries_list.sort() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
656 |
entries = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
657 |
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
|
658 |
current_entry = {} |
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
659 |
for (index, _subindex), entry in entries_list: |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
660 |
entry["children"] = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
661 |
if slave_pos is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
662 |
entry["Position"] = str(slave_pos) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
663 |
if index != current_index: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
664 |
current_index = index |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
665 |
current_entry = entry |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
666 |
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
|
667 |
elif current_entry: |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
668 |
current_entry["children"].append(entry) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
669 |
else: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
670 |
entries.append(entry) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
671 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
672 |
increment = self.CTNParent.GetModuleIncrement()[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
673 |
count = 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
674 |
#print module_info |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
675 |
# moduleNameAndPos : (ST-1214, Module 1), (ST-1214, Module 2), ... , |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
676 |
# moduleNameAndPos.split(",") : ["ST-1214", " Module 1"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
677 |
# moduleNameAndPos.split(",")[0] : "ST-1214" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
678 |
for moduleNameAndPos in moduleNames: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
679 |
moduleName = moduleNameAndPos.split(",")[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
680 |
modulePosName = moduleNameAndPos.split(",")[1] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
681 |
idx_increment = int(increment) * count |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
682 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
683 |
for MDP_entry in module_info.get(moduleName): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
684 |
LocalMDPEntry = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
685 |
#print MDP_entry |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
686 |
local_idx = MDP_entry["Index"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
687 |
if ExtractHexDecValue(local_idx) == 0: #and local_idx[0] == "#": |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
688 |
temp_index = ExtractHexDecValue(local_idx) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
689 |
else : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
690 |
temp_index = ExtractHexDecValue(MDP_entry["Index"]) + idx_increment |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
691 |
#temp_index = ExtractHexDecValue(MDP_entry["Index"]) + idx_increment |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
692 |
entry_index = hex(temp_index) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
693 |
entry_subidx = MDP_entry["SubIndex"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
694 |
entry_name = MDP_entry["Name"] + ", " + " " + \ |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
695 |
moduleName + " - " + modulePosName |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
696 |
entry_type = MDP_entry["Type"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
697 |
entry_bitsize = MDP_entry["BitSize"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
698 |
entry_access = MDP_entry["Access"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
699 |
mapping_type = MDP_entry["PDOMapping"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
700 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
701 |
LocalMDPEntry.append({ |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
702 |
"Index": entry_index, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
703 |
"SubIndex": entry_subidx, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
704 |
"Name": entry_name, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
705 |
"Type": entry_type, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
706 |
"BitSize": entry_bitsize, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
707 |
"Access": entry_access, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
708 |
"PDOMapping": mapping_type, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
709 |
"children": ""}) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
710 |
entries.append(LocalMDPEntry[0]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
711 |
count += 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
712 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
713 |
#print entries |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
714 |
return entries |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
715 |
return [] |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
716 |
|
2111 | 717 |
def GetSlaveVariableDataType(self, slave_pos, index, subindex): |
718 |
slave = self.GetSlave(slave_pos) |
|
719 |
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
|
720 |
device, _module_extra_params = self.GetModuleInfos(slave.getType()) |
2111 | 721 |
if device is not None: |
722 |
entries = device.GetEntriesList() |
|
723 |
entry_infos = entries.get((index, subindex)) |
|
724 |
if entry_infos is not None: |
|
725 |
return entry_infos["Type"] |
|
726 |
return None |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
727 |
|
2111 | 728 |
def GetNodesVariables(self, vendor=None, slave_pos=None, slave_profile=None, limits=None): |
729 |
entries = [] |
|
730 |
for slave_position in self.GetSlaves(): |
|
731 |
if slave_pos is not None and slave_position != slave_pos: |
|
732 |
continue |
|
733 |
slave = self.GetSlave(slave_position) |
|
734 |
type_infos = slave.getType() |
|
735 |
if vendor is not None and ExtractHexDecValue(type_infos["vendor"]) != vendor: |
|
736 |
continue |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
737 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 738 |
if slave_profile is not None and slave_profile not in device.GetProfileNumbers(): |
739 |
continue |
|
740 |
entries.extend(self.GetSlaveVariables(slave_position, limits, device)) |
|
741 |
return entries |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
742 |
|
2111 | 743 |
def GetModuleInfos(self, type_infos): |
744 |
return self.CTNParent.GetModuleInfos(type_infos) |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
745 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
746 |
# add jblee |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
747 |
def GetModuleEntryList(self): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
748 |
return self.CTNParent.GetModuleEntryList() |
2111 | 749 |
|
750 |
def GetSlaveTypesLibrary(self, profile_filter=None): |
|
751 |
return self.CTNParent.GetModulesLibrary(profile_filter) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
752 |
|
2111 | 753 |
def GetLibraryVendors(self): |
754 |
return self.CTNParent.GetVendors() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
755 |
|
2111 | 756 |
def GetDeviceLocationTree(self, slave_pos, current_location, device_name): |
757 |
slave = self.GetSlave(slave_pos) |
|
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
758 |
vars = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
759 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
760 |
# add jblee |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
761 |
files = os.listdir(self.CTNPath()) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
762 |
moduleNames = [] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
763 |
modulePos = 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
764 |
for file in files: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
765 |
filepath = os.path.join(self.CTNPath(), file) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
766 |
if os.path.isdir(filepath): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
767 |
MDPFilePath = os.path.join(filepath, "DataForMDP.txt") |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
768 |
CheckConfNodePath = os.path.join(filepath, "baseconfnode.xml") |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
769 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
770 |
try : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
771 |
moduleDataFile = open(MDPFilePath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
772 |
confNodeFile = open(CheckConfNodePath, 'r') |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
773 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
774 |
lines = moduleDataFile.readlines() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
775 |
checklines = confNodeFile.readlines() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
776 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
777 |
moduleDataFile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
778 |
confNodeFile.close() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
779 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
780 |
module_info = self.GetModuleEntryList() |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
781 |
# checklines(ex) : <BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="EthercatSlave_0"/> |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
782 |
# checklines[1].split() : [<BaseParams, xmlns:xsd="http://www.w3.org/2001/XMLSchema" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
783 |
# IEC_Channel="0", Name="EthercatSlave_0"/>] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
784 |
# checklines[1].split()[2] : IEC_Channel="0" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
785 |
# checklines[1].split()[2].split("\"") = [IEC_Channel=, 0, ] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
786 |
pos_check = int(checklines[1].split()[2].split("\"")[1]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
787 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
788 |
if slave_pos != pos_check: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
789 |
continue |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
790 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
791 |
for line in lines: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
792 |
if line == "\n": |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
793 |
continue |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
794 |
# module_name : ST-1214, ST-2314, ... |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
795 |
# if user add module => ST-1214 3EA, ST-2314 3EA |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
796 |
# each result_module_name : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
797 |
# (ST-1214, Module 1), (ST-1214, Module 2), (ST-1214, Module 3) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
798 |
# (ST-2314, Module 4), (ST-2314, Module 5), (ST-2314, Module 6) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
799 |
module_name = line.split()[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
800 |
result_module_name = module_name + ", Module %d" % modulePos |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
801 |
moduleNames.append(result_module_name) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
802 |
modulePos += 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
803 |
except : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
804 |
pass |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
805 |
|
2111 | 806 |
if slave is not None: |
807 |
type_infos = slave.getType() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
808 |
|
2406
ffd091b51cd0
clean etherlab: pylint, W0612 # (unused-variable) Unused variable 'X'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
809 |
device, _module_extra_params = self.GetModuleInfos(type_infos) |
2111 | 810 |
if device is not None: |
811 |
sync_managers = [] |
|
812 |
for sync_manager in device.getSm(): |
|
813 |
sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte()) |
|
814 |
sync_manager_direction = sync_manager_control_byte & 0x0c |
|
815 |
if sync_manager_direction: |
|
816 |
sync_managers.append(LOCATION_VAR_OUTPUT) |
|
817 |
else: |
|
818 |
sync_managers.append(LOCATION_VAR_INPUT) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
819 |
|
2111 | 820 |
entries = device.GetEntriesList().items() |
821 |
entries.sort() |
|
822 |
for (index, subindex), entry in entries: |
|
823 |
var_size = self.GetSizeOfType(entry["Type"]) |
|
824 |
if var_size is not None: |
|
825 |
var_class = VARCLASSCONVERSION.get(entry["PDOMapping"], None) |
|
826 |
if var_class is not None: |
|
827 |
if var_class == LOCATION_VAR_INPUT: |
|
828 |
var_dir = "%I" |
|
829 |
else: |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
830 |
var_dir = "%Q" |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
831 |
|
2380
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
832 |
vars.append({ |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
833 |
"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
|
834 |
"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
|
835 |
"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
|
836 |
"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
|
837 |
"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
|
838 |
"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
|
839 |
(index, subindex)))), |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
840 |
"description": "", |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
841 |
"children": [], |
b35bce45bc5a
clean etherlab: pep8, E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2375
diff
changeset
|
842 |
}) |
2641
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
843 |
|
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
844 |
# add jblee for MDP |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
845 |
if not entries : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
846 |
increment = self.CTNParent.GetModuleIncrement()[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
847 |
count = 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
848 |
for moduleNameAndPos in moduleNames: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
849 |
moduleName = moduleNameAndPos.split(",")[0] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
850 |
idx_increment = int(increment) * count |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
851 |
for MDP_entry in module_info.get(moduleName): |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
852 |
local_idx = MDP_entry["Index"] |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
853 |
if ExtractHexDecValue(local_idx) != 0 and local_idx[0] == "#": |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
854 |
index = ExtractHexDecValue(local_idx) + idx_increment |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
855 |
else : |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
856 |
index = ExtractHexDecValue(MDP_entry["Index"]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
857 |
subindex = int(MDP_entry["SubIndex"]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
858 |
var_class = VARCLASSCONVERSION.get(MDP_entry["PDOMapping"], None) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
859 |
if var_class is not None: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
860 |
if var_class == LOCATION_VAR_INPUT: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
861 |
var_dir = "%I" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
862 |
else: |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
863 |
var_dir = "%Q" |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
864 |
var_size = self.GetSizeOfType(MDP_entry["Type"]) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
865 |
result_name = MDP_entry["Name"] + ", " + moduleNameAndPos |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
866 |
vars.append({"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, result_name), |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
867 |
"type": var_class, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
868 |
"size": var_size, |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
869 |
"IEC_type": MDP_entry["Type"], |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
870 |
"var_name": "%s_%4.4x_%2.2x" % ("_".join(moduleName.split()), index, subindex), |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
871 |
"location": "%s%s%s"%(var_dir, var_size, ".".join(map(str, current_location + |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
872 |
(index, subindex)))), |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
873 |
"description": "", |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
874 |
"children": []}) |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
875 |
count += 1 |
c9deff128c37
EtherCat master plugin : commit changes recovered from KOSMOS 2018 installer, unkown author(s).
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2165
diff
changeset
|
876 |
|
2111 | 877 |
return vars |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
878 |
|
2111 | 879 |
def CTNTestModified(self): |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
880 |
return self.ChangesToSave or not self.ModelIsSaved() |
2111 | 881 |
|
2133 | 882 |
def OnCTNSave(self, from_project_path=None): |
2111 | 883 |
config_filepath = self.ConfigFileName() |
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
884 |
config_xmlfile = open(config_filepath, "w") |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
885 |
config_xmlfile.write(etree.tostring( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
886 |
self.Config, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
887 |
pretty_print=True, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
888 |
xml_declaration=True, |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
889 |
encoding='utf-8')) |
2111 | 890 |
config_xmlfile.close() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
891 |
|
2111 | 892 |
process_filepath = self.ProcessVariablesFileName() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
893 |
|
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
894 |
process_xmlfile = open(process_filepath, "w") |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
895 |
process_xmlfile.write(etree.tostring( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
896 |
self.ProcessVariables, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
897 |
pretty_print=True, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
898 |
xml_declaration=True, |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
899 |
encoding='utf-8')) |
2111 | 900 |
process_xmlfile.close() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
901 |
|
2111 | 902 |
self.Buffer.CurrentSaved() |
903 |
return True |
|
904 |
||
905 |
def GetProcessVariableName(self, location, var_type): |
|
906 |
return "__M%s_%s" % (self.GetSizeOfType(var_type), "_".join(map(str, location))) |
|
907 |
||
908 |
def _Generate_C(self, buildpath, locations): |
|
909 |
current_location = self.GetCurrentLocation() |
|
910 |
# 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
|
911 |
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
|
912 |
|
2358
8e5a9830867e
cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2356
diff
changeset
|
913 |
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
|
914 |
|
2111 | 915 |
self.FileGenerator = _EthercatCFileGenerator(self) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
916 |
|
2111 | 917 |
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
|
918 |
|
2111 | 919 |
for idx, variable in enumerate(self.ProcessVariables.getvariable()): |
920 |
name = None |
|
921 |
var_type = None |
|
922 |
read_from = variable.getReadFrom() |
|
923 |
write_to = variable.getWriteTo() |
|
924 |
if read_from is not None: |
|
925 |
pos = read_from.getPosition() |
|
926 |
index = read_from.getIndex() |
|
927 |
subindex = read_from.getSubIndex() |
|
928 |
location = current_location + (idx, ) |
|
929 |
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
|
930 |
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
|
931 |
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
|
932 |
self.GetProcessVariableName(location, var_type)) |
2111 | 933 |
if write_to is not None: |
934 |
pos = write_to.getPosition() |
|
935 |
index = write_to.getIndex() |
|
936 |
subindex = write_to.getSubIndex() |
|
937 |
if name is None: |
|
938 |
location = current_location + (idx, ) |
|
939 |
var_type = self.GetSlaveVariableDataType(pos, index, subindex) |
|
940 |
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
|
941 |
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
|
942 |
|
2111 | 943 |
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
|
944 |
|
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
|
945 |
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
|
946 |
0, |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
947 |
(current_location, |
2358
8e5a9830867e
cleanup etherlab: pep8, E228 missing whitespace around modulo operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2356
diff
changeset
|
948 |
[(Gen_Ethercatfile_path, '"-I%s"' % os.path.abspath(self.GetCTRoot().GetIECLibPath()))], |
2111 | 949 |
True)) |
2112
e88cd6ff885e
Fixed linking with non RTDM etherlab lib. Now with rtdm...
Edouard Tisserant
parents:
2111
diff
changeset
|
950 |
LDFLAGS.append("-lethercat_rtdm -lrtdm") |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
951 |
|
2111 | 952 |
return LocationCFilesAndCFLAGS, LDFLAGS, extra_files |
953 |
||
954 |
ConfNodeMethods = [ |
|
2375
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
955 |
{ |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
956 |
"bitmap": "ScanNetwork", |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
957 |
"name": _("Scan Network"), |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
958 |
"tooltip": _("Scan Network"), |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
959 |
"method": "_ScanNetwork", |
cfa68a06a24d
clean etherlab: pep8, E203 whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2370
diff
changeset
|
960 |
}, |
2111 | 961 |
] |
962 |
||
963 |
def CTNGenerate_C(self, buildpath, locations): |
|
964 |
current_location = self.GetCurrentLocation() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
965 |
|
2111 | 966 |
slaves = self.GetSlaves() |
967 |
for slave_pos in slaves: |
|
968 |
slave = self.GetSlave(slave_pos) |
|
969 |
if slave is not None: |
|
970 |
self.FileGenerator.DeclareSlave(slave_pos, slave) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
971 |
|
2111 | 972 |
for location in locations: |
973 |
loc = location["LOC"][len(current_location):] |
|
974 |
slave_pos = loc[0] |
|
975 |
if slave_pos in slaves and len(loc) == 3 and location["DIR"] != "M": |
|
976 |
self.FileGenerator.DeclareVariable( |
|
977 |
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
|
978 |
|
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
979 |
return [], "", False |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
980 |
|
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
981 |
# ------------------------------------------------------------------------------- |
2111 | 982 |
# 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
|
983 |
# ------------------------------------------------------------------------------- |
2111 | 984 |
|
985 |
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
|
986 |
"""Return a copy of the config""" |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
987 |
return deepcopy(model) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
988 |
|
2111 | 989 |
def CreateBuffer(self, saved): |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
990 |
self.Buffer = UndoBuffer( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
991 |
(EtherCATConfigParser.Dumps(self.Config), |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
992 |
ProcessVariablesParser.Dumps(self.ProcessVariables)), |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
993 |
saved) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
994 |
|
2111 | 995 |
def BufferModel(self): |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
996 |
self.Buffer.Buffering( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
997 |
(EtherCATConfigParser.Dumps(self.Config), |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
998 |
ProcessVariablesParser.Dumps(self.ProcessVariables))) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
999 |
|
2111 | 1000 |
def ModelIsSaved(self): |
1001 |
if self.Buffer is not None: |
|
1002 |
return self.Buffer.IsCurrentSaved() |
|
1003 |
else: |
|
1004 |
return True |
|
1005 |
||
1006 |
def LoadPrevious(self): |
|
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1007 |
config, process_variables = self.Buffer.Previous() |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1008 |
self.Config = EtherCATConfigParser.Loads(config) |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1009 |
self.ProcessVariables = ProcessVariablesParser.Loads(process_variables) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
1010 |
|
2111 | 1011 |
def LoadNext(self): |
2157
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1012 |
config, process_variables = self.Buffer.Next() |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1013 |
self.Config = EtherCATConfigParser.Loads(config) |
a2385e535cf5
Fixed controllers for working with latest version of xmlclass
Laurent Bessard
parents:
2152
diff
changeset
|
1014 |
self.ProcessVariables = ProcessVariablesParser.Loads(process_variables) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
1015 |
|
2111 | 1016 |
def GetBufferState(self): |
1017 |
first = self.Buffer.IsFirst() |
|
1018 |
last = self.Buffer.IsLast() |
|
1019 |
return not first, not last |