102 </xsd:complexType> |
104 </xsd:complexType> |
103 </xsd:element> |
105 </xsd:element> |
104 </xsd:schema> |
106 </xsd:schema> |
105 """ % ("\n".join(["""\ |
107 """ % ("\n".join(["""\ |
106 <xsd:attribute name="Enable%s" type="xsd:boolean" |
108 <xsd:attribute name="Enable%s" type="xsd:boolean" |
107 use="optional" default="false"/>""" % category |
109 use="optional" default="false"/>""" % category |
108 for category, variables in EXTRA_NODE_VARIABLES]) + AxisXSD) |
110 for category, variables in EXTRA_NODE_VARIABLES]) + AxisXSD) |
109 |
111 |
110 NODE_PROFILE = 402 |
112 NODE_PROFILE = 402 |
111 EditorType = CIA402NodeEditor |
113 EditorType = CIA402NodeEditor |
112 |
114 |
113 ConfNodeMethods = [ |
115 ConfNodeMethods = [ |
114 {"bitmap" : "CIA402AxisRef", |
116 { |
115 "name" : _("Axis Ref"), |
117 "bitmap": "CIA402AxisRef", |
116 "tooltip" : _("Initiate Drag'n drop of Axis ref located variable"), |
118 "name": _("Axis Ref"), |
117 "method" : "_getCIA402AxisRef", |
119 "tooltip": _("Initiate Drag'n drop of Axis ref located variable"), |
118 "push": True}, |
120 "method": "_getCIA402AxisRef", |
119 {"bitmap" : "CIA402NetPos", |
121 "push": True, |
120 "name" : _("Axis Pos"), |
122 }, |
121 "tooltip" : _("Initiate Drag'n drop of Network position located variable"), |
123 { |
122 "method" : "_getCIA402NetworkPosition", |
124 "bitmap": "CIA402NetPos", |
123 "push": True}, |
125 "name": _("Axis Pos"), |
|
126 "tooltip": _("Initiate Drag'n drop of Network position located variable"), |
|
127 "method": "_getCIA402NetworkPosition", |
|
128 "push": True, |
|
129 }, |
124 ] |
130 ] |
125 |
131 |
126 #-------------------------------------------------- |
132 # -------------------------------------------------- |
127 # class code |
133 # class code |
128 #-------------------------------------------------- |
134 # -------------------------------------------------- |
129 |
135 |
130 def __init__(self): |
136 def __init__(self): |
|
137 _EthercatSlaveCTN.__init__(self) |
|
138 |
131 # ----------- call ethercat mng. function -------------- |
139 # ----------- call ethercat mng. function -------------- |
132 self.CommonMethod = _CommonSlave(self) |
140 self.CommonMethod = _CommonSlave(self) |
133 |
141 |
134 def GetIconName(self): |
142 def GetIconName(self): |
135 return "CIA402Slave" |
143 return "CIA402Slave" |
136 |
144 |
137 def SetParamsAttribute(self, path, value): |
145 def SetParamsAttribute(self, path, value): |
138 if path == "CIA402SlaveParams.Type": |
146 if path == "CIA402SlaveParams.Type": |
139 path = "SlaveParams.Type" |
147 path = "SlaveParams.Type" |
140 elif path == "CIA402SlaveParams.Alias": |
148 elif path == "CIA402SlaveParams.Alias": |
141 path = "SlaveParams.Alias" |
149 path = "SlaveParams.Alias" |
142 return _EthercatSlaveCTN.SetParamsAttribute(self, path, value) |
150 return _EthercatSlaveCTN.SetParamsAttribute(self, path, value) |
143 |
151 |
144 def GetVariableLocationTree(self): |
152 def GetVariableLocationTree(self): |
145 axis_name = self.CTNName() |
153 axis_name = self.CTNName() |
146 current_location = self.GetCurrentLocation() |
154 current_location = self.GetCurrentLocation() |
147 children = [{"name": name_frmt % (axis_name), |
155 children = [ |
148 "type": LOCATION_VAR_INPUT, |
156 { |
149 "size": "W", |
157 "name": name_frmt % (axis_name), |
150 "IEC_type": iec_type, |
158 "type": LOCATION_VAR_INPUT, |
151 "var_name": var_name_frmt % axis_name, |
159 "size": "W", |
152 "location": location_frmt % ( |
160 "IEC_type": iec_type, |
153 ".".join(map(str, current_location))), |
161 "var_name": var_name_frmt % axis_name, |
154 "description": "", |
162 "location": location_frmt % (".".join(map(str, current_location))), |
155 "children": []} |
163 "description": "", |
156 for name_frmt, iec_type, var_name_frmt, location_frmt in |
164 "children": [] |
157 [("%s Network Position", "UINT", "%s_pos", "%%IW%s"), |
165 } |
158 ("%s Axis Ref", "AXIS_REF", "%s", "%%IW%s.402")]] |
166 for name_frmt, iec_type, var_name_frmt, location_frmt in [ |
159 children.extend(self.CTNParent.GetDeviceLocationTree( |
167 ("%s Network Position", "UINT", "%s_pos", "%%IW%s"), |
160 self.GetSlavePos(), current_location, axis_name)) |
168 ("%s Axis Ref", "AXIS_REF", "%s", "%%IW%s.402") |
161 return {"name": axis_name, |
169 ] |
162 "type": LOCATION_CONFNODE, |
170 ] |
163 "location": self.GetFullIEC_Channel(), |
171 children.extend(self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), |
164 "children": children, |
172 current_location, |
|
173 axis_name)) |
|
174 return { |
|
175 "name": axis_name, |
|
176 "type": LOCATION_CONFNODE, |
|
177 "location": self.GetFullIEC_Channel(), |
|
178 "children": children, |
165 } |
179 } |
166 |
180 |
167 def CTNGlobalInstances(self): |
181 def CTNGlobalInstances(self): |
168 current_location = self.GetCurrentLocation() |
182 current_location = self.GetCurrentLocation() |
169 return [("%s_%s" % (block_infos["blocktype"], |
183 return [("%s_%s" % (block_infos["blocktype"], |
170 "_".join(map(str, current_location))), |
184 "_".join(map(str, current_location))), |
171 "EtherLab%s" % block_infos["blocktype"], "") |
185 "EtherLab%s" % block_infos["blocktype"], "") |
172 for block_infos in FIELDBUS_INTERFACE_GLOBAL_INSTANCES] |
186 for block_infos in FIELDBUS_INTERFACE_GLOBAL_INSTANCES] |
173 |
187 |
174 def StartDragNDrop(self, data): |
188 def StartDragNDrop(self, data): |
175 data_obj = wx.TextDataObject(str(data)) |
189 data_obj = wx.TextDataObject(str(data)) |
176 dragSource = wx.DropSource(self.GetCTRoot().AppFrame) |
190 dragSource = wx.DropSource(self.GetCTRoot().AppFrame) |
177 dragSource.SetData(data_obj) |
191 dragSource.SetData(data_obj) |
178 dragSource.DoDragDrop() |
192 dragSource.DoDragDrop() |
179 |
193 |
180 def _getCIA402NetworkPosition(self): |
194 def _getCIA402NetworkPosition(self): |
181 self.StartDragNDrop( |
195 self.StartDragNDrop( |
182 ("%%IW%s" % ".".join(map(str, self.GetCurrentLocation())), |
196 ("%%IW%s" % ".".join(map(str, self.GetCurrentLocation())), |
183 "location", "UINT", self.CTNName() + "_Pos", "")) |
197 "location", "UINT", self.CTNName() + "_Pos", "")) |
184 |
198 |
185 def _getCIA402AxisRef(self): |
199 def _getCIA402AxisRef(self): |
186 self.StartDragNDrop( |
200 self.StartDragNDrop( |
187 ("%%IW%s.402" % ".".join(map(str, self.GetCurrentLocation())), |
201 ("%%IW%s.402" % ".".join(map(str, self.GetCurrentLocation())), |
188 "location", "AXIS_REF", self.CTNName(), "")) |
202 "location", "AXIS_REF", self.CTNName(), "")) |
189 |
203 |
190 def CTNGenerate_C(self, buildpath, locations): |
204 def CTNGenerate_C(self, buildpath, locations): |
191 current_location = self.GetCurrentLocation() |
205 current_location = self.GetCurrentLocation() |
192 |
206 |
193 location_str = "_".join(map(lambda x:str(x), current_location)) |
207 location_str = "_".join(map(str, current_location)) |
194 slave_pos = self.GetSlavePos() |
208 slave_pos = self.GetSlavePos() |
195 MCL_headers = Headers |
209 |
196 |
210 # Open CIA402 node code template file |
197 # Open CIA402 node code template file |
211 plc_cia402node_filepath = os.path.join(os.path.split(__file__)[0], |
198 plc_cia402node_filepath = os.path.join(os.path.split(__file__)[0], |
|
199 "plc_cia402node.c") |
212 "plc_cia402node.c") |
200 plc_cia402node_file = open(plc_cia402node_filepath, 'r') |
213 plc_cia402node_file = open(plc_cia402node_filepath, 'r') |
201 plc_cia402node_code = plc_cia402node_file.read() |
214 plc_cia402node_code = plc_cia402node_file.read() |
202 plc_cia402node_file.close() |
215 plc_cia402node_file.close() |
203 |
216 |
204 # Init list of generated strings for each code template file section |
217 # Init list of generated strings for each code template file section |
205 fieldbus_interface_declaration = [] |
218 fieldbus_interface_declaration = [] |
206 fieldbus_interface_definition = [] |
219 fieldbus_interface_definition = [] |
207 init_axis_params = [] |
220 init_axis_params = [] |
208 extra_variables_retrieve = [] |
221 extra_variables_retrieve = [] |
209 extra_variables_publish = [] |
222 extra_variables_publish = [] |
210 extern_located_variables_declaration = [] |
223 extern_located_variables_declaration = [] |
211 entry_variables = [] |
224 entry_variables = [] |
212 init_entry_variables = [] |
225 init_entry_variables = [] |
213 |
226 |
214 # Fieldbus interface code sections |
227 # Fieldbus interface code sections |
215 for blocktype_infos in FIELDBUS_INTERFACE_GLOBAL_INSTANCES: |
228 for blocktype_infos in FIELDBUS_INTERFACE_GLOBAL_INSTANCES: |
216 blocktype = blocktype_infos["blocktype"] |
229 blocktype = blocktype_infos["blocktype"] |
217 ucase_blocktype = blocktype.upper() |
230 ucase_blocktype = blocktype.upper() |
218 blockname = "_".join([ucase_blocktype, location_str]) |
231 blockname = "_".join([ucase_blocktype, location_str]) |
219 |
232 |
220 extract_inputs = "\n".join(["""\ |
233 extract_inputs = "\n".join([ |
221 __SET_VAR(%s->, %s,, %s);""" % (blockname, input_name, input_value) |
234 """\ |
222 for (input_name, input_value) in [ |
235 __SET_VAR(%s->, %s,, %s);""" % (blockname, input_name, input_value) |
223 ("EXECUTE", "__GET_VAR(data__->EXECUTE)")] + [ |
236 for (input_name, input_value) in |
224 (input["name"].upper(), |
237 [("EXECUTE", "__GET_VAR(data__->EXECUTE)")] + [ |
|
238 (input["name"].upper(), |
225 "__GET_VAR(data__->%s)" % input["name"].upper()) |
239 "__GET_VAR(data__->%s)" % input["name"].upper()) |
226 for input in blocktype_infos["inputs"]] |
240 for input in blocktype_infos["inputs"] |
227 ]) |
241 ]]) |
228 |
242 |
229 |
243 return_outputs = "\n".join([ |
230 return_outputs = "\n".join(["""\ |
244 """\ |
231 __SET_VAR(data__->,%(output_name)s,, |
245 __SET_VAR(data__->,%(output_name)s,, |
232 __GET_VAR(%(blockname)s->%(output_name)s));""" % locals() |
246 __GET_VAR(%(blockname)s->%(output_name)s));""" % { |
233 for output_name in ["DONE", "BUSY", "ERROR"] + [ |
247 "output_name": output_name, |
234 output["name"].upper() |
248 "blockname": blockname |
235 for output in blocktype_infos["outputs"]] |
249 } |
236 ]) |
250 for output_name in ["DONE", "BUSY", "ERROR"] + [ |
237 |
251 output["name"].upper() |
|
252 for output in blocktype_infos["outputs"]] |
|
253 ]) |
|
254 |
|
255 loc_dict = { |
|
256 "ucase_blocktype": ucase_blocktype, |
|
257 "blocktype": blocktype, |
|
258 "blockname": blockname, |
|
259 "location_str": location_str, |
|
260 "extract_inputs": extract_inputs, |
|
261 "return_outputs": return_outputs, |
|
262 } |
|
263 |
238 fieldbus_interface_declaration.append(""" |
264 fieldbus_interface_declaration.append(""" |
239 extern void ETHERLAB%(ucase_blocktype)s_body__(ETHERLAB%(ucase_blocktype)s* data__); |
265 extern void ETHERLAB%(ucase_blocktype)s_body__(ETHERLAB%(ucase_blocktype)s* data__); |
240 void __%(blocktype)s_%(location_str)s(MC_%(ucase_blocktype)s *data__) { |
266 void __%(blocktype)s_%(location_str)s(MC_%(ucase_blocktype)s *data__) { |
241 __DECLARE_GLOBAL_PROTOTYPE(ETHERLAB%(ucase_blocktype)s, %(blockname)s); |
267 __DECLARE_GLOBAL_PROTOTYPE(ETHERLAB%(ucase_blocktype)s, %(blockname)s); |
242 ETHERLAB%(ucase_blocktype)s* %(blockname)s = __GET_GLOBAL_%(blockname)s(); |
268 ETHERLAB%(ucase_blocktype)s* %(blockname)s = __GET_GLOBAL_%(blockname)s(); |
243 __SET_VAR(%(blockname)s->, POS,, AxsPub.axis->NetworkPosition); |
269 __SET_VAR(%(blockname)s->, POS,, AxsPub.axis->NetworkPosition); |
244 %(extract_inputs)s |
270 %(extract_inputs)s |
245 ETHERLAB%(ucase_blocktype)s_body__(%(blockname)s); |
271 ETHERLAB%(ucase_blocktype)s_body__(%(blockname)s); |
246 %(return_outputs)s |
272 %(return_outputs)s |
247 }""" % locals()) |
273 }""" % loc_dict) |
248 |
274 |
249 fieldbus_interface_definition.append("""\ |
275 fieldbus_interface_definition.append("""\ |
250 AxsPub.axis->__mcl_func_MC_%(blocktype)s = __%(blocktype)s_%(location_str)s;\ |
276 AxsPub.axis->__mcl_func_MC_%(blocktype)s = __%(blocktype)s_%(location_str)s;\ |
251 """ % locals()) |
277 """ % loc_dict) |
252 |
278 |
253 # Get a copy list of default variables to map |
279 # Get a copy list of default variables to map |
254 variables = NODE_VARIABLES[:] |
280 variables = NODE_VARIABLES[:] |
255 |
281 |
256 # Set AxisRef public struct members value |
282 # Set AxisRef public struct members value |
257 node_params = self.CTNParams[1].getElementInfos(self.CTNParams[0]) |
283 node_params = self.CTNParams[1].getElementInfos(self.CTNParams[0]) |
258 for param in node_params["children"]: |
284 for param in node_params["children"]: |
259 param_name = param["name"] |
285 param_name = param["name"] |
260 |
286 |
261 # Param is optional variables section enable flag |
287 # Param is optional variables section enable flag |
262 extra_node_variable_infos = EXTRA_NODE_VARIABLES_DICT.get(param_name) |
288 extra_node_variable_infos = EXTRA_NODE_VARIABLES_DICT.get(param_name) |
263 if extra_node_variable_infos is not None: |
289 if extra_node_variable_infos is not None: |
264 param_name = param_name.replace("Enable", "") + "Enabled" |
290 param_name = param_name.replace("Enable", "") + "Enabled" |
265 |
291 |
266 if not param["value"]: |
292 if not param["value"]: |
267 continue |
293 continue |
268 |
294 |
269 # Optional variables section is enabled |
295 # Optional variables section is enabled |
270 for variable_infos in extra_node_variable_infos: |
296 for variable_infos in extra_node_variable_infos: |
271 var_name = variable_infos["description"][0] |
297 var_name = variable_infos["description"][0] |
272 |
298 |
273 # Add each variables defined in section description to the |
299 # Add each variables defined in section description to the |
274 # list of variables to map |
300 # list of variables to map |
275 variables.append(variable_infos["description"]) |
301 variables.append(variable_infos["description"]) |
276 |
302 |
277 # Add code to publish or retrive variable |
303 # Add code to publish or retrive variable |
278 for var_exchange_dir, str_list, default_template in [ |
304 coded = [ |
279 ("retrieve", extra_variables_retrieve, |
305 ("retrieve", |
280 " AxsPub.axis->%(var_name)s = *(AxsPub.%(var_name)s);"), |
306 extra_variables_retrieve, |
281 ("publish", extra_variables_publish, |
307 " AxsPub.axis->%(var_name)s = *(AxsPub.%(var_name)s);"), |
282 " *(AxsPub.%(var_name)s) = AxsPub.axis->%(var_name)s;")]: |
308 ("publish", |
283 |
309 extra_variables_publish, |
284 template = variable_infos.get(var_exchange_dir, |
310 " *(AxsPub.%(var_name)s) = AxsPub.axis->%(var_name)s;") |
285 default_template) |
311 ] |
|
312 for var_exchange_dir, _str_list, default_template in coded: |
|
313 template = variable_infos.get(var_exchange_dir, default_template) |
286 if template is not None: |
314 if template is not None: |
287 extra_variables_publish.append(template % locals()) |
315 extra_variables_publish.append(template % locals()) |
288 |
316 |
289 # Set AxisRef public struct member value if defined |
317 # Set AxisRef public struct member value if defined |
290 if param["value"] is not None: |
318 if param["value"] is not None: |
291 param_value = ({True: "1", False: "0"}[param["value"]] |
319 param_value = ({True: "1", False: "0"}[param["value"]] |
292 if param["type"] == "boolean" |
320 if param["type"] == "boolean" |
293 else str(param["value"])) |
321 else str(param["value"])) |
294 |
322 |
295 init_axis_params.append("""\ |
323 init_axis_params.append("""\ |
296 AxsPub.axis->%(param_name)s = %(param_value)s;""" % locals()) |
324 AxsPub.axis->%(param_name)s = %(param_value)s;""" % { |
297 |
325 "param_value": param_value, |
|
326 "param_name": param_name, |
|
327 }) |
|
328 |
298 # Add each variable in list of variables to map to master list of |
329 # Add each variable in list of variables to map to master list of |
299 # variables to add to network configuration |
330 # variables to add to network configuration |
300 for name, index, subindex, var_type, dir in variables: |
331 for name, index, subindex, var_type, dir in variables: |
301 var_size = self.GetSizeOfType(var_type) |
332 var_size = self.GetSizeOfType(var_type) |
|
333 loc_dict = { |
|
334 "var_size": var_size, |
|
335 "var_type": var_type, |
|
336 "name:": name, |
|
337 "location_str": location_str, |
|
338 "index": index, |
|
339 "subindex": subindex, |
|
340 } |
302 var_name = """\ |
341 var_name = """\ |
303 __%(dir)s%(var_size)s%(location_str)s_%(index)d_%(subindex)d""" % locals() |
342 __%(dir)s%(var_size)s%(location_str)s_%(index)d_%(subindex)d""" % loc_dict |
304 |
343 loc_dict["var_name"] = var_name |
|
344 |
305 extern_located_variables_declaration.append( |
345 extern_located_variables_declaration.append( |
306 "IEC_%(var_type)s *%(var_name)s;" % locals()) |
346 "IEC_%(var_type)s *%(var_name)s;" % loc_dict) |
307 entry_variables.append( |
347 entry_variables.append( |
308 " IEC_%(var_type)s *%(name)s;" % locals()) |
348 " IEC_%(var_type)s *%(name)s;" % loc_dict) |
309 init_entry_variables.append( |
349 init_entry_variables.append( |
310 " AxsPub.%(name)s = %(var_name)s;" % locals()) |
350 " AxsPub.%(name)s = %(var_name)s;" % loc_dict) |
311 |
351 |
312 self.CTNParent.FileGenerator.DeclareVariable( |
352 self.CTNParent.FileGenerator.DeclareVariable( |
313 slave_pos, index, subindex, var_type, dir, var_name) |
353 slave_pos, index, subindex, var_type, dir, var_name) |
314 |
354 |
315 # Add newline between string in list of generated strings for sections |
355 # Add newline between string in list of generated strings for sections |
316 [fieldbus_interface_declaration, fieldbus_interface_definition, |
356 [fieldbus_interface_declaration, fieldbus_interface_definition, |
317 init_axis_params, extra_variables_retrieve, extra_variables_publish, |
357 init_axis_params, extra_variables_retrieve, extra_variables_publish, |
318 extern_located_variables_declaration, entry_variables, |
358 extern_located_variables_declaration, entry_variables, |
319 init_entry_variables] = map(lambda l: "\n".join(l), [ |
359 init_entry_variables] = map("\n".join, [ |
320 fieldbus_interface_declaration, fieldbus_interface_definition, |
360 fieldbus_interface_declaration, fieldbus_interface_definition, |
321 init_axis_params, extra_variables_retrieve, extra_variables_publish, |
361 init_axis_params, extra_variables_retrieve, extra_variables_publish, |
322 extern_located_variables_declaration, entry_variables, |
362 extern_located_variables_declaration, entry_variables, |
323 init_entry_variables]) |
363 init_entry_variables]) |
324 |
364 |
325 # Write generated content to CIA402 node file |
365 # Write generated content to CIA402 node file |
326 Gen_CIA402Nodefile_path = os.path.join(buildpath, |
366 Gen_CIA402Nodefile_path = os.path.join(buildpath, |
327 "cia402node_%s.c"%location_str) |
367 "cia402node_%s.c" % location_str) |
328 cia402nodefile = open(Gen_CIA402Nodefile_path, 'w') |
368 cia402nodefile = open(Gen_CIA402Nodefile_path, 'w') |
329 cia402nodefile.write(plc_cia402node_code % locals()) |
369 cia402nodefile.write(plc_cia402node_code % locals()) |
330 cia402nodefile.close() |
370 cia402nodefile.close() |
331 |
371 |
332 return [(Gen_CIA402Nodefile_path, '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath()))],"",True |
372 return [(Gen_CIA402Nodefile_path, '"-I%s"' % os.path.abspath(self.GetCTRoot().GetIECLibPath()))], "", True |