author | laurent |
Mon, 21 May 2012 10:07:35 +0200 | |
changeset 2054 | fea31f89b5f6 |
parent 2053 | 5998beb54a6c |
child 2057 | bb63c0479411 |
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 |
import cPickle |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
3 |
from xml.dom import minidom |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
4 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
5 |
import wx |
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 * |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
8 |
from ConfigTreeNode import ConfigTreeNode |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
9 |
from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2042
diff
changeset
|
10 |
from ConfigEditor import NodeEditor, CIA402NodeEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
11 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
12 |
try: |
2049 | 13 |
from MotionLibrary import Headers, AxisXSD |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
14 |
HAS_MCL = True |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
15 |
except: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
16 |
HAS_MCL = False |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
17 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
18 |
CONFNODEFOLDER = os.path.split(os.path.realpath(__file__))[0] |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
19 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
20 |
TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L", |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
21 |
"USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
22 |
"BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L"} |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
23 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
24 |
DATATYPECONVERSION = {"BOOL" : "BIT", "SINT" : "S8", "INT" : "S16", "DINT" : "S32", "LINT" : "S64", |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
25 |
"USINT" : "U8", "UINT" : "U16", "UDINT" : "U32", "ULINT" : "U64", |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
26 |
"BYTE" : "U8", "WORD" : "U16", "DWORD" : "U32", "LWORD" : "U64"} |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
27 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
28 |
VARCLASSCONVERSION = {"T": LOCATION_VAR_INPUT, "R": LOCATION_VAR_OUTPUT, "RT": LOCATION_VAR_MEMORY} |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
29 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
30 |
#-------------------------------------------------- |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
31 |
# Remote Exec Etherlab Commands |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
32 |
#-------------------------------------------------- |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
33 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
34 |
SCAN_COMMAND = """ |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
35 |
import commands |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
36 |
result = commands.getoutput("ethercat slaves") |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
37 |
slaves = [] |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
38 |
for slave_line in result.splitlines(): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
39 |
chunks = slave_line.split() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
40 |
idx, pos, state, flag = chunks[:4] |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
41 |
name = " ".join(chunks[4:]) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
42 |
alias, position = pos.split(":") |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
43 |
slave = {"idx": int(idx), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
44 |
"alias": int(alias), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
45 |
"position": int(position), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
46 |
"name": name} |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
47 |
details = commands.getoutput("ethercat slaves -p %d -v" % slave["idx"]) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
48 |
for details_line in details.splitlines(): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
49 |
details_line = details_line.strip() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
50 |
for header, param in [("Vendor Id:", "vendor_id"), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
51 |
("Product code:", "product_code"), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
52 |
("Revision number:", "revision_number")]: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
53 |
if details_line.startswith(header): |
2042
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
54 |
slave[param] = details_line.split()[-1] |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
55 |
break |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
56 |
slaves.append(slave) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
57 |
returnVal = slaves |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
58 |
""" |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
59 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
60 |
#-------------------------------------------------- |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
61 |
# Ethercat Node |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
62 |
#-------------------------------------------------- |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
63 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
64 |
class _EthercatSlaveCTN: |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
65 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
66 |
NODE_PROFILE = None |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
67 |
EditorType = NodeEditor |
2034 | 68 |
|
2053 | 69 |
def GetIconPath(self): |
70 |
return os.path.join(CONFNODEFOLDER, "images", "Slave.png") |
|
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2042
diff
changeset
|
71 |
|
2034 | 72 |
def ExtractHexDecValue(self, value): |
73 |
return ExtractHexDecValue(value) |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
74 |
|
2034 | 75 |
def GetSizeOfType(self, type): |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
76 |
return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
77 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
78 |
def GetSlavePos(self): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
79 |
return self.BaseParams.getIEC_Channel() |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
80 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
81 |
def GetParamsAttributes(self, path = None): |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
82 |
if path: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
83 |
parts = path.split(".", 1) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
84 |
if self.MandatoryParams and parts[0] == self.MandatoryParams[0]: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
85 |
return self.MandatoryParams[1].getElementInfos(parts[0], parts[1]) |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
86 |
elif self.CTNParams and parts[0] == self.CTNParams[0]: |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
87 |
return self.CTNParams[1].getElementInfos(parts[0], parts[1]) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
88 |
else: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
89 |
params = [] |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
90 |
if wx.VERSION < (2, 8, 0) and self.MandatoryParams: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
91 |
params.append(self.MandatoryParams[1].getElementInfos(self.MandatoryParams[0])) |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
92 |
slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos()) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
93 |
params.append({ |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
94 |
'use': 'required', |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
95 |
'type': 'element', |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
96 |
'name': 'SlaveParams', |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
97 |
'value': None, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
98 |
'children': [{ |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
99 |
'use': 'optional', |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
100 |
'type': self.CTNParent.GetSlaveTypesLibrary(self.NODE_PROFILE), |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
101 |
'name': 'Type', |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
102 |
'value': (slave_type["device_type"], slave_type)}, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
103 |
{'use': 'optional', |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
104 |
'type': 'unsignedLong', |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
105 |
'name': 'Alias', |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
106 |
'value': self.CTNParent.GetSlaveAlias(self.GetSlavePos())}] |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
107 |
}) |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
108 |
if self.CTNParams: |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
109 |
params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0])) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
110 |
return params |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
111 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
112 |
def SetParamsAttribute(self, path, value): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
113 |
position = self.BaseParams.getIEC_Channel() |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
114 |
value, changed = ConfigTreeNode.SetParamsAttribute(self, path, value) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
115 |
# Filter IEC_Channel, Slave_Type and Alias that have specific behavior |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
116 |
if path == "BaseParams.IEC_Channel": |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
117 |
self.CTNParent.SetSlavePosition(position, value) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
118 |
elif path == "SlaveParams.Type": |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
119 |
self.CTNParent.SetSlaveType(position, value) |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
120 |
slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos()) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
121 |
value = (slave_type["device_type"], slave_type) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
122 |
changed = True |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
123 |
elif path == "SlaveParams.Alias": |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
124 |
self.CTNParent.SetSlaveAlias(position, value) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
125 |
changed = True |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
126 |
return value, changed |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
127 |
|
2034 | 128 |
def GetSlaveInfos(self): |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
129 |
return self.CTNParent.GetSlaveInfos(self.GetSlavePos()) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
130 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
131 |
def GetVariableLocationTree(self): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
132 |
return {"name": self.BaseParams.getName(), |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
133 |
"type": LOCATION_CONFNODE, |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
134 |
"location": self.GetFullIEC_Channel(), |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
135 |
"children": self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName()) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
136 |
} |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
137 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
138 |
def CTNGenerate_C(self, buildpath, locations): |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
139 |
""" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
140 |
Generate C code |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
141 |
@param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
142 |
@param locations: List of complete variables locations \ |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
143 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
144 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
145 |
"DIR" : direction "Q","I" or "M" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
146 |
"SIZE" : size "X", "B", "W", "D", "L" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
147 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
148 |
}, ...] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
149 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
150 |
""" |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
151 |
return [],"",False |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
152 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
153 |
#-------------------------------------------------- |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2042
diff
changeset
|
154 |
# Ethercat CIA402 Node |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
155 |
#-------------------------------------------------- |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
156 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
157 |
if HAS_MCL: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
158 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
159 |
NODE_VARIABLES = [ |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
160 |
("ControlWord", 0x6040, 0x00, "UINT", "Q"), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
161 |
("TargetPosition", 0x607a, 0x00, "DINT", "Q"), |
2045 | 162 |
("ModesOfOperation", 0x06060, 0x00, "SINT", "Q"), |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
163 |
("StatusWord", 0x6041, 0x00, "UINT", "I"), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
164 |
("ModesOfOperationDisplay", 0x06061, 0x00, "SINT", "I"), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
165 |
("ActualPosition", 0x6064, 0x00, "DINT", "I"), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
166 |
] |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
167 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
168 |
class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN): |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
169 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
170 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2042
diff
changeset
|
171 |
<xsd:element name="CIA402SlaveParams"> |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
172 |
<xsd:complexType> |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
173 |
%s |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
174 |
</xsd:complexType> |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
175 |
</xsd:element> |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
176 |
</xsd:schema> |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
177 |
""" % AxisXSD |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
178 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
179 |
NODE_PROFILE = 402 |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2042
diff
changeset
|
180 |
EditorType = CIA402NodeEditor |
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2042
diff
changeset
|
181 |
|
2053 | 182 |
def GetIconPath(self): |
183 |
return os.path.join(CONFNODEFOLDER, "images", "CIA402Slave.png") |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
184 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
185 |
def CTNGenerate_C(self, buildpath, locations): |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
186 |
""" |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
187 |
Generate C code |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
188 |
@param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
189 |
@param locations: List of complete variables locations \ |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
190 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
191 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
192 |
"DIR" : direction "Q","I" or "M" |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
193 |
"SIZE" : size "X", "B", "W", "D", "L" |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
194 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
195 |
}, ...] |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
196 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
197 |
""" |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
198 |
current_location = self.GetCurrentLocation() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
199 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
200 |
location_str = "_".join(map(lambda x:str(x), current_location)) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
201 |
|
2045 | 202 |
plc_cia402node_filepath = os.path.join(os.path.split(__file__)[0], "plc_cia402node.c") |
203 |
plc_cia402node_file = open(plc_cia402node_filepath, 'r') |
|
204 |
plc_cia402node_code = plc_cia402node_file.read() |
|
205 |
plc_cia402node_file.close() |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
206 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
207 |
str_completion = { |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
208 |
"location": location_str, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
209 |
"MCL_headers": Headers, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
210 |
"extern_located_variables_declaration": [], |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
211 |
"entry_variables": [], |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
212 |
"init_axis_params": [], |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
213 |
"init_entry_variables": [], |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
214 |
} |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
215 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
216 |
for variable in NODE_VARIABLES: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
217 |
var_infos = dict(zip(["name", "index", "subindex", "var_type", "dir"], variable)) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
218 |
var_infos["location"] = location_str |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
219 |
var_infos["var_size"] = self.GetSizeOfType(var_infos["var_type"]) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
220 |
var_infos["var_name"] = "__%(dir)s%(var_size)s%(location)s_%(index)d_%(subindex)d" % var_infos |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
221 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
222 |
str_completion["extern_located_variables_declaration"].append( |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
223 |
"IEC_%(var_type)s *%(var_name)s;" % var_infos) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
224 |
str_completion["entry_variables"].append( |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
225 |
" IEC_%(var_type)s *%(name)s;" % var_infos) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
226 |
str_completion["init_entry_variables"].append( |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2042
diff
changeset
|
227 |
" __CIA402Node_%(location)s.%(name)s = %(var_name)s;" % var_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
|
228 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
229 |
self.CTNParent.FileGenerator.DeclareVariable( |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
230 |
self.GetSlavePos(), var_infos["index"], var_infos["subindex"], |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
231 |
var_infos["var_type"], var_infos["dir"], var_infos["var_name"]) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
232 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
233 |
params = self.CTNParams[1].getElementInfos(self.CTNParams[0]) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
234 |
for param in params["children"]: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
235 |
if param["value"] 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
|
236 |
param_infos = { |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
237 |
"location": location_str, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
238 |
"param_name": param["name"], |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
239 |
} |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
240 |
if param["type"] == "boolean": |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
241 |
param_infos["param_value"] = {True: "true", False: "false"}[param["value"]] |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
242 |
else: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
243 |
param_infos["param_value"] = str(param["value"]) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
244 |
str_completion["init_axis_params"].append( |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2042
diff
changeset
|
245 |
" __CIA402Node_%(location)s.axis->%(param_name)s = %(param_value)s;" % param_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
|
246 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
247 |
for element in ["extern_located_variables_declaration", |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
248 |
"entry_variables", |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
249 |
"init_axis_params", |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
250 |
"init_entry_variables"]: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
251 |
str_completion[element] = "\n".join(str_completion[element]) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
252 |
|
2045 | 253 |
Gen_CIA402Nodefile_path = os.path.join(buildpath, "cia402node_%s.c"%location_str) |
254 |
cia402nodefile = open(Gen_CIA402Nodefile_path, 'w') |
|
255 |
cia402nodefile.write(plc_cia402node_code % str_completion) |
|
256 |
cia402nodefile.close() |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
257 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
258 |
return [(Gen_CIA402Nodefile_path, '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()))],"",True |
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
|
259 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
260 |
#-------------------------------------------------- |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
261 |
# Ethercat MASTER |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
262 |
#-------------------------------------------------- |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
263 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
264 |
EtherCATConfigClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATConfig.xsd")) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
265 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
266 |
def ExtractHexDecValue(value): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
267 |
try: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
268 |
return int(value) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
269 |
except: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
270 |
pass |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
271 |
try: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
272 |
return int(value.replace("#", "0"), 16) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
273 |
except: |
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
|
274 |
raise ValueError, "Invalid value for HexDecValue \"%s\"" % value |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
275 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
276 |
def GenerateHexDecValue(value, base=10): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
277 |
if base == 10: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
278 |
return str(value) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
279 |
elif base == 16: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
280 |
return "#x%.8x" % value |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
281 |
else: |
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
|
282 |
raise ValueError, "Not supported base" |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
283 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
284 |
cls = EtherCATConfigClasses.get("Config_Slave", None) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
285 |
if cls: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
286 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
287 |
def getType(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
288 |
slave_info = self.getInfo() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
289 |
return {"device_type": slave_info.getName(), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
290 |
"vendor": GenerateHexDecValue(slave_info.getVendorId()), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
291 |
"product_code": GenerateHexDecValue(slave_info.getProductCode(), 16), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
292 |
"revision_number": GenerateHexDecValue(slave_info.getRevisionNo(), 16)} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
293 |
setattr(cls, "getType", getType) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
294 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
295 |
def setType(self, type_infos): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
296 |
slave_info = self.getInfo() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
297 |
slave_info.setName(type_infos["device_type"]) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
298 |
slave_info.setVendorId(ExtractHexDecValue(type_infos["vendor"])) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
299 |
slave_info.setProductCode(ExtractHexDecValue(type_infos["product_code"])) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
300 |
slave_info.setRevisionNo(ExtractHexDecValue(type_infos["revision_number"])) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
301 |
setattr(cls, "setType", setType) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
302 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
303 |
class _EthercatCTN: |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
304 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
305 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
306 |
<xsd:element name="EtherlabNode"> |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
307 |
<xsd:complexType> |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
308 |
<xsd:attribute name="MasterNumber" type="xsd:integer" use="optional" default="0"/> |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
309 |
<xsd:attribute name="ConfigurePDOs" type="xsd:boolean" use="optional" default="true"/> |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
310 |
</xsd:complexType> |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
311 |
</xsd:element> |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
312 |
</xsd:schema> |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
313 |
""" |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
314 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
315 |
CTNChildrenTypes = [("EthercatSlave", _EthercatSlaveCTN, "Ethercat Slave")] |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
316 |
if HAS_MCL: |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
317 |
CTNChildrenTypes.append(("EthercatCIA402Slave", _EthercatCIA402SlaveCTN, "Ethercat CIA402 Slave")) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
318 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
319 |
def __init__(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
320 |
filepath = self.ConfigFileName() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
321 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
322 |
self.Config = EtherCATConfigClasses["EtherCATConfig"]() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
323 |
if os.path.isfile(filepath): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
324 |
xmlfile = open(filepath, 'r') |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
325 |
tree = minidom.parse(xmlfile) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
326 |
xmlfile.close() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
327 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
328 |
for child in tree.childNodes: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
329 |
if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "EtherCATConfig": |
2051 | 330 |
self.Config.loadXMLTree(child) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
331 |
self.CreateConfigBuffer(True) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
332 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
333 |
self.CreateConfigBuffer(False) |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
334 |
self.OnCTNSave() |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
335 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
336 |
def ExtractHexDecValue(self, value): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
337 |
return ExtractHexDecValue(value) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
338 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
339 |
def GetSizeOfType(self, type): |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
340 |
return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
341 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
342 |
def ConfigFileName(self): |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
343 |
return os.path.join(self.CTNPath(), "config.xml") |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
344 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
345 |
def GetSlaves(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
346 |
slaves = [] |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
347 |
for slave in self.Config.getConfig().getSlave(): |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
348 |
slaves.append(slave.getInfo().getPhysAddr()) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
349 |
slaves.sort() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
350 |
return slaves |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
351 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
352 |
def GetSlave(self, slave_pos): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
353 |
for slave in self.Config.getConfig().getSlave(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
354 |
slave_info = slave.getInfo() |
2041
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 slave_info.getPhysAddr() == slave_pos: |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
356 |
return slave |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
357 |
return None |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
358 |
|
2042
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
359 |
def _ScanNetwork(self): |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
360 |
app_frame = self.GetCTRoot().AppFrame |
2042
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
361 |
|
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
362 |
execute = True |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
363 |
if len(self.Children) > 0: |
2042
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
364 |
dialog = wx.MessageDialog(app_frame, |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
365 |
_("The current network configuration will be deleted.\nDo you want to continue?"), |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
366 |
_("Scan Network"), |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
367 |
wx.YES_NO|wx.ICON_QUESTION) |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
368 |
execute = dialog.ShowModal() == wx.ID_YES |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
369 |
dialog.Destroy() |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
370 |
|
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
371 |
if execute: |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
372 |
error, returnVal = self.RemoteExec(SCAN_COMMAND, returnVal = None) |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
373 |
if error != 0: |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
374 |
dialog = wx.MessageDialog(app_frame, returnVal, "Error", wx.OK|wx.ICON_ERROR) |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
375 |
dialog.ShowModal() |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
376 |
dialog.Destroy() |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
377 |
elif returnVal is not None: |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
378 |
for child in self.IECSortedChildren(): |
2042
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
379 |
self._doRemoveChild(child) |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
380 |
|
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
381 |
for slave in returnVal: |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
382 |
type_infos = { |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
383 |
"vendor": slave["vendor_id"], |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
384 |
"product_code": slave["product_code"], |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
385 |
"revision_number":slave["revision_number"], |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
386 |
} |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
387 |
device = self.GetModuleInfos(type_infos) |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
388 |
if device is not None: |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
389 |
if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers(): |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
390 |
CTNType = "EthercatCIA402Slave" |
2042
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
391 |
else: |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
392 |
CTNType = "EthercatSlave" |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
393 |
self.CTNAddChild("slave%s" % slave["idx"], CTNType, slave["idx"]) |
2042
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
394 |
self.SetSlaveAlias(slave["idx"], slave["alias"]) |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
395 |
type_infos["device_type"] = device.getType().getcontent() |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
396 |
self.SetSlaveType(slave["idx"], type_infos) |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
397 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
398 |
def CTNAddChild(self, CTNName, CTNType, IEC_Channel=0): |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
399 |
""" |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
400 |
Create the confnodes that may be added as child to this node self |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
401 |
@param CTNType: string desining the confnode class name (get name from CTNChildrenTypes) |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
402 |
@param CTNName: string for the name of the confnode instance |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
403 |
""" |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
404 |
newConfNodeOpj = ConfigTreeNode.CTNAddChild(self, CTNName, CTNType, IEC_Channel) |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
405 |
|
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
406 |
slave = self.GetSlave(newConfNodeOpj.BaseParams.getIEC_Channel()) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
407 |
if slave is None: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
408 |
slave = EtherCATConfigClasses["Config_Slave"]() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
409 |
slave_infos = slave.getInfo() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
410 |
slave_infos.setName("undefined") |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
411 |
slave_infos.setPhysAddr(newConfNodeOpj.BaseParams.getIEC_Channel()) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
412 |
slave_infos.setAutoIncAddr(0) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
413 |
self.Config.getConfig().appendSlave(slave) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
414 |
self.BufferConfig() |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
415 |
self.OnCTNSave() |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
416 |
|
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
417 |
return newConfNodeOpj |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
418 |
|
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
419 |
def _doRemoveChild(self, CTNInstance): |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
420 |
slave_pos = CTNInstance.GetSlavePos() |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
421 |
config = self.Config.getConfig() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
422 |
for idx, slave in enumerate(config.getSlave()): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
423 |
slave_infos = slave.getInfo() |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
424 |
if slave_infos.getPhysAddr() == slave_pos: |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
425 |
config.removeSlave(idx) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
426 |
self.BufferConfig() |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
427 |
self.OnCTNSave() |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
428 |
ConfigTreeNode._doRemoveChild(self, CTNInstance) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
429 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
430 |
def SetSlavePosition(self, slave_pos, new_pos): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
431 |
slave = self.GetSlave(slave_pos) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
432 |
if slave is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
433 |
slave_info = slave.getInfo() |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
434 |
slave_info.setPhysAddr(new_pos) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
435 |
self.BufferConfig() |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
436 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
437 |
def GetSlaveAlias(self, slave_pos): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
438 |
slave = self.GetSlave(slave_pos) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
439 |
if slave 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
|
440 |
slave_info = slave.getInfo() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
441 |
return slave_info.getAutoIncAddr() |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
442 |
return None |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
443 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
444 |
def SetSlaveAlias(self, slave_pos, alias): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
445 |
slave = self.GetSlave(slave_pos) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
446 |
if slave 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
|
447 |
slave_info = slave.getInfo() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
448 |
slave_info.setAutoIncAddr(alias) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
449 |
self.BufferConfig() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
450 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
451 |
def GetSlaveType(self, slave_pos): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
452 |
slave = self.GetSlave(slave_pos) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
453 |
if slave is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
454 |
return slave.getType() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
455 |
return None |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
456 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
457 |
def SetSlaveType(self, slave_pos, type_infos): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
458 |
slave = self.GetSlave(slave_pos) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
459 |
if slave is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
460 |
slave.setType(type_infos) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
461 |
self.BufferConfig() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
462 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
463 |
def GetSlaveInfos(self, slave_pos): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
464 |
slave = self.GetSlave(slave_pos) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
465 |
if slave is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
466 |
type_infos = slave.getType() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
467 |
device = self.GetModuleInfos(type_infos) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
468 |
if device is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
469 |
infos = type_infos.copy() |
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
|
470 |
entries = device.GetEntriesList() |
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
|
471 |
entries_list = entries.items() |
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
|
472 |
entries_list.sort() |
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
473 |
entries = [] |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
474 |
current_index = None |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
475 |
current_entry = None |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
476 |
for (index, subindex), entry in entries_list: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
477 |
entry["children"] = [] |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
478 |
if index != current_index: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
479 |
current_index = index |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
480 |
current_entry = entry |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
481 |
entries.append(entry) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
482 |
elif current_entry is not None: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
483 |
current_entry["children"].append(entry) |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
484 |
else: |
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
485 |
entries.append(entry) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
486 |
infos.update({"physics": device.getPhysics(), |
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
|
487 |
"sync_managers": device.GetSyncManagers(), |
2038
6f78c4ac22f9
Replacing wx.Grid control by a wx.TreeListCtrl for displaying slaves entries
laurent
parents:
2037
diff
changeset
|
488 |
"entries": entries}) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
489 |
return infos |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
490 |
return None |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
491 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
492 |
def GetModuleInfos(self, type_infos): |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
493 |
return self.CTNParent.GetModuleInfos(type_infos) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
494 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
495 |
def GetSlaveTypesLibrary(self, profile_filter=None): |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
496 |
return self.CTNParent.GetModulesLibrary(profile_filter) |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
497 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
498 |
def GetDeviceLocationTree(self, slave_pos, current_location, device_name): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
499 |
slave = self.GetSlave(slave_pos) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
500 |
if slave 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
|
501 |
type_infos = slave.getType() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
502 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
503 |
vars = [] |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
504 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
505 |
device = self.GetModuleInfos(type_infos) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
506 |
if device 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
|
507 |
sync_managers = [] |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
508 |
for sync_manager in device.getSm(): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
509 |
sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte()) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
510 |
sync_manager_direction = sync_manager_control_byte & 0x0c |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
511 |
if sync_manager_direction: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
512 |
sync_managers.append(LOCATION_VAR_OUTPUT) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
513 |
else: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
514 |
sync_managers.append(LOCATION_VAR_INPUT) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
515 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
516 |
entries = device.GetEntriesList().items() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
517 |
entries.sort() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
518 |
for (index, subindex), entry in entries: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
519 |
var_size = self.GetSizeOfType(entry["Type"]) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
520 |
if var_size 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
|
521 |
var_class = VARCLASSCONVERSION.get(entry["PDOMapping"], None) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
522 |
if var_class 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
|
523 |
if var_class == LOCATION_VAR_INPUT: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
524 |
var_dir = "%I" |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
525 |
else: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
526 |
var_dir = "%Q" |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
527 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
528 |
vars.append({"name": "0x%4.4x-0x%2.2x: %s" % (index, subindex, entry["Name"]), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
529 |
"type": var_class, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
530 |
"size": var_size, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
531 |
"IEC_type": entry["Type"], |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
532 |
"var_name": "%s_%4.4x_%2.2x" % ("_".join(device_name.split()), index, subindex), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
533 |
"location": "%s%s%s"%(var_dir, var_size, ".".join(map(str, current_location + |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
534 |
(index, subindex)))), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
535 |
"description": "", |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
536 |
"children": []}) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
537 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
538 |
return vars |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
539 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
540 |
def CTNTestModified(self): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
541 |
return self.ChangesToSave or not self.ConfigIsSaved() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
542 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
543 |
def OnCTNSave(self): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
544 |
filepath = self.ConfigFileName() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
545 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
546 |
text = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
547 |
extras = {"xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance", |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
548 |
"xsi:noNamespaceSchemaLocation" : "EtherCATInfo.xsd"} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
549 |
text += self.Config.generateXMLText("EtherCATConfig", 0, extras) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
550 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
551 |
xmlfile = open(filepath,"w") |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
552 |
xmlfile.write(text.encode("utf-8")) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
553 |
xmlfile.close() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
554 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
555 |
self.ConfigBuffer.CurrentSaved() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
556 |
return True |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
557 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
558 |
def _Generate_C(self, buildpath, locations): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
559 |
current_location = self.GetCurrentLocation() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
560 |
# define a unique name for the generated C file |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
561 |
location_str = "_".join(map(lambda x:str(x), current_location)) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
562 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
563 |
Gen_Ethercatfile_path = os.path.join(buildpath, "ethercat_%s.c"%location_str) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
564 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
565 |
self.FileGenerator = _EthercatCFileGenerator(self) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
566 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
567 |
LocationCFilesAndCFLAGS, LDFLAGS, extra_files = ConfigTreeNode._Generate_C(self, buildpath, locations) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
568 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
569 |
self.FileGenerator.GenerateCFile(Gen_Ethercatfile_path, location_str, self.EtherlabNode) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
570 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
571 |
LocationCFilesAndCFLAGS.append( |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
572 |
(current_location, |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
573 |
[(Gen_Ethercatfile_path, '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()))], |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
574 |
True)) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
575 |
LDFLAGS.append("-lethercat -lrtdm") |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
576 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
577 |
return LocationCFilesAndCFLAGS, LDFLAGS, extra_files |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
578 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
579 |
ConfNodeMethods = [ |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
580 |
{"bitmap" : os.path.join(CONFNODEFOLDER, "images", "ScanNetwork"), |
2042
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
581 |
"name" : _("Scan Network"), |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
582 |
"tooltip" : _("Scan Network"), |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
583 |
"method" : "_ScanNetwork"}, |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
584 |
] |
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
585 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
586 |
def CTNGenerate_C(self, buildpath, locations): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
587 |
""" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
588 |
Generate C code |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
589 |
@param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
590 |
@param locations: List of complete variables locations \ |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
591 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
592 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
593 |
"DIR" : direction "Q","I" or "M" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
594 |
"SIZE" : size "X", "B", "W", "D", "L" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
595 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
596 |
}, ...] |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
597 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
598 |
""" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
599 |
current_location = self.GetCurrentLocation() |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
600 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
601 |
slaves = self.GetSlaves() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
602 |
for slave_pos in slaves: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
603 |
slave = self.GetSlave(slave_pos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
604 |
if slave is not None: |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
605 |
self.FileGenerator.DeclareSlave(slave_pos, slave.getInfo().getAutoIncAddr(), slave.getType()) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
606 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
607 |
for location in locations: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
608 |
loc = location["LOC"][len(current_location):] |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
609 |
slave_pos = loc[0] |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
610 |
if slave_pos in slaves and len(loc) == 3: |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
611 |
self.FileGenerator.DeclareVariable( |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
612 |
slave_pos, loc[1], loc[2], location["IEC_TYPE"], location["DIR"], location["NAME"]) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
613 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
614 |
return [],"",False |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
615 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
616 |
#------------------------------------------------------------------------------- |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
617 |
# Current Buffering Management Functions |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
618 |
#------------------------------------------------------------------------------- |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
619 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
620 |
""" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
621 |
Return a copy of the config |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
622 |
""" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
623 |
def Copy(self, model): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
624 |
return cPickle.loads(cPickle.dumps(model)) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
625 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
626 |
def CreateConfigBuffer(self, saved): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
627 |
self.ConfigBuffer = UndoBuffer(cPickle.dumps(self.Config), saved) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
628 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
629 |
def BufferConfig(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
630 |
self.ConfigBuffer.Buffering(cPickle.dumps(self.Config)) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
631 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
632 |
def ConfigIsSaved(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
633 |
if self.ConfigBuffer is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
634 |
return self.ConfigBuffer.IsCurrentSaved() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
635 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
636 |
return True |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
637 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
638 |
def LoadPrevious(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
639 |
self.Config = cPickle.loads(self.ConfigBuffer.Previous()) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
640 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
641 |
def LoadNext(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
642 |
self.Config = cPickle.loads(self.ConfigBuffer.Next()) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
643 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
644 |
def GetBufferState(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
645 |
first = self.ConfigBuffer.IsFirst() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
646 |
last = self.ConfigBuffer.IsLast() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
647 |
return not first, not last |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
648 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
649 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
650 |
SLAVE_PDOS_CONFIGURATION_DECLARATION = """ |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
651 |
/* Slave %(slave)d, "%(device_type)s" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
652 |
* Vendor ID: 0x%(vendor).8x |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
653 |
* Product code: 0x%(product_code).8x |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
654 |
* Revision number: 0x%(revision_number).8x |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
655 |
*/ |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
656 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
657 |
ec_pdo_entry_info_t slave_%(slave)d_pdo_entries[] = { |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
658 |
%(pdos_entries_infos)s |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
659 |
}; |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
660 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
661 |
ec_pdo_info_t slave_%(slave)d_pdos[] = { |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
662 |
%(pdos_infos)s |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
663 |
}; |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
664 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
665 |
ec_sync_info_t slave_%(slave)d_syncs[] = { |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
666 |
%(pdos_sync_infos)s |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
667 |
{0xff} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
668 |
}; |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
669 |
""" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
670 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
671 |
SLAVE_CONFIGURATION_TEMPLATE = """ |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
672 |
if (!(slave%(slave)d = ecrt_master_slave_config(master, %(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x))) { |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
673 |
fprintf(stderr, "Failed to get slave %(device_type)s configuration at alias %(alias)d and position %(position)d.\\n"); |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
674 |
return -1; |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
675 |
} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
676 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
677 |
if (ecrt_slave_config_pdos(slave%(slave)d, EC_END, slave_%(slave)d_syncs)) { |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
678 |
fprintf(stderr, "Failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d.\\n"); |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
679 |
return -1; |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
680 |
} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
681 |
""" |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
682 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
683 |
SLAVE_INITIALIZATION_TEMPLATE = """ |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
684 |
{ |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
685 |
uint8_t value[] = {%(data)s}; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
686 |
if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
687 |
fprintf(stderr, "Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code); |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
688 |
return -1; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
689 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
690 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
691 |
""" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
692 |
|
2039
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
693 |
SLAVE_OUTPUT_PDO_DEFAULT_VALUE = """ |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
694 |
{ |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
695 |
uint8_t value[%(data_size)d]; |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
696 |
if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) { |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
697 |
fprintf(stderr, "Failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code); |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
698 |
return -1; |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
699 |
} |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
700 |
for (i = 0; i < result_size; i++) { |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
701 |
%(real_var)s = (%(real_var)s << 8) + value[i]; |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
702 |
} |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
703 |
} |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
704 |
""" |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
705 |
|
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
|
706 |
def ConfigureVariable(entry_infos, str_completion): |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
707 |
entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
708 |
if entry_infos["data_type"] is 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
|
709 |
raise ValueError, _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"] |
2039
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
710 |
|
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
711 |
if entry_infos.has_key("real_var"): |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
712 |
str_completion["located_variables_declaration"].append( |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
713 |
"IEC_%(var_type)s %(real_var)s;" % entry_infos) |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
714 |
else: |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
715 |
entry_infos["real_var"] = "beremiz" + entry_infos["var_name"] |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
716 |
str_completion["located_variables_declaration"].extend( |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
717 |
["IEC_%(var_type)s %(real_var)s;" % entry_infos, |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
718 |
"IEC_%(var_type)s *%(var_name)s = &%(real_var)s;" % entry_infos]) |
2034 | 719 |
|
720 |
str_completion["used_pdo_entry_offset_variables_declaration"].append( |
|
721 |
"unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_infos) |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
722 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
723 |
if entry_infos["data_type"] == "BIT": |
2034 | 724 |
str_completion["used_pdo_entry_offset_variables_declaration"].append( |
725 |
"unsigned int slave%(slave)d_%(index).4x_%(subindex).2x_bit;" % entry_infos) |
|
726 |
||
727 |
str_completion["used_pdo_entry_configuration"].append( |
|
728 |
(" {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, " + |
|
729 |
"0x%(index).4x, %(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x, " + |
|
730 |
"&slave%(slave)d_%(index).4x_%(subindex).2x_bit},") % entry_infos) |
|
731 |
||
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
732 |
if entry_infos["dir"] == "I": |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
733 |
str_completion["retrieve_variables"].append( |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
734 |
(" %(real_var)s = EC_READ_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
735 |
"slave%(slave)d_%(index).4x_%(subindex).2x_bit);") % entry_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
736 |
elif entry_infos["dir"] == "Q": |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
737 |
str_completion["publish_variables"].append( |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
738 |
(" EC_WRITE_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
739 |
"slave%(slave)d_%(index).4x_%(subindex).2x_bit, %(real_var)s);") % entry_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
740 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
741 |
else: |
2034 | 742 |
str_completion["used_pdo_entry_configuration"].append( |
743 |
(" {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, 0x%(index).4x, " + |
|
744 |
"%(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x},") % entry_infos) |
|
745 |
||
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
746 |
if entry_infos["dir"] == "I": |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
747 |
str_completion["retrieve_variables"].append( |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
748 |
(" %(real_var)s = EC_READ_%(data_type)s(domain1_pd + " + |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
749 |
"slave%(slave)d_%(index).4x_%(subindex).2x);") % entry_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
750 |
elif entry_infos["dir"] == "Q": |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
751 |
str_completion["publish_variables"].append( |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
752 |
(" EC_WRITE_%(data_type)s(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
753 |
"%(real_var)s);") % entry_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
754 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
755 |
class _EthercatCFileGenerator: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
756 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
757 |
def __init__(self, controler): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
758 |
self.Controler = controler |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
759 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
760 |
self.Slaves = [] |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
761 |
self.UsedVariables = {} |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
762 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
763 |
def __del__(self): |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
764 |
self.Controler = None |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
765 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
766 |
def DeclareSlave(self, slave_index, slave_alias, slave): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
767 |
self.Slaves.append((slave_index, slave_alias, slave)) |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
768 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
769 |
def DeclareVariable(self, slave_index, index, subindex, iec_type, dir, name): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
770 |
slave_variables = self.UsedVariables.setdefault(slave_index, {}) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
771 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
772 |
entry_infos = slave_variables.get((index, subindex), None) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
773 |
if entry_infos is 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
|
774 |
slave_variables[(index, 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
|
775 |
"infos": (iec_type, dir, name), |
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
|
776 |
"mapped": False} |
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
|
777 |
elif entry_infos["infos"] != (iec_type, dir, name): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
778 |
raise ValueError, _("Definition conflict for location \"%s\"") % name |
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
|
779 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
780 |
def GenerateCFile(self, filepath, location_str, etherlab_node_infos): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
781 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
782 |
plc_etherlab_filepath = os.path.join(os.path.split(__file__)[0], "plc_etherlab.c") |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
783 |
plc_etherlab_file = open(plc_etherlab_filepath, 'r') |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
784 |
plc_etherlab_code = plc_etherlab_file.read() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
785 |
plc_etherlab_file.close() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
786 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
787 |
str_completion = { |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
788 |
"location": location_str, |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
789 |
"configure_pdos": int(etherlab_node_infos.getConfigurePDOs()), |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
790 |
"master_number": etherlab_node_infos.getMasterNumber(), |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
791 |
"located_variables_declaration": [], |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
792 |
"used_pdo_entry_offset_variables_declaration": [], |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
793 |
"used_pdo_entry_configuration": [], |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
794 |
"pdos_configuration_declaration": "", |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
795 |
"slaves_declaration": "", |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
796 |
"slaves_configuration": "", |
2039
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
797 |
"slaves_output_pdos_default_values_extraction": "", |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
798 |
"slaves_initialization": "", |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
799 |
"retrieve_variables": [], |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
800 |
"publish_variables": [], |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
801 |
} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
802 |
|
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
|
803 |
for slave_entries in self.UsedVariables.itervalues(): |
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
|
804 |
for entry_infos in slave_entries.itervalues(): |
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
|
805 |
entry_infos["mapped"] = False |
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
|
806 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
807 |
self.Slaves.sort() |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
808 |
alias = {} |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
809 |
for (slave_idx, slave_alias, type_infos) in self.Slaves: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
810 |
if alias.get(slave_alias) 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
|
811 |
alias[slave_alias] += 1 |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
812 |
else: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
813 |
alias[slave_alias] = 0 |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
814 |
slave_pos = (slave_alias, alias[slave_alias]) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
815 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
816 |
device = self.Controler.GetModuleInfos(type_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
817 |
if device is not None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
818 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
819 |
slave_variables = self.UsedVariables.get(slave_idx, {}) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
820 |
device_entries = device.GetEntriesList() |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
821 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
822 |
if len(device.getTxPdo() + device.getRxPdo()) > 0 or len(slave_variables) > 0: |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
823 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
824 |
for element in ["vendor", "product_code", "revision_number"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
825 |
type_infos[element] = ExtractHexDecValue(type_infos[element]) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
826 |
type_infos.update(dict(zip(["slave", "alias", "position"], (slave_idx,) + slave_pos))) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
827 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
828 |
str_completion["slaves_declaration"] += "static ec_slave_config_t *slave%(slave)d = NULL;\n" % type_infos |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
829 |
str_completion["slaves_configuration"] += SLAVE_CONFIGURATION_TEMPLATE % type_infos |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
830 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
831 |
for initCmd in device.getInitCmd(): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
832 |
index = ExtractHexDecValue(initCmd.getIndex()) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
833 |
subindex = ExtractHexDecValue(initCmd.getSubIndex()) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
834 |
entry = device_entries.get((index, subindex), None) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
835 |
if entry is not None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
836 |
data_size = entry["BitSize"] / 8 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
837 |
data = ("%%.%dx" % (data_size * 2)) % initCmd.getData().getcontent() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
838 |
data_str = ",".join(["0x%s" % data[i:i+2] for i in xrange(0, data_size * 2, 2)]) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
839 |
init_cmd_infos = { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
840 |
"index": index, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
841 |
"subindex": subindex, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
842 |
"data": data_str, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
843 |
"data_size": data_size |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
844 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
845 |
init_cmd_infos.update(type_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
846 |
str_completion["slaves_initialization"] += SLAVE_INITIALIZATION_TEMPLATE % init_cmd_infos |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
847 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
848 |
pdos_infos = { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
849 |
"pdos_entries_infos": [], |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
850 |
"pdos_infos": [], |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
851 |
"pdos_sync_infos": [], |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
852 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
853 |
pdos_infos.update(type_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
854 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
855 |
sync_managers = [] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
856 |
for sync_manager_idx, sync_manager in enumerate(device.getSm()): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
857 |
sync_manager_infos = { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
858 |
"index": sync_manager_idx, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
859 |
"name": sync_manager.getcontent(), |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
860 |
"slave": slave_idx, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
861 |
"pdos": [], |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
862 |
"pdos_number": 0, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
863 |
} |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
864 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
865 |
sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte()) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
866 |
sync_manager_direction = sync_manager_control_byte & 0x0c |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
867 |
sync_manager_watchdog = sync_manager_control_byte & 0x40 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
868 |
if sync_manager_direction: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
869 |
sync_manager_infos["sync_manager_type"] = "EC_DIR_OUTPUT" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
870 |
else: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
871 |
sync_manager_infos["sync_manager_type"] = "EC_DIR_INPUT" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
872 |
if sync_manager_watchdog: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
873 |
sync_manager_infos["watchdog"] = "EC_WD_ENABLE" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
874 |
else: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
875 |
sync_manager_infos["watchdog"] = "EC_WD_DISABLE" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
876 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
877 |
sync_managers.append(sync_manager_infos) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
878 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
879 |
pdos_index = [] |
2034 | 880 |
excluded_pdos = [] |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
881 |
for only_mandatory in [True, False]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
882 |
for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] + |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
883 |
[(pdo, "Outputs") for pdo in device.getRxPdo()]): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
884 |
entries = pdo.getEntry() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
885 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
886 |
pdo_needed = pdo.getMandatory() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
887 |
if pdo_needed is None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
888 |
pdo_needed = False |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
889 |
if only_mandatory != pdo_needed: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
890 |
continue |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
891 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
892 |
pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent()) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
893 |
pdos_index.append(pdo_index) |
2034 | 894 |
if pdo_index in excluded_pdos: |
895 |
continue |
|
896 |
||
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
897 |
entries_infos = [] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
898 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
899 |
for entry in entries: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
900 |
index = ExtractHexDecValue(entry.getIndex().getcontent()) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
901 |
subindex = ExtractHexDecValue(entry.getSubIndex()) |
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
|
902 |
entry_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
|
903 |
"index": 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
|
904 |
"subindex": subindex, |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
905 |
"name": ExtractName(entry.getName()), |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
906 |
"bitlen": entry.getBitLen(), |
2023
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
907 |
} |
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
|
908 |
entry_infos.update(type_infos) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
909 |
entries_infos.append(" {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos) |
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
|
910 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
911 |
entry_declaration = slave_variables.get((index, subindex), None) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
912 |
if entry_declaration is not None and not entry_declaration["mapped"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
913 |
pdo_needed = True |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
914 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
915 |
entry_infos.update(dict(zip(["var_type", "dir", "var_name"], entry_declaration["infos"]))) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
916 |
entry_declaration["mapped"] = True |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
917 |
|
2045 | 918 |
entry_type = entry.getDataType().getcontent() |
919 |
if entry_infos["var_type"] != entry_type: |
|
920 |
message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"] |
|
921 |
if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != |
|
922 |
self.Controler.GetSizeOfType(entry_type)): |
|
923 |
raise ValueError, message |
|
924 |
else: |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
925 |
self.Controler.GetCTRoot().logger.write_warning(message + "\n") |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
926 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
927 |
if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
928 |
entry_infos["dir"] == "Q" and pdo_type != "Outputs"): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
929 |
raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
930 |
|
2034 | 931 |
ConfigureVariable(entry_infos, str_completion) |
2039
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
932 |
|
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
933 |
elif pdo_type == "Outputs" and entry.getDataType() is not None: |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
934 |
entry_infos["dir"] = "Q" |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
935 |
entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8) |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
936 |
entry_infos["var_type"] = entry.getDataType().getcontent() |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
937 |
entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
938 |
|
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
939 |
ConfigureVariable(entry_infos, str_completion) |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
940 |
|
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
941 |
str_completion["slaves_output_pdos_default_values_extraction"] += \ |
3a218f6bd805
Adding support for uploading default value for unused entries in output pdos from slaves before starting master
laurent
parents:
2038
diff
changeset
|
942 |
SLAVE_OUTPUT_PDO_DEFAULT_VALUE % entry_infos |
2034 | 943 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
944 |
if pdo_needed: |
2034 | 945 |
for excluded in pdo.getExclude(): |
946 |
excluded_index = ExtractHexDecValue(excluded.getcontent()) |
|
947 |
if excluded_index not in excluded_pdos: |
|
948 |
excluded_pdos.append(excluded_index) |
|
949 |
||
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
950 |
sm = pdo.getSm() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
951 |
if sm is None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
952 |
for sm_idx, sync_manager in enumerate(sync_managers): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
953 |
if sync_manager["name"] == pdo_type: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
954 |
sm = sm_idx |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
955 |
if sm is None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
956 |
raise ValueError, _("No sync manager available for %s pdo!") % pdo_type |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
957 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
958 |
sync_managers[sm]["pdos_number"] += 1 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
959 |
sync_managers[sm]["pdos"].append( |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
960 |
{"slave": slave_idx, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
961 |
"index": pdo_index, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
962 |
"name": ExtractName(pdo.getName()), |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
963 |
"type": pdo_type, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
964 |
"entries": entries_infos, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
965 |
"entries_number": len(entries_infos), |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
966 |
"fixed": pdo.getFixed() == True}) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
967 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
968 |
dynamic_pdos = {} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
969 |
dynamic_pdos_number = 0 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
970 |
for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
971 |
("Outputs", 0x1a00, 0x1C00)]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
972 |
for sync_manager in sync_managers: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
973 |
if sync_manager["name"] == category: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
974 |
category_infos = dynamic_pdos.setdefault(category, {}) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
975 |
category_infos["sync_manager"] = sync_manager |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
976 |
category_infos["pdos"] = [pdo for pdo in category_infos["sync_manager"]["pdos"] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
977 |
if not pdo["fixed"] and pdo["type"] == category] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
978 |
category_infos["current_index"] = min_index |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
979 |
category_infos["max_index"] = max_index |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
980 |
break |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
981 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
982 |
for (index, subindex), entry_declaration in slave_variables.iteritems(): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
983 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
984 |
if not entry_declaration["mapped"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
985 |
entry = device_entries.get((index, subindex), None) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
986 |
if entry is None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
987 |
raise ValueError, _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") % \ |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
988 |
(index, subindex, type_infos["device_type"]) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
989 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
990 |
entry_infos = { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
991 |
"index": index, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
992 |
"subindex": subindex, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
993 |
"name": entry["Name"], |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
994 |
"bitlen": entry["BitSize"], |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
995 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
996 |
entry_infos.update(type_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
997 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
998 |
entry_infos.update(dict(zip(["var_type", "dir", "var_name", "real_var"], entry_declaration["infos"]))) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
999 |
entry_declaration["mapped"] = True |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1000 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1001 |
if entry_infos["var_type"] != entry["Type"]: |
2045 | 1002 |
message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"] |
1003 |
if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != |
|
1004 |
self.Controler.GetSizeOfType(entry["Type"])): |
|
1005 |
raise ValueError, message |
|
1006 |
else: |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
1007 |
self.Controler.GetCTRoot().logger.write_warning(message + "\n") |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1008 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1009 |
if entry_infos["dir"] == "I" and entry["PDOMapping"] in ["T", "RT"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1010 |
pdo_type = "Inputs" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1011 |
elif entry_infos["dir"] == "Q" and entry["PDOMapping"] in ["R", "RT"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1012 |
pdo_type = "Outputs" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1013 |
else: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1014 |
raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1015 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1016 |
if not dynamic_pdos.has_key(pdo_type): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1017 |
raise ValueError, _("No Sync manager defined for %s!") % pdo_type |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1018 |
|
2034 | 1019 |
ConfigureVariable(entry_infos, str_completion) |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1020 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1021 |
if len(dynamic_pdos[pdo_type]["pdos"]) > 0: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1022 |
pdo = dynamic_pdos[pdo_type]["pdos"][0] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1023 |
else: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1024 |
while dynamic_pdos[pdo_type]["current_index"] in pdos_index: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1025 |
dynamic_pdos[pdo_type]["current_index"] += 1 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1026 |
if dynamic_pdos[pdo_type]["current_index"] >= dynamic_pdos[pdo_type]["max_index"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1027 |
raise ValueError, _("No more free PDO index available for %s!") % pdo_type |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1028 |
pdos_index.append(dynamic_pdos[pdo_type]["current_index"]) |
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
|
1029 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1030 |
dynamic_pdos_number += 1 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1031 |
pdo = {"slave": slave_idx, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1032 |
"index": dynamic_pdos[pdo_type]["current_index"], |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1033 |
"name": "Dynamic PDO %d" % dynamic_pdos_number, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1034 |
"type": pdo_type, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1035 |
"entries": [], |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1036 |
"entries_number": 0, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1037 |
"fixed": False} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1038 |
dynamic_pdos[pdo_type]["sync_manager"]["pdos_number"] += 1 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1039 |
dynamic_pdos[pdo_type]["sync_manager"]["pdos"].append(pdo) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1040 |
dynamic_pdos[pdo_type]["pdos"].append(pdo) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1041 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1042 |
pdo["entries"].append(" {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1043 |
pdo["entries_number"] += 1 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1044 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1045 |
if pdo["entries_number"] == 255: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1046 |
dynamic_pdos[pdo_type]["pdos"].pop(0) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1047 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1048 |
pdo_offset = 0 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1049 |
entry_offset = 0 |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1050 |
for sync_manager_infos in sync_managers: |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1051 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1052 |
for pdo_infos in sync_manager_infos["pdos"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1053 |
pdo_infos["offset"] = entry_offset |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1054 |
pdo_entries = pdo_infos["entries"] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1055 |
pdos_infos["pdos_infos"].append( |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1056 |
(" {0x%(index).4x, %(entries_number)d, " + |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1057 |
"slave_%(slave)d_pdo_entries + %(offset)d}, /* %(name)s */") % pdo_infos) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1058 |
entry_offset += len(pdo_entries) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1059 |
pdos_infos["pdos_entries_infos"].extend(pdo_entries) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1060 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1061 |
sync_manager_infos["offset"] = pdo_offset |
2047
b0b7bd288b6e
Fixed wrong PDO in unused sync managers\nFix higen drive ethercat example
edouard_and_laurent
parents:
2045
diff
changeset
|
1062 |
pdo_offset_shift = sync_manager_infos["pdos_number"] |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1063 |
pdos_infos["pdos_sync_infos"].append( |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1064 |
(" {%(index)d, %(sync_manager_type)s, %(pdos_number)d, " + |
2047
b0b7bd288b6e
Fixed wrong PDO in unused sync managers\nFix higen drive ethercat example
edouard_and_laurent
parents:
2045
diff
changeset
|
1065 |
("slave_%(slave)d_pdos + %(offset)d" if pdo_offset_shift else "NULL") + |
b0b7bd288b6e
Fixed wrong PDO in unused sync managers\nFix higen drive ethercat example
edouard_and_laurent
parents:
2045
diff
changeset
|
1066 |
", %(watchdog)s},") % sync_manager_infos) |
b0b7bd288b6e
Fixed wrong PDO in unused sync managers\nFix higen drive ethercat example
edouard_and_laurent
parents:
2045
diff
changeset
|
1067 |
pdo_offset += pdo_offset_shift |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1068 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1069 |
for element in ["pdos_entries_infos", "pdos_infos", "pdos_sync_infos"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1070 |
pdos_infos[element] = "\n".join(pdos_infos[element]) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1071 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1072 |
str_completion["pdos_configuration_declaration"] += SLAVE_PDOS_CONFIGURATION_DECLARATION % pdos_infos |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1073 |
|
2023
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
1074 |
for element in ["used_pdo_entry_offset_variables_declaration", |
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
1075 |
"used_pdo_entry_configuration", |
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
1076 |
"located_variables_declaration", |
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
1077 |
"retrieve_variables", |
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
1078 |
"publish_variables"]: |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1079 |
str_completion[element] = "\n".join(str_completion[element]) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1080 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1081 |
etherlabfile = open(filepath, 'w') |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1082 |
etherlabfile.write(plc_etherlab_code % str_completion) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1083 |
etherlabfile.close() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1084 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1085 |
#-------------------------------------------------- |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
1086 |
# Ethercat ConfNode |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1087 |
#-------------------------------------------------- |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1088 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1089 |
EtherCATInfoClasses = GenerateClassesFromXSD(os.path.join(os.path.dirname(__file__), "EtherCATInfo.xsd")) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1090 |
|
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
|
1091 |
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
|
1092 |
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
|
1093 |
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
|
1094 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1095 |
def GetProfileNumbers(self): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1096 |
profiles = [] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1097 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1098 |
for profile in self.getProfile(): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1099 |
profile_content = profile.getcontent() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1100 |
if profile_content is None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1101 |
continue |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1102 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1103 |
for content_element in profile_content["value"]: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1104 |
if content_element["name"] == "ProfileNo": |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1105 |
profiles.append(content_element["value"]) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1106 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1107 |
return profiles |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1108 |
setattr(cls, "GetProfileNumbers", GetProfileNumbers) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1109 |
|
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
|
1110 |
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
|
1111 |
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
|
1112 |
|
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
|
1113 |
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
|
1114 |
|
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
|
1115 |
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
|
1116 |
if profile_content is None: |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1117 |
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
|
1118 |
|
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
|
1119 |
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
|
1120 |
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
|
1121 |
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
|
1122 |
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
|
1123 |
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
|
1124 |
|
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
|
1125 |
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
|
1126 |
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
|
1127 |
|
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
|
1128 |
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
|
1129 |
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
|
1130 |
|
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
|
1131 |
for dictionary in self.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
|
1132 |
|
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
|
1133 |
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
|
1134 |
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
|
1135 |
|
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
|
1136 |
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
|
1137 |
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
|
1138 |
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
|
1139 |
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
|
1140 |
|
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
|
1141 |
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
|
1142 |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1143 |
def getInitCmd(self): |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1144 |
mailbox = self.getMailbox() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1145 |
if mailbox is None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1146 |
return [] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1147 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1148 |
coe = mailbox.getCoE() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1149 |
if coe is None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1150 |
return [] |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1151 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1152 |
return coe.getInitCmd() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1153 |
setattr(cls, "getInitCmd", getInitCmd) |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1154 |
|
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
|
1155 |
def GetEntriesList(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
|
1156 |
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
|
1157 |
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
|
1158 |
|
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
|
1159 |
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
|
1160 |
|
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
|
1161 |
for dictionary in self.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
|
1162 |
|
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
|
1163 |
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
|
1164 |
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
|
1165 |
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
|
1166 |
entry_type = object.getType() |
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
|
1167 |
entry_name = ExtractName(object.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
|
1168 |
|
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
|
1169 |
entry_type_infos = self.DataTypes.get(entry_type, 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
|
1170 |
if entry_type_infos 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
|
1171 |
content = entry_type_infos.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
|
1172 |
for subitem in 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
|
1173 |
entry_subidx = subitem.getSubIdx() |
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
|
1174 |
if entry_subidx 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
|
1175 |
entry_subidx = "0" |
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
|
1176 |
subidx = ExtractHexDecValue(entry_subidx) |
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
|
1177 |
subitem_access = "" |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1178 |
subitem_pdomapping = "" |
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
|
1179 |
subitem_flags = subitem.getFlags() |
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
|
1180 |
if subitem_flags 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
|
1181 |
access = subitem_flags.getAccess() |
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
|
1182 |
if access 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
|
1183 |
subitem_access = access.getcontent() |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1184 |
pdomapping = subitem_flags.getPdoMapping() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1185 |
if pdomapping is not None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1186 |
subitem_pdomapping = pdomapping.upper() |
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
|
1187 |
entries[(index, subidx)] = { |
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
|
1188 |
"Index": 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
|
1189 |
"SubIndex": entry_subidx, |
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
|
1190 |
"Name": "%s - %s" % |
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
|
1191 |
(entry_name.decode("utf-8"), |
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
|
1192 |
ExtractName(subitem.getDisplayName(), |
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
|
1193 |
subitem.getName()).decode("utf-8")), |
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
|
1194 |
"Type": subitem.getType(), |
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
|
1195 |
"BitSize": subitem.getBitSize(), |
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
|
1196 |
"Access": subitem_access, |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1197 |
"PDOMapping": subitem_pdomapping, |
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
|
1198 |
"PDO 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
|
1199 |
"PDO name": "", |
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
|
1200 |
"PDO type": ""} |
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
|
1201 |
else: |
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
|
1202 |
entry_access = "" |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1203 |
entry_pdomapping = "" |
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
|
1204 |
entry_flags = object.getFlags() |
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
|
1205 |
if entry_flags 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
|
1206 |
access = entry_flags.getAccess() |
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
|
1207 |
if access 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
|
1208 |
entry_access = access.getcontent() |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1209 |
pdomapping = entry_flags.getPdoMapping() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1210 |
if pdomapping is not None: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1211 |
entry_pdomapping = pdomapping.upper() |
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
|
1212 |
entries[(index, 0)] = { |
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
|
1213 |
"Index": 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
|
1214 |
"SubIndex": "0", |
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
|
1215 |
"Name": entry_name, |
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
|
1216 |
"Type": entry_type, |
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
|
1217 |
"BitSize": object.getBitSize(), |
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
|
1218 |
"Access": entry_access, |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1219 |
"PDOMapping": entry_pdomapping, |
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
|
1220 |
"PDO 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
|
1221 |
"PDO name": "", |
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
|
1222 |
"PDO type": ""} |
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
|
1223 |
|
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
|
1224 |
for TxPdo in self.getTxPdo(): |
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
|
1225 |
ExtractPdoInfos(TxPdo, "Transmit", 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
|
1226 |
for RxPdo in self.getRxPdo(): |
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
|
1227 |
ExtractPdoInfos(RxPdo, "Receive", 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
|
1228 |
|
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
|
1229 |
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
|
1230 |
setattr(cls, "GetEntriesList", GetEntriesList) |
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
|
1231 |
|
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
|
1232 |
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
|
1233 |
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
|
1234 |
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
|
1235 |
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
|
1236 |
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
|
1237 |
("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
|
1238 |
("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
|
1239 |
("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
|
1240 |
("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
|
1241 |
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
|
1242 |
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
|
1243 |
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
|
1244 |
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
|
1245 |
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
|
1246 |
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
|
1247 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1248 |
def GroupItemCompare(x, y): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1249 |
if x["type"] == y["type"]: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1250 |
if x["type"] == ETHERCAT_GROUP: |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1251 |
return cmp(x["order"], y["order"]) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1252 |
else: |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1253 |
return cmp(x["name"], y["name"]) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1254 |
elif x["type"] == ETHERCAT_GROUP: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1255 |
return -1 |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1256 |
return 1 |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1257 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1258 |
def SortGroupItems(group): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1259 |
for item in group["children"]: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1260 |
if item["type"] == ETHERCAT_GROUP: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1261 |
SortGroupItems(item) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1262 |
group["children"].sort(GroupItemCompare) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1263 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1264 |
def ExtractName(names, default=None): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1265 |
if len(names) == 1: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1266 |
return names[0].getcontent() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1267 |
else: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1268 |
for name in names: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1269 |
if name.getLcId() == 1033: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1270 |
return name.getcontent() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1271 |
return default |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1272 |
|
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
|
1273 |
def ExtractPdoInfos(pdo, pdo_type, entries): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1274 |
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
|
1275 |
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
|
1276 |
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
|
1277 |
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
|
1278 |
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
|
1279 |
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
|
1280 |
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
|
1281 |
|
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
|
1282 |
entry = entries.get((index, subindex), 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
|
1283 |
if entry 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
|
1284 |
entry["PDO index"] = pdo_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
|
1285 |
entry["PDO name"] = pdo_name |
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
|
1286 |
entry["PDO type"] = pdo_type |
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
|
1287 |
else: |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1288 |
entry_type = pdo_entry.getDataType() |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1289 |
if entry_type is not None: |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1290 |
if pdo_type == "Transmit": |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1291 |
access = "ro" |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1292 |
pdomapping = "T" |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1293 |
else: |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1294 |
access = "wo" |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1295 |
pdomapping = "R" |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1296 |
entries[(index, subindex)] = { |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1297 |
"Index": entry_index, |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1298 |
"SubIndex": entry_subindex, |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1299 |
"Name": ExtractName(pdo_entry.getName()), |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1300 |
"Type": entry_type.getcontent(), |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1301 |
"Access": access, |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
2031
diff
changeset
|
1302 |
"PDOMapping": pdomapping, |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1303 |
"PDO index": pdo_index, |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1304 |
"PDO name": pdo_name, |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1305 |
"PDO type": pdo_type} |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1306 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1307 |
class RootClass: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1308 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
1309 |
CTNChildrenTypes = [("EthercatNode",_EthercatCTN,"Ethercat Master")] |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1310 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1311 |
def __init__(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1312 |
self.LoadModulesLibrary() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1313 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1314 |
def GetModulesLibraryPath(self): |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
1315 |
library_path = os.path.join(self.CTNPath(), "modules") |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1316 |
if not os.path.exists(library_path): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1317 |
os.mkdir(library_path) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1318 |
return library_path |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1319 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1320 |
def _ImportModuleLibrary(self): |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
1321 |
dialog = wx.FileDialog(self.GetCTRoot().AppFrame, _("Choose an XML file"), os.getcwd(), "", _("XML files (*.xml)|*.xml|All files|*.*"), wx.OPEN) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1322 |
if dialog.ShowModal() == wx.ID_OK: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1323 |
filepath = dialog.GetPath() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1324 |
if os.path.isfile(filepath): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1325 |
shutil.copy(filepath, self.GetModulesLibraryPath()) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1326 |
self.LoadModulesLibrary() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1327 |
else: |
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
1328 |
self.GetCTRoot().logger.write_error(_("No such XML file: %s\n") % filepath) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1329 |
dialog.Destroy() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1330 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
1331 |
ConfNodeMethods = [ |
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
1332 |
{"bitmap" : os.path.join(CONFNODEFOLDER, "images", "ImportESI"), |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1333 |
"name" : _("Import module library"), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1334 |
"tooltip" : _("Import module library"), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1335 |
"method" : "_ImportModuleLibrary"}, |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1336 |
] |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1337 |
|
2048
5726f2bbdace
reflected changes in beremiz extension mechanism
Edouard Tisserant
parents:
2047
diff
changeset
|
1338 |
def CTNGenerate_C(self, buildpath, locations): |
2023
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
1339 |
return [],"",False |
f9f884cf3033
Adding support for not configuring pdos when not mandatory and not needed by locations defined in PLC program. Adding support for displaying locations tree in Topology panel and BrowseLocationsDialog. Merging pdos grid and variables grid into one single grid in slave infos panel.
laurent
parents:
2022
diff
changeset
|
1340 |
|
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1341 |
def LoadModulesLibrary(self): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1342 |
self.ModulesLibrary = {} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1343 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1344 |
library_path = self.GetModulesLibraryPath() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1345 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1346 |
files = os.listdir(library_path) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1347 |
for file in files: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1348 |
filepath = os.path.join(library_path, file) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1349 |
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
|
1350 |
xmlfile = open(filepath, 'r') |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1351 |
xml_tree = minidom.parse(xmlfile) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1352 |
xmlfile.close() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1353 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1354 |
modules_infos = None |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1355 |
for child in xml_tree.childNodes: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1356 |
if child.nodeType == xml_tree.ELEMENT_NODE and child.nodeName == "EtherCATInfo": |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1357 |
modules_infos = EtherCATInfoClasses["EtherCATInfo.xsd"]["EtherCATInfo"]() |
2051 | 1358 |
modules_infos.loadXMLTree(child) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1359 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1360 |
if modules_infos is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1361 |
vendor = modules_infos.getVendor() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1362 |
|
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1363 |
vendor_category = self.ModulesLibrary.setdefault(ExtractHexDecValue(vendor.getId()), |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1364 |
{"name": ExtractName(vendor.getName(), _("Miscellaneous")), |
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1365 |
"groups": {}}) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1366 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1367 |
for group in modules_infos.getDescriptions().getGroups().getGroup(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1368 |
group_type = group.getType() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1369 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1370 |
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
|
1371 |
"parent": group.getParentGroup(), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1372 |
"order": group.getSortOrder(), |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1373 |
"devices": []}) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1374 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1375 |
for device in modules_infos.getDescriptions().getDevices().getDevice(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1376 |
device_group = device.getGroupType() |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1377 |
if not vendor_category["groups"].has_key(device_group): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1378 |
raise ValueError, "Not such group \"%\"" % device_group |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1379 |
vendor_category["groups"][device_group]["devices"].append((device.getType().getcontent(), device)) |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1380 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1381 |
def GetModulesLibrary(self, profile_filter=None): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1382 |
library = [] |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1383 |
children_dict = {} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1384 |
for vendor_id, vendor in self.ModulesLibrary.iteritems(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1385 |
groups = [] |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1386 |
for group_type, group in vendor["groups"].iteritems(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1387 |
group_infos = {"name": group["name"], |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1388 |
"order": group["order"], |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1389 |
"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
|
1390 |
"infos": None, |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1391 |
"children": children_dict.setdefault(group_type, [])} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1392 |
device_dict = {} |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1393 |
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
|
1394 |
if profile_filter is None or profile_filter in device.GetProfileNumbers(): |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1395 |
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
|
1396 |
"type": ETHERCAT_DEVICE, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1397 |
"infos": {"device_type": 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
|
1398 |
"vendor": vendor_id, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1399 |
"product_code": device.getType().getProductCode(), |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1400 |
"revision_number": device.getType().getRevisionNo()}, |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1401 |
"children": []} |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1402 |
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
|
1403 |
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
|
1404 |
device_type_occurrences.append(device_infos) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1405 |
for device_type_occurrences in device_dict.itervalues(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1406 |
if len(device_type_occurrences) > 1: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1407 |
for occurrence in device_type_occurrences: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1408 |
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
|
1409 |
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
|
1410 |
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
|
1411 |
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
|
1412 |
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
|
1413 |
else: |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1414 |
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
|
1415 |
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
|
1416 |
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
|
1417 |
"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
|
1418 |
"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
|
1419 |
"children": groups}) |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1420 |
library.sort(lambda x, y: cmp(x["name"], y["name"])) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1421 |
return library |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1422 |
|
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1423 |
def GetModuleInfos(self, type_infos): |
2031
c6f32810723e
Fix some issues regarding arbitrary variable mapping
laurent
parents:
2030
diff
changeset
|
1424 |
vendor = self.ModulesLibrary.get(ExtractHexDecValue(type_infos["vendor"]), None) |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1425 |
if vendor is not None: |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1426 |
for group_name, group in vendor["groups"].iteritems(): |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1427 |
for device_type, device in group["devices"]: |
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
|
1428 |
product_code = ExtractHexDecValue(device.getType().getProductCode()) |
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
|
1429 |
revision_number = ExtractHexDecValue(device.getType().getRevisionNo()) |
2042
563ccc918ded
Adding support for remotely scanning Etherlab network and automatically configure it
laurent
parents:
2041
diff
changeset
|
1430 |
if (product_code == ExtractHexDecValue(type_infos["product_code"]) and |
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
|
1431 |
revision_number == ExtractHexDecValue(type_infos["revision_number"])): |
2022
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1432 |
return device |
c2295d311402
First working implementation of Beremiz plugin for etherlab
laurent
parents:
diff
changeset
|
1433 |
return None |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1434 |
|
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2039
diff
changeset
|
1435 |