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