author | Laurent Bessard |
Mon, 24 Jun 2013 09:23:28 +0200 | |
changeset 2153 | 91c10856adaa |
parent 2152 | e6946c298a42 |
child 2165 | 02a2b5dee5e3 |
permissions | -rw-r--r-- |
2111 | 1 |
import wx |
2 |
||
3 |
from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
|
4 |
from ConfigTreeNode import ConfigTreeNode |
|
5 |
||
6 |
from ConfigEditor import NodeEditor |
|
7 |
||
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:
2131
diff
changeset
|
8 |
#------------------------------------------ |
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:
2131
diff
changeset
|
9 |
from CommonEtherCATFunction import _CommonSlave |
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:
2131
diff
changeset
|
10 |
#------------------------------------------ |
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:
2131
diff
changeset
|
11 |
|
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:
2131
diff
changeset
|
12 |
|
2111 | 13 |
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L", |
14 |
"USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", |
|
15 |
"BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L"} |
|
16 |
||
17 |
DATATYPECONVERSION = {"BOOL" : "BIT", "SINT" : "S8", "INT" : "S16", "DINT" : "S32", "LINT" : "S64", |
|
18 |
"USINT" : "U8", "UINT" : "U16", "UDINT" : "U32", "ULINT" : "U64", |
|
19 |
"BYTE" : "U8", "WORD" : "U16", "DWORD" : "U32", "LWORD" : "U64"} |
|
20 |
||
21 |
VARCLASSCONVERSION = {"T": LOCATION_VAR_INPUT, "R": LOCATION_VAR_OUTPUT, "RT": LOCATION_VAR_MEMORY} |
|
22 |
||
23 |
def ExtractHexDecValue(value): |
|
24 |
try: |
|
25 |
return int(value) |
|
26 |
except: |
|
27 |
pass |
|
28 |
try: |
|
29 |
return int(value.replace("#", "0"), 16) |
|
30 |
except: |
|
31 |
raise ValueError, "Invalid value for HexDecValue \"%s\"" % value |
|
32 |
||
33 |
def GenerateHexDecValue(value, base=10): |
|
34 |
if base == 10: |
|
35 |
return str(value) |
|
36 |
elif base == 16: |
|
37 |
return "#x%.8x" % value |
|
38 |
else: |
|
39 |
raise ValueError, "Not supported base" |
|
40 |
||
41 |
def ExtractName(names, default=None): |
|
42 |
if len(names) == 1: |
|
43 |
return names[0].getcontent() |
|
44 |
else: |
|
45 |
for name in names: |
|
46 |
if name.getLcId() == 1033: |
|
47 |
return name.getcontent() |
|
48 |
return default |
|
49 |
||
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:
2131
diff
changeset
|
50 |
|
2111 | 51 |
#-------------------------------------------------- |
52 |
# Ethercat Node |
|
53 |
#-------------------------------------------------- |
|
54 |
||
55 |
class _EthercatSlaveCTN: |
|
56 |
NODE_PROFILE = None |
|
57 |
EditorType = NodeEditor |
|
58 |
||
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:
2131
diff
changeset
|
59 |
def __init__(self): |
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:
2131
diff
changeset
|
60 |
# ----------- 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:
2131
diff
changeset
|
61 |
self.CommonMethod = _CommonSlave(self) |
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:
2131
diff
changeset
|
62 |
|
2111 | 63 |
def GetIconName(self): |
64 |
return "Slave" |
|
65 |
||
66 |
def ExtractHexDecValue(self, value): |
|
67 |
return ExtractHexDecValue(value) |
|
68 |
||
69 |
def GetSizeOfType(self, type): |
|
70 |
return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) |
|
71 |
||
72 |
def GetSlavePos(self): |
|
73 |
return self.BaseParams.getIEC_Channel() |
|
74 |
||
75 |
def GetParamsAttributes(self, path = None): |
|
76 |
if path: |
|
77 |
parts = path.split(".", 1) |
|
78 |
if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
|
79 |
return self.MandatoryParams[1].getElementInfos(parts[0], parts[1]) |
|
80 |
elif self.CTNParams and parts[0] == self.CTNParams[0]: |
|
81 |
return self.CTNParams[1].getElementInfos(parts[0], parts[1]) |
|
82 |
else: |
|
83 |
params = [] |
|
84 |
if self.CTNParams: |
|
85 |
params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0])) |
|
86 |
else: |
|
87 |
params.append({ |
|
88 |
'use': 'required', |
|
89 |
'type': 'element', |
|
90 |
'name': 'SlaveParams', |
|
91 |
'value': None, |
|
92 |
'children': [] |
|
93 |
}) |
|
94 |
||
95 |
slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos()) |
|
96 |
params[0]['children'].insert(0, |
|
97 |
{'use': 'optional', |
|
98 |
'type': self.CTNParent.GetSlaveTypesLibrary(self.NODE_PROFILE), |
|
99 |
'name': 'Type', |
|
100 |
'value': (slave_type["device_type"], slave_type)}) |
|
101 |
params[0]['children'].insert(1, |
|
102 |
{'use': 'optional', |
|
103 |
'type': 'unsignedLong', |
|
104 |
'name': 'Alias', |
|
105 |
'value': self.CTNParent.GetSlaveAlias(self.GetSlavePos())}) |
|
106 |
return params |
|
107 |
||
108 |
def SetParamsAttribute(self, path, value): |
|
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:
2131
diff
changeset
|
109 |
self.GetSlaveInfos() |
2111 | 110 |
position = self.BaseParams.getIEC_Channel() |
111 |
||
112 |
if path == "SlaveParams.Type": |
|
113 |
self.CTNParent.SetSlaveType(position, value) |
|
114 |
slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos()) |
|
115 |
value = (slave_type["device_type"], slave_type) |
|
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:
2131
diff
changeset
|
116 |
#if self._View 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:
2131
diff
changeset
|
117 |
#wx.CallAfter(self._View.EtherCATManagementTreebook.SlaveStatePanel.RefreshSlaveInfos()) |
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:
2131
diff
changeset
|
118 |
#self._View.EtherCATManagementTreebook.SlaveStatePanel.RefreshSlaveInfos() |
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:
2131
diff
changeset
|
119 |
#self._View.EtherCATManagementTreebook.PDOMonitoringPanel.PDOInfoUpdate() |
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:
2131
diff
changeset
|
120 |
#self._View.EtherCATManagementTreebook.SmartView.Create_SmartView() |
2111 | 121 |
return value, True |
122 |
elif path == "SlaveParams.Alias": |
|
123 |
self.CTNParent.SetSlaveAlias(position, value) |
|
124 |
return value, True |
|
125 |
||
126 |
value, refresh = ConfigTreeNode.SetParamsAttribute(self, path, value) |
|
127 |
||
128 |
# Filter IEC_Channel, Slave_Type and Alias that have specific behavior |
|
129 |
if path == "BaseParams.IEC_Channel" and value != position: |
|
130 |
self.CTNParent.SetSlavePosition(position, value) |
|
131 |
||
132 |
return value, refresh |
|
133 |
||
134 |
def GetSlaveInfos(self): |
|
135 |
return self.CTNParent.GetSlaveInfos(self.GetSlavePos()) |
|
136 |
||
137 |
def GetSlaveVariables(self, limits): |
|
138 |
return self.CTNParent.GetSlaveVariables(self.GetSlavePos(), limits) |
|
139 |
||
140 |
def GetVariableLocationTree(self): |
|
141 |
return {"name": self.BaseParams.getName(), |
|
142 |
"type": LOCATION_CONFNODE, |
|
143 |
"location": self.GetFullIEC_Channel(), |
|
144 |
"children": self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName()) |
|
145 |
} |
|
146 |
||
147 |
def CTNGenerate_C(self, buildpath, locations): |
|
148 |
return [],"",False |