author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Fri, 28 Sep 2018 19:22:14 +0300 | |
changeset 2368 | 642ae95218b6 |
parent 2366 | d635680e4c2c |
child 2375 | cfa68a06a24d |
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 |
||
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
19 |
# ------------------------------------------ |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
20 |
from CommonEtherCATFunction import _CommonSlave |
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
21 |
# ------------------------------------------ |
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
|
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", |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
25 |
"USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", |
2111 | 26 |
"BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L"} |
27 |
||
28 |
DATATYPECONVERSION = {"BOOL" : "BIT", "SINT" : "S8", "INT" : "S16", "DINT" : "S32", "LINT" : "S64", |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
29 |
"USINT" : "U8", "UINT" : "U16", "UDINT" : "U32", "ULINT" : "U64", |
2111 | 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 |
||
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2356
diff
changeset
|
34 |
|
2111 | 35 |
def ExtractHexDecValue(value): |
36 |
try: |
|
37 |
return int(value) |
|
2353
8f1a2846b2f5
cleanup etherlab: pep8, E722 do not use bare except
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
38 |
except Exception: |
2111 | 39 |
pass |
40 |
try: |
|
41 |
return int(value.replace("#", "0"), 16) |
|
2353
8f1a2846b2f5
cleanup etherlab: pep8, E722 do not use bare except
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
42 |
except Exception: |
2111 | 43 |
raise ValueError, "Invalid value for HexDecValue \"%s\"" % value |
44 |
||
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2356
diff
changeset
|
45 |
|
2111 | 46 |
def GenerateHexDecValue(value, base=10): |
47 |
if base == 10: |
|
48 |
return str(value) |
|
49 |
elif base == 16: |
|
50 |
return "#x%.8x" % value |
|
51 |
else: |
|
52 |
raise ValueError, "Not supported base" |
|
53 |
||
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2356
diff
changeset
|
54 |
|
2111 | 55 |
def ExtractName(names, default=None): |
56 |
if len(names) == 1: |
|
57 |
return names[0].getcontent() |
|
58 |
else: |
|
59 |
for name in names: |
|
60 |
if name.getLcId() == 1033: |
|
61 |
return name.getcontent() |
|
62 |
return default |
|
63 |
||
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
|
64 |
|
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
65 |
# -------------------------------------------------- |
2111 | 66 |
# Ethercat Node |
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
67 |
# -------------------------------------------------- |
2111 | 68 |
|
69 |
class _EthercatSlaveCTN: |
|
70 |
NODE_PROFILE = None |
|
71 |
EditorType = NodeEditor |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
72 |
|
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
|
73 |
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
|
74 |
# ----------- 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
|
75 |
self.CommonMethod = _CommonSlave(self) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
76 |
|
2111 | 77 |
def GetIconName(self): |
78 |
return "Slave" |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
79 |
|
2111 | 80 |
def ExtractHexDecValue(self, value): |
81 |
return ExtractHexDecValue(value) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
82 |
|
2111 | 83 |
def GetSizeOfType(self, type): |
84 |
return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
85 |
|
2111 | 86 |
def GetSlavePos(self): |
87 |
return self.BaseParams.getIEC_Channel() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
88 |
|
2366
d635680e4c2c
cleanup etherlab: pep8, E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2363
diff
changeset
|
89 |
def GetParamsAttributes(self, path=None): |
2111 | 90 |
if path: |
91 |
parts = path.split(".", 1) |
|
92 |
if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
|
93 |
return self.MandatoryParams[1].getElementInfos(parts[0], parts[1]) |
|
94 |
elif self.CTNParams and parts[0] == self.CTNParams[0]: |
|
95 |
return self.CTNParams[1].getElementInfos(parts[0], parts[1]) |
|
96 |
else: |
|
97 |
params = [] |
|
98 |
if self.CTNParams: |
|
99 |
params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0])) |
|
100 |
else: |
|
101 |
params.append({ |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
102 |
'use': 'required', |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
103 |
'type': 'element', |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
104 |
'name': 'SlaveParams', |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
105 |
'value': None, |
2111 | 106 |
'children': [] |
107 |
}) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
108 |
|
2111 | 109 |
slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos()) |
110 |
params[0]['children'].insert(0, |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
111 |
{'use': 'optional', |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
112 |
'type': self.CTNParent.GetSlaveTypesLibrary(self.NODE_PROFILE), |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
113 |
'name': 'Type', |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
114 |
'value': (slave_type["device_type"], slave_type)}) |
2111 | 115 |
params[0]['children'].insert(1, |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
116 |
{'use': 'optional', |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
117 |
'type': 'unsignedLong', |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
118 |
'name': 'Alias', |
2111 | 119 |
'value': self.CTNParent.GetSlaveAlias(self.GetSlavePos())}) |
120 |
return params |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
121 |
|
2111 | 122 |
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
|
123 |
self.GetSlaveInfos() |
2111 | 124 |
position = self.BaseParams.getIEC_Channel() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
125 |
|
2111 | 126 |
if path == "SlaveParams.Type": |
127 |
self.CTNParent.SetSlaveType(position, value) |
|
128 |
slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos()) |
|
129 |
value = (slave_type["device_type"], slave_type) |
|
2356
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
130 |
# if self._View is not None: |
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
131 |
# wx.CallAfter(self._View.EtherCATManagementTreebook.SlaveStatePanel.RefreshSlaveInfos()) |
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
132 |
# self._View.EtherCATManagementTreebook.SlaveStatePanel.RefreshSlaveInfos() |
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
133 |
# self._View.EtherCATManagementTreebook.PDOMonitoringPanel.PDOInfoUpdate() |
c26e0c66d8d5
cleanup etherlab: pep8, E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
134 |
# self._View.EtherCATManagementTreebook.SmartView.Create_SmartView() |
2111 | 135 |
return value, True |
136 |
elif path == "SlaveParams.Alias": |
|
137 |
self.CTNParent.SetSlaveAlias(position, value) |
|
138 |
return value, True |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
139 |
|
2111 | 140 |
value, refresh = ConfigTreeNode.SetParamsAttribute(self, path, value) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
141 |
|
2111 | 142 |
# Filter IEC_Channel, Slave_Type and Alias that have specific behavior |
143 |
if path == "BaseParams.IEC_Channel" and value != position: |
|
144 |
self.CTNParent.SetSlavePosition(position, value) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
145 |
|
2111 | 146 |
return value, refresh |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
147 |
|
2111 | 148 |
def GetSlaveInfos(self): |
149 |
return self.CTNParent.GetSlaveInfos(self.GetSlavePos()) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
150 |
|
2111 | 151 |
def GetSlaveVariables(self, limits): |
152 |
return self.CTNParent.GetSlaveVariables(self.GetSlavePos(), limits) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2353
diff
changeset
|
153 |
|
2111 | 154 |
def GetVariableLocationTree(self): |
2362
6d31ef14f396
cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
155 |
return { |
6d31ef14f396
cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
156 |
"name": self.BaseParams.getName(), |
6d31ef14f396
cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
157 |
"type": LOCATION_CONFNODE, |
6d31ef14f396
cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
158 |
"location": self.GetFullIEC_Channel(), |
6d31ef14f396
cleanup etherlab: pep8, E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
159 |
"children": self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName()) |
2111 | 160 |
} |
161 |
||
162 |
def CTNGenerate_C(self, buildpath, locations): |
|
2363
9c7da6ff6a34
cleanup etherlab: pep8, E231 missing whitespace after ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2362
diff
changeset
|
163 |
return [], "", False |