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