# HG changeset patch # User Laurent Bessard # Date 1353015824 -3600 # Node ID c9776ae8b5d0b46820033979ad1eafcc08e3f544 # Parent d964dbc2c7b0bb7c12bb2eafaabbc8a08d2df5d2 Adding support for Etherlab specific function blocks for MCL fieldbus interface function blocks diff -r d964dbc2c7b0 -r c9776ae8b5d0 etherlab/etherlab.py --- a/etherlab/etherlab.py Fri Nov 09 11:27:30 2012 +0100 +++ b/etherlab/etherlab.py Thu Nov 15 22:43:44 2012 +0100 @@ -208,6 +208,31 @@ ]) ] EXTRA_NODE_VARIABLES_DICT = dict([("Enable" + name, value) for name, value in EXTRA_NODE_VARIABLES]) + + BLOCK_INPUT_TEMPLATE = " __SET_VAR(%(blockname)s.,%(input_name)s, %(input_value)s);" + BLOCK_OUTPUT_TEMPLATE = " __SET_VAR(data__->,%(output_name)s, __GET_VAR(%(blockname)s.%(output_name)s));" + + BLOCK_FUNCTION_TEMPLATE = """ +void __%(blocktype)s_%(location)s(MCL_%(ucase_blocktype)s *data__) { + extern ETHERLAB%(ucase_blocktype)s %(blockname)s; +%(extract_inputs)s + ETHERLAB%(ucase_blocktype)s_body__(&%(blockname)s); +%(return_outputs)s +} +""" + + BLOCK_FUNTION_DEFINITION_TEMPLATE = " __CIA402Node_%(location)s.axis->__mcl_func_%(blocktype)s = &(__%(blocktype)s_%(location)s);" + + GLOBAL_INSTANCES = [ + {"blocktype": "GetTorqueLimit", + "inputs": [], + "outputs": [{"name": "TorqueLimitPos", "type": "UINT"}, + {"name": "TorqueLimitNeg", "type": "UINT"}]}, + {"blocktype": "SetTorqueLimit", + "inputs": [{"name": "TorqueLimitPos", "type": "UINT"}, + {"name": "TorqueLimitNeg", "type": "UINT"}], + "outputs": []}, + ] class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN): XSD = """ @@ -260,6 +285,11 @@ "children": children, } + def CTNGlobalInstances(self): + current_location = self.GetCurrentLocation() + return [("%s_%s" % (block_infos["blocktype"], "_".join(map(str, current_location))), + "EtherLab%s" % block_infos["blocktype"]) for block_infos in GLOBAL_INSTANCES] + def _getCIA402AxisRef(self): data = wx.TextDataObject(str(("%%IW%s.0" % ".".join(map(str, self.GetCurrentLocation())), "location", "AXIS_REF", self.CTNName(), ""))) @@ -294,6 +324,8 @@ "location": location_str, "MCL_headers": Headers, "extern_located_variables_declaration": [], + "fieldbus_interface_declaration": [], + "fieldbus_interface_definition": [], "entry_variables": [], "init_axis_params": [], "init_entry_variables": [], @@ -301,6 +333,39 @@ "extra_variables_publish": [] } + for blocktype_infos in GLOBAL_INSTANCES: + texts = { + "blocktype": blocktype_infos["blocktype"], + "ucase_blocktype": blocktype_infos["blocktype"].upper(), + "location": "_".join(map(str, current_location)) + } + texts["blockname"] = "%(ucase_blocktype)s_%(location)s" % texts + + inputs = [{"input_name": "POS", "input_value": str(self.GetSlavePos())}, + {"input_name": "EXECUTE", "input_value": "__GET_VAR(data__->EXECUTE)"}] +\ + [{"input_name": input["name"].upper(), + "input_value": "__GET_VAR(data__->%s)" % input["name"].upper()} + for input in blocktype_infos["inputs"]] + input_texts = [] + for input_infos in inputs: + input_infos.update(texts) + input_texts.append(BLOCK_INPUT_TEMPLATE % input_infos) + texts["extract_inputs"] = "\n".join(input_texts) + + outputs = [{"output_name": output} for output in ["DONE", "BUSY", "ERROR"]] + \ + [{"output_name": output["name"].upper()} for output in blocktype_infos["outputs"]] + output_texts = [] + for output_infos in outputs: + output_infos.update(texts) + output_texts.append(BLOCK_OUTPUT_TEMPLATE % output_infos) + texts["return_outputs"] = "\n".join(output_texts) + + str_completion["fieldbus_interface_declaration"].append( + BLOCK_FUNCTION_TEMPLATE % texts) + + str_completion["fieldbus_interface_definition"].append( + BLOCK_FUNTION_DEFINITION_TEMPLATE % texts) + variables = NODE_VARIABLES[:] params = self.CTNParams[1].getElementInfos(self.CTNParams[0]) @@ -353,6 +418,8 @@ var_infos["var_type"], var_infos["dir"], var_infos["var_name"]) for element in ["extern_located_variables_declaration", + "fieldbus_interface_declaration", + "fieldbus_interface_definition", "entry_variables", "init_axis_params", "init_entry_variables", diff -r d964dbc2c7b0 -r c9776ae8b5d0 etherlab/plc_cia402node.c --- a/etherlab/plc_cia402node.c Fri Nov 09 11:27:30 2012 +0100 +++ b/etherlab/plc_cia402node.c Thu Nov 15 22:43:44 2012 +0100 @@ -11,6 +11,8 @@ #include "iec_std_lib.h" #endif +#include "POUS.h" + IEC_INT beremiz__IW%(location)s_0; IEC_INT *__IW%(location)s_0 = &beremiz__IW%(location)s_0; @@ -48,11 +50,14 @@ %(extern_located_variables_declaration)s +%(fieldbus_interface_declaration)s + int __init_%(location)s() { %(init_entry_variables)s *__IW%(location)s_0 = __MK_Alloc_AXIS_REF(); __CIA402Node_%(location)s.axis = __MK_GetPublic_AXIS_REF(*__IW%(location)s_0); +%(fieldbus_interface_definition)s __MK_Set_AXIS_REF_Pos(*__IW%(location)s_0, %(slave_pos)d); *(__CIA402Node_%(location)s.ModesOfOperation) = 0x08; return 0; diff -r d964dbc2c7b0 -r c9776ae8b5d0 etherlab/pous.xml --- a/etherlab/pous.xml Fri Nov 09 11:27:30 2012 +0100 +++ b/etherlab/pous.xml Thu Nov 15 22:43:44 2012 +0100 @@ -8,7 +8,7 @@ productVersion="1" creationDateTime="2012-10-22T12:12:45"/> + modificationDateTime="2012-11-13T18:03:39"> @@ -267,6 +267,1042 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execute + + + + + + + Pos + + + + + + + Pos + + + + + + + 16#60E0 + + + + + + + 16#60E0 + + + + + + + 0 + + + + + + + 0 + + + + + + + 'uint16' + + + + + + + 'uint16' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Done + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Done + + + + + + + Execute + + + + + + + + + + + Busy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TorqueLimitPos + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TorqueLimitNeg + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Execute + + + + + + + Pos + + + + + + + Pos + + + + + + + 16#60E0 + + + + + + + 16#60E0 + + + + + + + 0 + + + + + + + 0 + + + + + + + 'uint16' + + + + + + + 'uint16' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TorqueLimitPos + + + + + + + + + + + TorqueLimitNeg + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Done + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Done + + + + + + + Execute + + + + + + + + + + + Busy + + + +