author | Laurent Bessard |
Tue, 25 Jun 2013 00:55:38 +0200 | |
changeset 2156 | c8eee6be2da8 |
parent 2152 | e6946c298a42 |
child 2157 | a2385e535cf5 |
permissions | -rw-r--r-- |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1 |
import os, shutil |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
2 |
from xml.dom import minidom |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
3 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
4 |
import wx |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
5 |
import csv |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
6 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
7 |
from xmlclass import * |
2111 | 8 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
9 |
from ConfigTreeNode import ConfigTreeNode |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
10 |
from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
2111 | 11 |
|
12 |
from EthercatSlave import ExtractHexDecValue, ExtractName |
|
13 |
from EthercatMaster import _EthercatCTN |
|
14 |
from ConfigEditor import LibraryEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
15 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
16 |
#-------------------------------------------------- |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
17 |
# Ethercat ConfNode |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
18 |
#-------------------------------------------------- |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
19 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
20 |
EtherCATInfoClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATInfo.xsd")) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
21 |
|
2074
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
22 |
cls = EtherCATInfoClasses["EtherCATBase.xsd"].get("DictionaryType", None) |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
23 |
if cls: |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
24 |
cls.loadXMLTreeArgs = None |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
25 |
|
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
26 |
setattr(cls, "_loadXMLTree", getattr(cls, "loadXMLTree")) |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
27 |
|
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
28 |
def loadXMLTree(self, *args): |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
29 |
self.loadXMLTreeArgs = args |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
30 |
setattr(cls, "loadXMLTree", loadXMLTree) |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
31 |
|
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
32 |
def load(self): |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
33 |
if self.loadXMLTreeArgs is not None: |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
34 |
self._loadXMLTree(*self.loadXMLTreeArgs) |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
35 |
self.loadXMLTreeArgs = None |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
36 |
setattr(cls, "load", load) |
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
37 |
|
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
38 |
cls = EtherCATInfoClasses["EtherCATInfo.xsd"].get("DeviceType", None) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
39 |
if cls: |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
40 |
cls.DataTypes = None |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
41 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
42 |
def GetProfileNumbers(self): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
43 |
profiles = [] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
44 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
45 |
for profile in self.getProfile(): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
46 |
profile_content = profile.getcontent() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
47 |
if profile_content is None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
48 |
continue |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
49 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
50 |
for content_element in profile_content["value"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
51 |
if content_element["name"] == "ProfileNo": |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
52 |
profiles.append(content_element["value"]) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
53 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
54 |
return profiles |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
55 |
setattr(cls, "GetProfileNumbers", GetProfileNumbers) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
56 |
|
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
57 |
def GetProfileDictionaries(self): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
58 |
dictionaries = [] |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
59 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
60 |
for profile in self.getProfile(): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
61 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
62 |
profile_content = profile.getcontent() |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
63 |
if profile_content is None: |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
64 |
continue |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
65 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
66 |
for content_element in profile_content["value"]: |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
67 |
if content_element["name"] == "Dictionary": |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
68 |
dictionaries.append(content_element["value"]) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
69 |
elif content_element["name"] == "DictionaryFile": |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
70 |
raise ValueError, "DictionaryFile for defining Device Profile is not yet supported!" |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
71 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
72 |
return dictionaries |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
73 |
setattr(cls, "GetProfileDictionaries", GetProfileDictionaries) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
74 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
75 |
def ExtractDataTypes(self): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
76 |
self.DataTypes = {} |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
77 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
78 |
for dictionary in self.GetProfileDictionaries(): |
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
79 |
dictionary.load() |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
80 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
81 |
datatypes = dictionary.getDataTypes() |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
82 |
if datatypes is not None: |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
83 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
84 |
for datatype in datatypes.getDataType(): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
85 |
content = datatype.getcontent() |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
86 |
if content is not None and content["name"] == "SubItem": |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
87 |
self.DataTypes[datatype.getName()] = datatype |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
88 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
89 |
setattr(cls, "ExtractDataTypes", ExtractDataTypes) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
90 |
|
2079
49242019a9ca
Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents:
2077
diff
changeset
|
91 |
def getCoE(self): |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
92 |
mailbox = self.getMailbox() |
2079
49242019a9ca
Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents:
2077
diff
changeset
|
93 |
if mailbox is not None: |
49242019a9ca
Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents:
2077
diff
changeset
|
94 |
return mailbox.getCoE() |
49242019a9ca
Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents:
2077
diff
changeset
|
95 |
return None |
49242019a9ca
Fix C code Generator to use CoE section contained in the slave ESI file for defining Ethercat network configuration
Laurent Bessard
parents:
2077
diff
changeset
|
96 |
setattr(cls, "getCoE", getCoE) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
97 |
|
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
98 |
def GetEntriesList(self, limits=None): |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
99 |
if self.DataTypes is None: |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
100 |
self.ExtractDataTypes() |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
101 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
102 |
entries = {} |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
103 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
104 |
for dictionary in self.GetProfileDictionaries(): |
2074
bf2fa4cb62a9
Adding support for loading Profile dictionaries only if needed
Laurent Bessard
parents:
2073
diff
changeset
|
105 |
dictionary.load() |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
106 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
107 |
for object in dictionary.getObjects().getObject(): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
108 |
entry_index = object.getIndex().getcontent() |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
109 |
index = ExtractHexDecValue(entry_index) |
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
110 |
if limits is None or limits[0] <= index <= limits[1]: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
111 |
entry_type = object.getType() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
112 |
entry_name = ExtractName(object.getName()) |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
113 |
|
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
114 |
entry_type_infos = self.DataTypes.get(entry_type, None) |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
115 |
if entry_type_infos is not None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
116 |
content = entry_type_infos.getcontent() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
117 |
for subitem in content["value"]: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
118 |
entry_subidx = subitem.getSubIdx() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
119 |
if entry_subidx is None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
120 |
entry_subidx = "0" |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
121 |
subidx = ExtractHexDecValue(entry_subidx) |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
122 |
subitem_access = "" |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
123 |
subitem_pdomapping = "" |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
124 |
subitem_flags = subitem.getFlags() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
125 |
if subitem_flags is not None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
126 |
access = subitem_flags.getAccess() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
127 |
if access is not None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
128 |
subitem_access = access.getcontent() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
129 |
pdomapping = subitem_flags.getPdoMapping() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
130 |
if pdomapping is not None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
131 |
subitem_pdomapping = pdomapping.upper() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
132 |
entries[(index, subidx)] = { |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
133 |
"Index": entry_index, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
134 |
"SubIndex": entry_subidx, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
135 |
"Name": "%s - %s" % |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
136 |
(entry_name.decode("utf-8"), |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
137 |
ExtractName(subitem.getDisplayName(), |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
138 |
subitem.getName()).decode("utf-8")), |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
139 |
"Type": subitem.getType(), |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
140 |
"BitSize": subitem.getBitSize(), |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
141 |
"Access": subitem_access, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
142 |
"PDOMapping": subitem_pdomapping} |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
143 |
else: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
144 |
entry_access = "" |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
145 |
entry_pdomapping = "" |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
146 |
entry_flags = object.getFlags() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
147 |
if entry_flags is not None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
148 |
access = entry_flags.getAccess() |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
149 |
if access is not None: |
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
150 |
entry_access = access.getcontent() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
151 |
pdomapping = entry_flags.getPdoMapping() |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
152 |
if pdomapping is not None: |
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
153 |
entry_pdomapping = pdomapping.upper() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
154 |
entries[(index, 0)] = { |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
155 |
"Index": entry_index, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
156 |
"SubIndex": "0", |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
157 |
"Name": entry_name, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
158 |
"Type": entry_type, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
159 |
"BitSize": object.getBitSize(), |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
160 |
"Access": entry_access, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
161 |
"PDOMapping": entry_pdomapping} |
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
|
162 |
|
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
163 |
for TxPdo in self.getTxPdo(): |
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
164 |
ExtractPdoInfos(TxPdo, "Transmit", entries, limits) |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
165 |
for RxPdo in self.getRxPdo(): |
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
166 |
ExtractPdoInfos(RxPdo, "Receive", entries, limits) |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
167 |
|
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
168 |
return entries |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
169 |
setattr(cls, "GetEntriesList", GetEntriesList) |
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
|
170 |
|
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
171 |
def GetSyncManagers(self): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
172 |
sync_managers = [] |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
173 |
for sync_manager in self.getSm(): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
174 |
sync_manager_infos = {} |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
175 |
for name, value in [("Name", sync_manager.getcontent()), |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
176 |
("Start Address", sync_manager.getStartAddress()), |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
177 |
("Default Size", sync_manager.getDefaultSize()), |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
178 |
("Control Byte", sync_manager.getControlByte()), |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
179 |
("Enable", sync_manager.getEnable())]: |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
180 |
if value is None: |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
181 |
value ="" |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
182 |
sync_manager_infos[name] = value |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
183 |
sync_managers.append(sync_manager_infos) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
184 |
return sync_managers |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
185 |
setattr(cls, "GetSyncManagers", GetSyncManagers) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
186 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
187 |
def GroupItemCompare(x, y): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
188 |
if x["type"] == y["type"]: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
189 |
if x["type"] == ETHERCAT_GROUP: |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
190 |
return cmp(x["order"], y["order"]) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
191 |
else: |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
192 |
return cmp(x["name"], y["name"]) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
193 |
elif x["type"] == ETHERCAT_GROUP: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
194 |
return -1 |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
195 |
return 1 |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
196 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
197 |
def SortGroupItems(group): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
198 |
for item in group["children"]: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
199 |
if item["type"] == ETHERCAT_GROUP: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
200 |
SortGroupItems(item) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
201 |
group["children"].sort(GroupItemCompare) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
202 |
|
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
203 |
def ExtractPdoInfos(pdo, pdo_type, entries, limits=None): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
204 |
pdo_index = pdo.getIndex().getcontent() |
2029
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
205 |
pdo_name = ExtractName(pdo.getName()) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
206 |
for pdo_entry in pdo.getEntry(): |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
207 |
entry_index = pdo_entry.getIndex().getcontent() |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
208 |
entry_subindex = pdo_entry.getSubIndex() |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
209 |
index = ExtractHexDecValue(entry_index) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
210 |
subindex = ExtractHexDecValue(entry_subindex) |
7c848efa21c6
Adding support for displaying slave sync managers and profile object dictionary and for arbitrarily mapping variable through variable location
laurent
parents:
2026
diff
changeset
|
211 |
|
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
212 |
if limits is None or limits[0] <= index <= limits[1]: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
213 |
entry = entries.get((index, subindex), None) |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
214 |
if entry is not None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
215 |
entry["PDO index"] = pdo_index |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
216 |
entry["PDO name"] = pdo_name |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
217 |
entry["PDO type"] = pdo_type |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
218 |
else: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
219 |
entry_type = pdo_entry.getDataType() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
220 |
if entry_type is not None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
221 |
if pdo_type == "Transmit": |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
222 |
access = "ro" |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
223 |
pdomapping = "T" |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
224 |
else: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
225 |
access = "wo" |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
226 |
pdomapping = "R" |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
227 |
entries[(index, subindex)] = { |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
228 |
"Index": entry_index, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
229 |
"SubIndex": entry_subindex, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
230 |
"Name": ExtractName(pdo_entry.getName()), |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
231 |
"Type": entry_type.getcontent(), |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
232 |
"Access": access, |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
233 |
"PDOMapping": pdomapping} |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
234 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
235 |
class ModulesLibrary: |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
236 |
|
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
237 |
MODULES_EXTRA_PARAMS = [ |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
238 |
("pdo_alignment", { |
2138
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
239 |
"column_label": _("PDO alignment"), |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
240 |
"column_size": 150, |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
241 |
"default": 8, |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
242 |
"description": _( |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
243 |
"Minimal size in bits between 2 pdo entries")}), |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
244 |
("max_pdo_size", { |
2138
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
245 |
"column_label": _("Max entries by PDO"), |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
246 |
"column_size": 150, |
2139
1565239349a8
Added support for module extra params in EthercatCFileGenerator
Laurent Bessard
parents:
2138
diff
changeset
|
247 |
"default": 255, |
2138
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
248 |
"description": _( |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
249 |
"""Maximal number of entries mapped in a PDO |
2139
1565239349a8
Added support for module extra params in EthercatCFileGenerator
Laurent Bessard
parents:
2138
diff
changeset
|
250 |
including empty entries used for PDO alignment""")}), |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
251 |
("add_pdo", { |
2138
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
252 |
"column_label": _("Creating new PDO"), |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
253 |
"column_size": 150, |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
254 |
"default": 0, |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
255 |
"description": _( |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
256 |
"""Adding a PDO not defined in default configuration |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
257 |
for mapping needed location variables |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
258 |
(1 if possible)""")}) |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
259 |
] |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
260 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
261 |
def __init__(self, path, parent_library=None): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
262 |
self.Path = path |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
263 |
if not os.path.exists(self.Path): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
264 |
os.makedirs(self.Path) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
265 |
self.ParentLibrary = parent_library |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
266 |
|
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
267 |
if parent_library is not None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
268 |
self.LoadModules() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
269 |
else: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
270 |
self.Library = None |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
271 |
self.LoadModulesExtraParams() |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
272 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
273 |
def GetPath(self): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
274 |
return self.Path |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
275 |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
276 |
def GetModulesExtraParamsFilePath(self): |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
277 |
return os.path.join(self.Path, "modules_extra_params.cfg") |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
278 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
279 |
def LoadModules(self): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
280 |
self.Library = {} |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
281 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
282 |
files = os.listdir(self.Path) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
283 |
for file in files: |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
284 |
filepath = os.path.join(self.Path, file) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
285 |
if os.path.isfile(filepath) and os.path.splitext(filepath)[-1] == ".xml": |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
286 |
xmlfile = open(filepath, 'r') |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
287 |
xml_tree = minidom.parse(xmlfile) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
288 |
xmlfile.close() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
289 |
|
2152
e6946c298a42
Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents:
2149
diff
changeset
|
290 |
self.modules_infos = None |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
291 |
for child in xml_tree.childNodes: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
292 |
if child.nodeType == xml_tree.ELEMENT_NODE and child.nodeName == "EtherCATInfo": |
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
|
293 |
self.modules_infos = EtherCATInfoClasses["EtherCATInfo.xsd"]["EtherCATInfo"]() |
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
|
294 |
self.modules_infos.loadXMLTree(child) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
295 |
|
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
|
296 |
if self.modules_infos is not None: |
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
|
297 |
vendor = self.modules_infos.getVendor() |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
298 |
|
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
299 |
vendor_category = self.Library.setdefault(ExtractHexDecValue(vendor.getId()), |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
300 |
{"name": ExtractName(vendor.getName(), _("Miscellaneous")), |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
301 |
"groups": {}}) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
302 |
|
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
|
303 |
for group in self.modules_infos.getDescriptions().getGroups().getGroup(): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
304 |
group_type = group.getType() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
305 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
306 |
vendor_category["groups"].setdefault(group_type, {"name": ExtractName(group.getName(), group_type), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
307 |
"parent": group.getParentGroup(), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
308 |
"order": group.getSortOrder(), |
2152
e6946c298a42
Cherry-pick and re-commit to legitimate ancestor of commit 'Ethercat Management Function Refactoring Source by RTES Lab.' from youcu <youcu1022@gmail.com>
Edouard Tisserant
parents:
2149
diff
changeset
|
309 |
"value": group.getcontent()["value"], |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
310 |
"devices": []}) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
311 |
|
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
|
312 |
for device in self.modules_infos.getDescriptions().getDevices().getDevice(): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
313 |
device_group = device.getGroupType() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
314 |
if not vendor_category["groups"].has_key(device_group): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
315 |
raise ValueError, "Not such group \"%\"" % device_group |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
316 |
vendor_category["groups"][device_group]["devices"].append((device.getType().getcontent(), device)) |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
317 |
|
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
|
318 |
return self.Library |
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
|
319 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
320 |
def GetModulesLibrary(self, profile_filter=None): |
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
321 |
if self.Library is None: |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
322 |
self.LoadModules() |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
323 |
library = [] |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
324 |
for vendor_id, vendor in self.Library.iteritems(): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
325 |
groups = [] |
2073
d14ab97a452a
Fix bug modules present in all groups with the same name even if they are defined by different vendors
Laurent Bessard
parents:
2069
diff
changeset
|
326 |
children_dict = {} |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
327 |
for group_type, group in vendor["groups"].iteritems(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
328 |
group_infos = {"name": group["name"], |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
329 |
"order": group["order"], |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
330 |
"type": ETHERCAT_GROUP, |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
331 |
"infos": None, |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
332 |
"children": children_dict.setdefault(group_type, [])} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
333 |
device_dict = {} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
334 |
for device_type, device in group["devices"]: |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
335 |
if profile_filter is None or profile_filter in device.GetProfileNumbers(): |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
336 |
product_code = device.getType().getProductCode() |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
337 |
revision_number = device.getType().getRevisionNo() |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
338 |
module_infos = {"device_type": device_type, |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
339 |
"vendor": vendor_id, |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
340 |
"product_code": product_code, |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
341 |
"revision_number": revision_number} |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
342 |
module_infos.update(self.GetModuleExtraParams(vendor_id, product_code, revision_number)) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
343 |
device_infos = {"name": ExtractName(device.getName()), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
344 |
"type": ETHERCAT_DEVICE, |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
345 |
"infos": module_infos, |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
346 |
"children": []} |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
347 |
group_infos["children"].append(device_infos) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
348 |
device_type_occurrences = device_dict.setdefault(device_type, []) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
349 |
device_type_occurrences.append(device_infos) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
350 |
for device_type_occurrences in device_dict.itervalues(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
351 |
if len(device_type_occurrences) > 1: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
352 |
for occurrence in device_type_occurrences: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
353 |
occurrence["name"] += _(" (rev. %s)") % occurrence["infos"]["revision_number"] |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
354 |
if len(group_infos["children"]) > 0: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
355 |
if group["parent"] is not None: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
356 |
parent_children = children_dict.setdefault(group["parent"], []) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
357 |
parent_children.append(group_infos) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
358 |
else: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
359 |
groups.append(group_infos) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
360 |
if len(groups) > 0: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
361 |
library.append({"name": vendor["name"], |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
362 |
"type": ETHERCAT_VENDOR, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
363 |
"infos": None, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
364 |
"children": groups}) |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
365 |
library.sort(lambda x, y: cmp(x["name"], y["name"])) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
366 |
return library |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
367 |
|
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
368 |
def GetVendors(self): |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
369 |
return [(vendor_id, vendor["name"]) for vendor_id, vendor in self.Library.items()] |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
370 |
|
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
371 |
def GetModuleInfos(self, module_infos): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
372 |
vendor = ExtractHexDecValue(module_infos["vendor"]) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
373 |
vendor_infos = self.Library.get(vendor) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
374 |
if vendor_infos is not None: |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
375 |
for group_name, group_infos in vendor_infos["groups"].iteritems(): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
376 |
for device_type, device_infos in group_infos["devices"]: |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
377 |
product_code = ExtractHexDecValue(device_infos.getType().getProductCode()) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
378 |
revision_number = ExtractHexDecValue(device_infos.getType().getRevisionNo()) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
379 |
if (product_code == ExtractHexDecValue(module_infos["product_code"]) and |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
380 |
revision_number == ExtractHexDecValue(module_infos["revision_number"])): |
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
|
381 |
self.cntdevice = device_infos |
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
|
382 |
self.cntdeviceType = device_type |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
383 |
return device_infos, self.GetModuleExtraParams(vendor, product_code, revision_number) |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
384 |
return None, None |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
385 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
386 |
def ImportModuleLibrary(self, filepath): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
387 |
if os.path.isfile(filepath): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
388 |
shutil.copy(filepath, self.Path) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
389 |
self.LoadModules() |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
390 |
return True |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
391 |
return False |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
392 |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
393 |
def LoadModulesExtraParams(self): |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
394 |
self.ModulesExtraParams = {} |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
395 |
|
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
396 |
csvfile_path = self.GetModulesExtraParamsFilePath() |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
397 |
if os.path.exists(csvfile_path): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
398 |
csvfile = open(csvfile_path, "rb") |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
399 |
sample = csvfile.read(1024) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
400 |
csvfile.seek(0) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
401 |
dialect = csv.Sniffer().sniff(sample) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
402 |
has_header = csv.Sniffer().has_header(sample) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
403 |
reader = csv.reader(csvfile, dialect) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
404 |
for row in reader: |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
405 |
if has_header: |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
406 |
has_header = False |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
407 |
else: |
2138
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
408 |
params_values = {} |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
409 |
for (param, param_infos), value in zip( |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
410 |
self.MODULES_EXTRA_PARAMS, row[3:]): |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
411 |
if value != "": |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
412 |
params_values[param] = int(value) |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
413 |
self.ModulesExtraParams[ |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
414 |
tuple(map(int, row[:3]))] = params_values |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
415 |
csvfile.close() |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
416 |
|
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
417 |
def SaveModulesExtraParams(self): |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
418 |
csvfile = open(self.GetModulesExtraParamsFilePath(), "wb") |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
419 |
extra_params = [param for param, params_infos in self.MODULES_EXTRA_PARAMS] |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
420 |
writer = csv.writer(csvfile, delimiter=';') |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
421 |
writer.writerow(['Vendor', 'product_code', 'revision_number'] + extra_params) |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
422 |
for (vendor, product_code, revision_number), module_extra_params in self.ModulesExtraParams.iteritems(): |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
423 |
writer.writerow([vendor, product_code, revision_number] + |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
424 |
[module_extra_params.get(param, '') |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
425 |
for param in extra_params]) |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
426 |
csvfile.close() |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
427 |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
428 |
def SetModuleExtraParam(self, vendor, product_code, revision_number, param, value): |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
429 |
vendor = ExtractHexDecValue(vendor) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
430 |
product_code = ExtractHexDecValue(product_code) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
431 |
revision_number = ExtractHexDecValue(revision_number) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
432 |
|
2138
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
433 |
module_infos = (vendor, product_code, revision_number) |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
434 |
self.ModulesExtraParams.setdefault(module_infos, {}) |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
435 |
self.ModulesExtraParams[module_infos][param] = value |
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
436 |
|
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
437 |
self.SaveModulesExtraParams() |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
438 |
|
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
439 |
def GetModuleExtraParams(self, vendor, product_code, revision_number): |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
440 |
vendor = ExtractHexDecValue(vendor) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
441 |
product_code = ExtractHexDecValue(product_code) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
442 |
revision_number = ExtractHexDecValue(revision_number) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
443 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
444 |
if self.ParentLibrary is not None: |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
445 |
extra_params = self.ParentLibrary.GetModuleExtraParams(vendor, product_code, revision_number) |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
446 |
else: |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
447 |
extra_params = {} |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
448 |
|
2138
79dc2d15c580
Fixed support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2137
diff
changeset
|
449 |
extra_params.update(self.ModulesExtraParams.get((vendor, product_code, revision_number), {})) |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
450 |
|
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
451 |
for param, param_infos in self.MODULES_EXTRA_PARAMS: |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
452 |
extra_params.setdefault(param, param_infos["default"]) |
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
453 |
|
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2133
diff
changeset
|
454 |
return extra_params |
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
455 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
456 |
USERDATA_DIR = wx.StandardPaths.Get().GetUserDataDir() |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
457 |
if wx.Platform != '__WXMSW__': |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
458 |
USERDATA_DIR += '_files' |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
459 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
460 |
ModulesDatabase = ModulesLibrary( |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
461 |
os.path.join(USERDATA_DIR, "ethercat_modules")) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
462 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
463 |
class RootClass: |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
464 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
465 |
CTNChildrenTypes = [("EthercatNode",_EthercatCTN,"Ethercat Master")] |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
466 |
EditorType = LibraryEditor |
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
|
467 |
|
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
|
468 |
|
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
469 |
def __init__(self): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
470 |
self.ModulesLibrary = None |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
471 |
self.LoadModulesLibrary() |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
472 |
|
2149
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2139
diff
changeset
|
473 |
def GetIconName(self): |
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2139
diff
changeset
|
474 |
return "Ethercat" |
7f473761c932
Added icon for Ethercat extension root and Ethercat master node
Laurent Bessard
parents:
2139
diff
changeset
|
475 |
|
2133 | 476 |
def GetModulesLibraryPath(self, project_path=None): |
477 |
if project_path is None: |
|
478 |
project_path = self.CTNPath() |
|
479 |
return os.path.join(project_path, "modules") |
|
480 |
||
481 |
def OnCTNSave(self, from_project_path=None): |
|
482 |
if from_project_path is not None: |
|
483 |
shutil.copytree(self.GetModulesLibraryPath(from_project_path), |
|
484 |
self.GetModulesLibraryPath()) |
|
485 |
return True |
|
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
486 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
487 |
def CTNGenerate_C(self, buildpath, locations): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
488 |
return [],"",False |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
489 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
490 |
def LoadModulesLibrary(self): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
491 |
if self.ModulesLibrary is None: |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
492 |
self.ModulesLibrary = ModulesLibrary(self.GetModulesLibraryPath(), ModulesDatabase) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
493 |
else: |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
494 |
self.ModulesLibrary.LoadModulesLibrary() |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
495 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
496 |
def GetModulesDatabaseInstance(self): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
497 |
return ModulesDatabase |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
498 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
499 |
def GetModulesLibraryInstance(self): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
500 |
return self.ModulesLibrary |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
501 |
|
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
502 |
def GetModulesLibrary(self, profile_filter=None): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
503 |
return self.ModulesLibrary.GetModulesLibrary(profile_filter) |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
504 |
|
2098
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
505 |
def GetVendors(self): |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
506 |
return self.ModulesLibrary.GetVendors() |
392791b5cc04
Improved Ethercat Network Configurator panels
Laurent Bessard
parents:
2097
diff
changeset
|
507 |
|
2097
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
508 |
def GetModuleInfos(self, module_infos): |
58d07e039896
Added panel for managing ESI files from project and from database including module PDO alignment setting
Laurent Bessard
parents:
2096
diff
changeset
|
509 |
return self.ModulesLibrary.GetModuleInfos(module_infos) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
510 |