author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Fri, 28 Sep 2018 13:07:46 +0300 | |
changeset 2350 | 9f7028ab8294 |
parent 2165 | 02a2b5dee5e3 |
child 2353 | 8f1a2846b2f5 |
child 2641 | c9deff128c37 |
permissions | -rw-r--r-- |
2165
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
1 |
#!/usr/bin/env python |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
3 |
|
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
4 |
# This file is part of Beremiz |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
5 |
# |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
6 |
# Copyright (C) 2011-2014: Laurent BESSARD, Edouard TISSERANT |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
7 |
# RTES Lab : CRKim, JBLee, youcu |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
8 |
# Higen Motor : Donggu Kang |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
9 |
# |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2152
diff
changeset
|
11 |
|
2111 | 12 |
import wx |
13 |
||
14 |
from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
|
15 |
from ConfigTreeNode import ConfigTreeNode |
|
16 |
||
17 |
from ConfigEditor import NodeEditor |
|
18 |
||
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
|
19 |
#------------------------------------------ |
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
|
20 |
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
|
21 |
#------------------------------------------ |
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
|
22 |
|
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
|
23 |
|
2111 | 24 |
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L", |
25 |
"USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", |
|
26 |
"BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L"} |
|
27 |
||
28 |
DATATYPECONVERSION = {"BOOL" : "BIT", "SINT" : "S8", "INT" : "S16", "DINT" : "S32", "LINT" : "S64", |
|
29 |
"USINT" : "U8", "UINT" : "U16", "UDINT" : "U32", "ULINT" : "U64", |
|
30 |
"BYTE" : "U8", "WORD" : "U16", "DWORD" : "U32", "LWORD" : "U64"} |
|
31 |
||
32 |
VARCLASSCONVERSION = {"T": LOCATION_VAR_INPUT, "R": LOCATION_VAR_OUTPUT, "RT": LOCATION_VAR_MEMORY} |
|
33 |
||
34 |
def ExtractHexDecValue(value): |
|
35 |
try: |
|
36 |
return int(value) |
|
37 |
except: |
|
38 |
pass |
|
39 |
try: |
|
40 |
return int(value.replace("#", "0"), 16) |
|
41 |
except: |
|
42 |
raise ValueError, "Invalid value for HexDecValue \"%s\"" % value |
|
43 |
||
44 |
def GenerateHexDecValue(value, base=10): |
|
45 |
if base == 10: |
|
46 |
return str(value) |
|
47 |
elif base == 16: |
|
48 |
return "#x%.8x" % value |
|
49 |
else: |
|
50 |
raise ValueError, "Not supported base" |
|
51 |
||
52 |
def ExtractName(names, default=None): |
|
53 |
if len(names) == 1: |
|
54 |
return names[0].getcontent() |
|
55 |
else: |
|
56 |
for name in names: |
|
57 |
if name.getLcId() == 1033: |
|
58 |
return name.getcontent() |
|
59 |
return default |
|
60 |
||
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
|
61 |
|
2111 | 62 |
#-------------------------------------------------- |
63 |
# Ethercat Node |
|
64 |
#-------------------------------------------------- |
|
65 |
||
66 |
class _EthercatSlaveCTN: |
|
67 |
NODE_PROFILE = None |
|
68 |
EditorType = NodeEditor |
|
69 |
||
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
|
70 |
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
|
71 |
# ----------- 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
|
72 |
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
|
73 |
|
2111 | 74 |
def GetIconName(self): |
75 |
return "Slave" |
|
76 |
||
77 |
def ExtractHexDecValue(self, value): |
|
78 |
return ExtractHexDecValue(value) |
|
79 |
||
80 |
def GetSizeOfType(self, type): |
|
81 |
return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) |
|
82 |
||
83 |
def GetSlavePos(self): |
|
84 |
return self.BaseParams.getIEC_Channel() |
|
85 |
||
86 |
def GetParamsAttributes(self, path = None): |
|
87 |
if path: |
|
88 |
parts = path.split(".", 1) |
|
89 |
if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
|
90 |
return self.MandatoryParams[1].getElementInfos(parts[0], parts[1]) |
|
91 |
elif self.CTNParams and parts[0] == self.CTNParams[0]: |
|
92 |
return self.CTNParams[1].getElementInfos(parts[0], parts[1]) |
|
93 |
else: |
|
94 |
params = [] |
|
95 |
if self.CTNParams: |
|
96 |
params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0])) |
|
97 |
else: |
|
98 |
params.append({ |
|
99 |
'use': 'required', |
|
100 |
'type': 'element', |
|
101 |
'name': 'SlaveParams', |
|
102 |
'value': None, |
|
103 |
'children': [] |
|
104 |
}) |
|
105 |
||
106 |
slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos()) |
|
107 |
params[0]['children'].insert(0, |
|
108 |
{'use': 'optional', |
|
109 |
'type': self.CTNParent.GetSlaveTypesLibrary(self.NODE_PROFILE), |
|
110 |
'name': 'Type', |
|
111 |
'value': (slave_type["device_type"], slave_type)}) |
|
112 |
params[0]['children'].insert(1, |
|
113 |
{'use': 'optional', |
|
114 |
'type': 'unsignedLong', |
|
115 |
'name': 'Alias', |
|
116 |
'value': self.CTNParent.GetSlaveAlias(self.GetSlavePos())}) |
|
117 |
return params |
|
118 |
||
119 |
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
|
120 |
self.GetSlaveInfos() |
2111 | 121 |
position = self.BaseParams.getIEC_Channel() |
122 |
||
123 |
if path == "SlaveParams.Type": |
|
124 |
self.CTNParent.SetSlaveType(position, value) |
|
125 |
slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos()) |
|
126 |
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
|
127 |
#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
|
128 |
#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
|
129 |
#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
|
130 |
#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
|
131 |
#self._View.EtherCATManagementTreebook.SmartView.Create_SmartView() |
2111 | 132 |
return value, True |
133 |
elif path == "SlaveParams.Alias": |
|
134 |
self.CTNParent.SetSlaveAlias(position, value) |
|
135 |
return value, True |
|
136 |
||
137 |
value, refresh = ConfigTreeNode.SetParamsAttribute(self, path, value) |
|
138 |
||
139 |
# Filter IEC_Channel, Slave_Type and Alias that have specific behavior |
|
140 |
if path == "BaseParams.IEC_Channel" and value != position: |
|
141 |
self.CTNParent.SetSlavePosition(position, value) |
|
142 |
||
143 |
return value, refresh |
|
144 |
||
145 |
def GetSlaveInfos(self): |
|
146 |
return self.CTNParent.GetSlaveInfos(self.GetSlavePos()) |
|
147 |
||
148 |
def GetSlaveVariables(self, limits): |
|
149 |
return self.CTNParent.GetSlaveVariables(self.GetSlavePos(), limits) |
|
150 |
||
151 |
def GetVariableLocationTree(self): |
|
152 |
return {"name": self.BaseParams.getName(), |
|
153 |
"type": LOCATION_CONFNODE, |
|
154 |
"location": self.GetFullIEC_Channel(), |
|
155 |
"children": self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName()) |
|
156 |
} |
|
157 |
||
158 |
def CTNGenerate_C(self, buildpath, locations): |
|
159 |
return [],"",False |