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