--- 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; + ETHERLAB%(ucase_blocktype)s_body__(&%(blockname)s); + BLOCK_FUNTION_DEFINITION_TEMPLATE = " __CIA402Node_%(location)s.axis->__mcl_func_%(blocktype)s = &(__%(blocktype)s_%(location)s);" + {"blocktype": "GetTorqueLimit", + "outputs": [{"name": "TorqueLimitPos", "type": "UINT"}, + {"name": "TorqueLimitNeg", "type": "UINT"}]}, + {"blocktype": "SetTorqueLimit", + "inputs": [{"name": "TorqueLimitPos", "type": "UINT"}, + {"name": "TorqueLimitNeg", "type": "UINT"}], class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN):
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
@@ -260,6 +285,11 @@
+ 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,
"extern_located_variables_declaration": [],
+ "fieldbus_interface_declaration": [], + "fieldbus_interface_definition": [], "init_entry_variables": [],
@@ -301,6 +333,39 @@
"extra_variables_publish": []
+ for blocktype_infos in GLOBAL_INSTANCES: + "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"]] + 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"]] + 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", --- 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 @@
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()
*__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;
--- 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 @@
creationDateTime="2012-10-22T12:12:45"/>
<contentHeader name="EtherlabMaster SDO Blocks"
- modificationDateTime="2012-10-25T19:53:33">
+ modificationDateTime="2012-11-13T18:03:39"> @@ -267,6 +267,1042 @@
+ <pou name="EtherLabSetTorqueLimit" pouType="functionBlock"> + <variable name="Execute"> + <variable name="TorqueLimitPos"> + <variable name="TorqueLimitNeg"> + <variable name="Error"> + <variable name="ErrorID"> + <variable name="EtherLabSDOUpload0"> + <derived name="EtherLabSDODownload"/> + <variable name="EtherLabSDOUpload1"> + <derived name="EtherLabSDODownload"/> + <block localId="1" width="168" height="238" typeName="EtherLabSDODownload" instanceName="EtherLabSDOUpload0"> + <position x="479" y="70"/> + <variable formalParameter="EXECUTE"> + <relPosition x="0" y="38"/> + <connection refLocalId="3"> + <position x="479" y="108"/> + <position x="111" y="108"/> + <variable formalParameter="POS"> + <relPosition x="0" y="74"/> + <connection refLocalId="4"> + <position x="479" y="144"/> + <position x="423" y="144"/> + <variable formalParameter="INDEX"> + <relPosition x="0" y="110"/> + <connection refLocalId="6"> + <position x="479" y="180"/> + <position x="423" y="180"/> + <variable formalParameter="SUBINDEX"> + <relPosition x="0" y="146"/> + <connection refLocalId="8"> + <position x="479" y="216"/> + <position x="423" y="216"/> + <variable formalParameter="VARTYPE"> + <relPosition x="0" y="182"/> + <connection refLocalId="10"> + <position x="479" y="252"/> + <position x="423" y="252"/> + <variable formalParameter="VALUE"> + <relPosition x="0" y="218"/> + <connection refLocalId="25" formalParameter="OUT"> + <position x="479" y="288"/> + <position x="450" y="288"/> + <position x="450" y="306"/> + <position x="422" y="306"/> + <variable formalParameter="ACK"> + <relPosition x="168" y="38"/> + <variable formalParameter="ERROR"> + <relPosition x="168" y="74"/> + <block localId="2" width="168" height="264" typeName="EtherLabSDODownload" instanceName="EtherLabSDOUpload1"> + <position x="482" y="351"/> + <variable formalParameter="EXECUTE"> + <relPosition x="0" y="40"/> + <connection refLocalId="3"> + <position x="482" y="391"/> + <position x="131" y="391"/> + <position x="131" y="108"/> + <position x="111" y="108"/> + <variable formalParameter="POS"> + <relPosition x="0" y="80"/> + <connection refLocalId="5"> + <position x="482" y="431"/> + <position x="431" y="431"/> + <variable formalParameter="INDEX"> + <relPosition x="0" y="120"/> + <connection refLocalId="7"> + <position x="482" y="471"/> + <position x="431" y="471"/> + <variable formalParameter="SUBINDEX"> + <relPosition x="0" y="160"/> + <connection refLocalId="9"> + <position x="482" y="511"/> + <position x="430" y="511"/> + <variable formalParameter="VARTYPE"> + <relPosition x="0" y="200"/> + <connection refLocalId="11"> + <position x="482" y="551"/> + <position x="431" y="551"/> + <variable formalParameter="VALUE"> + <relPosition x="0" y="240"/> + <connection refLocalId="12" formalParameter="OUT"> + <position x="482" y="591"/> + <position x="456" y="591"/> + <position x="456" y="610"/> + <position x="431" y="610"/> + <variable formalParameter="ACK"> + <relPosition x="168" y="40"/> + <variable formalParameter="ERROR"> + <relPosition x="168" y="80"/> + <inVariable localId="3" height="27" width="63"> + <position x="48" y="95"/> + <relPosition x="63" y="13"/> + <expression>Execute</expression> + <inVariable localId="4" height="27" width="35"> + <position x="388" y="131"/> + <relPosition x="35" y="13"/> + <expression>Pos</expression> + <inVariable localId="5" height="27" width="35"> + <position x="396" y="418"/> + <relPosition x="35" y="13"/> + <expression>Pos</expression> + <inVariable localId="6" height="27" width="68"> + <position x="355" y="167"/> + <relPosition x="68" y="13"/> + <expression>16#60E0</expression> + <inVariable localId="7" height="27" width="68"> + <position x="363" y="458"/> + <relPosition x="68" y="13"/> + <expression>16#60E0</expression> + <inVariable localId="8" height="27" width="33"> + <position x="390" y="203"/> + <relPosition x="33" y="13"/> + <expression>0</expression> + <inVariable localId="9" height="27" width="33"> + <position x="397" y="498"/> + <relPosition x="33" y="13"/> + <expression>0</expression> + <inVariable localId="10" height="27" width="60"> + <position x="363" y="239"/> + <relPosition x="60" y="13"/> + <expression>'uint16'</expression> + <inVariable localId="11" height="27" width="60"> + <position x="371" y="538"/> + <relPosition x="60" y="13"/> + <expression>'uint16'</expression> + <block localId="16" width="67" height="98" typeName="AND"> + <position x="763" y="69"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="39"/> + <connection refLocalId="1" formalParameter="ACK"> + <position x="763" y="108"/> + <position x="647" y="108"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="78"/> + <connection refLocalId="2" formalParameter="ACK"> + <position x="763" y="147"/> + <position x="707" y="147"/> + <position x="707" y="391"/> + <position x="650" y="391"/> + <variable formalParameter="OUT"> + <relPosition x="67" y="39"/> + <outVariable localId="17" height="27" width="45"> + <position x="941" y="95"/> + <relPosition x="0" y="13"/> + <connection refLocalId="16" formalParameter="OUT"> + <position x="941" y="108"/> + <position x="830" y="108"/> + <expression>Done</expression> + <block localId="18" width="67" height="111" typeName="OR"> + <position x="778" y="344"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="42"/> + <connection refLocalId="1" formalParameter="ERROR"> + <position x="778" y="386"/> + <position x="752" y="386"/> + <position x="752" y="254"/> + <position x="659" y="254"/> + <position x="659" y="144"/> + <position x="647" y="144"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="87"/> + <connection refLocalId="2" formalParameter="ERROR"> + <position x="778" y="431"/> + <position x="650" y="431"/> + <variable formalParameter="OUT"> + <relPosition x="67" y="42"/> + <block localId="19" width="67" height="98" typeName="AND"> + <position x="933" y="308"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="39"/> + <connection refLocalId="16" formalParameter="OUT"> + <position x="933" y="347"/> + <position x="886" y="347"/> + <position x="886" y="108"/> + <position x="830" y="108"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="78"/> + <connection refLocalId="18" formalParameter="OUT"> + <position x="933" y="386"/> + <position x="845" y="386"/> + <variable formalParameter="OUT"> + <relPosition x="67" y="39"/> + <outVariable localId="20" height="27" width="45"> + <position x="1037" y="334"/> + <relPosition x="0" y="13"/> + <connection refLocalId="19" formalParameter="OUT"> + <position x="1037" y="347"/> + <position x="1000" y="347"/> + <expression>Error</expression> + <block localId="22" width="97" height="93" typeName="RS" instanceName="RS0"> + <position x="854" y="498"/> + <variable formalParameter="S"> + <relPosition x="0" y="38"/> + <connection refLocalId="23"> + <position x="854" y="536"/> + <position x="795" y="536"/> + <variable formalParameter="R1"> + <relPosition x="0" y="74"/> + <connection refLocalId="21"> + <position x="854" y="572"/> + <position x="790" y="572"/> + <variable formalParameter="Q1"> + <relPosition x="97" y="38"/> + <inVariable localId="21" height="27" width="45"> + <position x="745" y="559"/> + <relPosition x="45" y="13"/> + <expression>Done</expression> + <inVariable localId="23" height="27" width="63"> + <position x="732" y="523"/> + <relPosition x="63" y="13"/> + <expression>Execute</expression> + <outVariable localId="24" height="27" width="41"> + <position x="1006" y="523"/> + <relPosition x="0" y="13"/> + <connection refLocalId="22" formalParameter="Q1"> + <position x="1006" y="536"/> + <position x="951" y="536"/> + <expression>Busy</expression> + <block localId="25" width="126" height="40" typeName="UINT_TO_STRING"> + <position x="296" y="276"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="14"> + <position x="296" y="306"/> + <position x="262" y="306"/> + <variable formalParameter="OUT"> + <relPosition x="126" y="30"/> + <inVariable localId="14" height="27" width="117"> + <position x="145" y="293"/> + <relPosition x="117" y="13"/> + <expression>TorqueLimitPos</expression> + <block localId="12" width="126" height="40" typeName="UINT_TO_STRING"> + <position x="305" y="580"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="15"> + <position x="305" y="610"/> + <position x="283" y="610"/> + <position x="283" y="611"/> + <position x="262" y="611"/> + <variable formalParameter="OUT"> + <relPosition x="126" y="30"/> + <inVariable localId="15" height="27" width="119"> + <position x="143" y="598"/> + <relPosition x="119" y="13"/> + <expression>TorqueLimitNeg</expression> + <pou name="EtherLabGetTorqueLimit" pouType="functionBlock"> + <variable name="Execute"> + <variable name="Error"> + <variable name="ErrorID"> + <variable name="TorqueLimitPos"> + <variable name="TorqueLimitNeg"> + <variable name="EtherLabSDOUpload0"> + <derived name="EtherLabSDOUpload"/> + <variable name="EtherLabSDOUpload1"> + <derived name="EtherLabSDOUpload"/> + <block localId="1" width="149" height="203" typeName="EtherLabSDOUpload" instanceName="EtherLabSDOUpload0"> + <position x="283" y="70"/> + <variable formalParameter="EXECUTE"> + <relPosition x="0" y="38"/> + <connection refLocalId="3"> + <position x="283" y="108"/> + <position x="111" y="108"/> + <variable formalParameter="POS"> + <relPosition x="0" y="74"/> + <connection refLocalId="4"> + <position x="283" y="144"/> + <position x="219" y="144"/> + <variable formalParameter="INDEX"> + <relPosition x="0" y="110"/> + <connection refLocalId="6"> + <position x="283" y="180"/> + <position x="219" y="180"/> + <variable formalParameter="SUBINDEX"> + <relPosition x="0" y="146"/> + <connection refLocalId="8"> + <position x="283" y="216"/> + <position x="219" y="216"/> + <variable formalParameter="VARTYPE"> + <relPosition x="0" y="182"/> + <connection refLocalId="10"> + <position x="283" y="252"/> + <position x="219" y="252"/> + <variable formalParameter="ACK"> + <relPosition x="149" y="38"/> + <variable formalParameter="VALID"> + <relPosition x="149" y="74"/> + <variable formalParameter="VALUE"> + <relPosition x="149" y="110"/> + <block localId="2" width="149" height="228" typeName="EtherLabSDOUpload" instanceName="EtherLabSDOUpload1"> + <position x="284" y="321"/> + <variable formalParameter="EXECUTE"> + <relPosition x="0" y="40"/> + <connection refLocalId="3"> + <position x="284" y="361"/> + <position x="131" y="361"/> + <position x="131" y="108"/> + <position x="111" y="108"/> + <variable formalParameter="POS"> + <relPosition x="0" y="81"/> + <connection refLocalId="5"> + <position x="284" y="402"/> + <position x="219" y="402"/> + <variable formalParameter="INDEX"> + <relPosition x="0" y="122"/> + <connection refLocalId="7"> + <position x="284" y="443"/> + <position x="219" y="443"/> + <variable formalParameter="SUBINDEX"> + <relPosition x="0" y="163"/> + <connection refLocalId="9"> + <position x="284" y="484"/> + <position x="219" y="484"/> + <variable formalParameter="VARTYPE"> + <relPosition x="0" y="204"/> + <connection refLocalId="11"> + <position x="284" y="525"/> + <position x="219" y="525"/> + <variable formalParameter="ACK"> + <relPosition x="149" y="40"/> + <variable formalParameter="VALID"> + <relPosition x="149" y="81"/> + <variable formalParameter="VALUE"> + <relPosition x="149" y="122"/> + <inVariable localId="3" height="27" width="63"> + <position x="48" y="95"/> + <relPosition x="63" y="13"/> + <expression>Execute</expression> + <inVariable localId="4" height="27" width="35"> + <position x="184" y="131"/> + <relPosition x="35" y="13"/> + <expression>Pos</expression> + <inVariable localId="5" height="27" width="35"> + <position x="184" y="389"/> + <relPosition x="35" y="13"/> + <expression>Pos</expression> + <inVariable localId="6" height="27" width="68"> + <position x="151" y="167"/> + <relPosition x="68" y="13"/> + <expression>16#60E0</expression> + <inVariable localId="7" height="27" width="68"> + <position x="151" y="430"/> + <relPosition x="68" y="13"/> + <expression>16#60E0</expression> + <inVariable localId="8" height="27" width="33"> + <position x="186" y="203"/> + <relPosition x="33" y="13"/> + <expression>0</expression> + <inVariable localId="9" height="27" width="33"> + <position x="186" y="471"/> + <relPosition x="33" y="13"/> + <expression>0</expression> + <inVariable localId="10" height="27" width="60"> + <position x="159" y="239"/> + <relPosition x="60" y="13"/> + <expression>'uint16'</expression> + <inVariable localId="11" height="27" width="60"> + <position x="159" y="512"/> + <relPosition x="60" y="13"/> + <expression>'uint16'</expression> + <block localId="12" width="126" height="40" typeName="STRING_TO_UINT"> + <position x="492" y="150"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="1" formalParameter="VALUE"> + <position x="492" y="180"/> + <position x="432" y="180"/> + <variable formalParameter="OUT"> + <relPosition x="126" y="30"/> + <block localId="13" width="126" height="40" typeName="STRING_TO_UINT"> + <position x="498" y="413"/> + <variable formalParameter="IN"> + <relPosition x="0" y="30"/> + <connection refLocalId="2" formalParameter="VALUE"> + <position x="498" y="443"/> + <position x="433" y="443"/> + <variable formalParameter="OUT"> + <relPosition x="126" y="30"/> + <outVariable localId="14" height="27" width="117"> + <position x="673" y="167"/> + <relPosition x="0" y="13"/> + <connection refLocalId="12" formalParameter="OUT"> + <position x="673" y="180"/> + <position x="618" y="180"/> + <expression>TorqueLimitPos</expression> + <outVariable localId="15" height="27" width="119"> + <position x="679" y="430"/> + <relPosition x="0" y="13"/> + <connection refLocalId="13" formalParameter="OUT"> + <position x="679" y="443"/> + <position x="624" y="443"/> + <expression>TorqueLimitNeg</expression> + <block localId="16" width="67" height="98" typeName="AND"> + <position x="861" y="69"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="39"/> + <connection refLocalId="1" formalParameter="ACK"> + <position x="861" y="108"/> + <position x="432" y="108"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="78"/> + <connection refLocalId="2" formalParameter="ACK"> + <position x="861" y="147"/> + <position x="804" y="147"/> + <position x="804" y="361"/> + <position x="433" y="361"/> + <variable formalParameter="OUT"> + <relPosition x="67" y="39"/> + <outVariable localId="17" height="27" width="45"> + <position x="1009" y="95"/> + <relPosition x="0" y="13"/> + <connection refLocalId="16" formalParameter="OUT"> + <position x="1009" y="108"/> + <position x="928" y="108"/> + <expression>Done</expression> + <block localId="18" width="67" height="111" typeName="OR"> + <position x="862" y="315"/> + <variable formalParameter="IN1" negated="true"> + <relPosition x="0" y="42"/> + <connection refLocalId="1" formalParameter="VALID"> + <position x="862" y="357"/> + <position x="839" y="357"/> + <position x="839" y="254"/> + <position x="469" y="254"/> + <position x="469" y="144"/> + <position x="432" y="144"/> + <variable formalParameter="IN2" negated="true"> + <relPosition x="0" y="87"/> + <connection refLocalId="2" formalParameter="VALID"> + <position x="862" y="402"/> + <position x="433" y="402"/> + <variable formalParameter="OUT"> + <relPosition x="67" y="42"/> + <block localId="19" width="67" height="98" typeName="AND"> + <position x="989" y="279"/> + <variable formalParameter="IN1"> + <relPosition x="0" y="39"/> + <connection refLocalId="16" formalParameter="OUT"> + <position x="989" y="318"/> + <position x="958" y="318"/> + <position x="958" y="108"/> + <position x="928" y="108"/> + <variable formalParameter="IN2"> + <relPosition x="0" y="78"/> + <connection refLocalId="18" formalParameter="OUT"> + <position x="989" y="357"/> + <position x="929" y="357"/> + <variable formalParameter="OUT"> + <relPosition x="67" y="39"/> + <outVariable localId="20" height="27" width="45"> + <position x="1102" y="305"/> + <relPosition x="0" y="13"/> + <connection refLocalId="19" formalParameter="OUT"> + <position x="1102" y="318"/> + <position x="1056" y="318"/> + <expression>Error</expression> + <block localId="22" width="97" height="93" typeName="RS" instanceName="RS0"> + <position x="657" y="517"/> + <variable formalParameter="S"> + <relPosition x="0" y="38"/> + <connection refLocalId="23"> + <position x="657" y="555"/> + <position x="600" y="555"/> + <variable formalParameter="R1"> + <relPosition x="0" y="74"/> + <connection refLocalId="21"> + <position x="657" y="591"/> + <position x="599" y="591"/> + <variable formalParameter="Q1"> + <relPosition x="97" y="38"/> + <inVariable localId="21" height="27" width="45"> + <position x="554" y="578"/> + <relPosition x="45" y="13"/> + <expression>Done</expression> + <inVariable localId="23" height="27" width="63"> + <position x="537" y="542"/> + <relPosition x="63" y="13"/> + <expression>Execute</expression> + <outVariable localId="24" height="27" width="41"> + <position x="811" y="542"/> + <relPosition x="0" y="13"/> + <connection refLocalId="22" formalParameter="Q1"> + <position x="811" y="555"/> + <position x="754" y="555"/> + <expression>Busy</expression>