Fixed bug when using real axis and simulated axis at the same time (got the same index)
authorLaurent Bessard
Fri, 05 Apr 2013 00:09:54 +0200
changeset 2118 c317b1aaf920
parent 2114 fc1bc441cf71
child 2119 5460eba6c5e0
Fixed bug when using real axis and simulated axis at the same time (got the same index)
etherlab/EthercatCIA402Slave.py
etherlab/plc_cia402node.c
--- a/etherlab/EthercatCIA402Slave.py	Thu Apr 04 17:50:43 2013 +0900
+++ b/etherlab/EthercatCIA402Slave.py	Fri Apr 05 00:09:54 2013 +0200
@@ -51,8 +51,7 @@
 }
 """
 
-BLOCK_FUNTION_DEFINITION_TEMPLATE = """    if (!__CIA402Node_%(location)s.axis->__mcl_func_MC_%(blocktype)s)
-__CIA402Node_%(location)s.axis->__mcl_func_MC_%(blocktype)s = __%(blocktype)s_%(location)s;"""
+BLOCK_FUNTION_DEFINITION_TEMPLATE = "        __CIA402Node_%(location)s.axis->__mcl_func_MC_%(blocktype)s = __%(blocktype)s_%(location)s;"
 
 GLOBAL_INSTANCES = [
     {"blocktype": "GetTorqueLimit", 
--- a/etherlab/plc_cia402node.c	Thu Apr 04 17:50:43 2013 +0900
+++ b/etherlab/plc_cia402node.c	Fri Apr 05 00:09:54 2013 +0200
@@ -55,10 +55,8 @@
 
 int __init_%(location)s()
 {
+    __FirstTick = 1;
 %(init_entry_variables)s
-	*__IW%(location)s_0 = __MK_Alloc_AXIS_REF();
-	__CIA402Node_%(location)s.axis = __MK_GetPublic_AXIS_REF(*__IW%(location)s_0);
-	__CIA402Node_%(location)s.axis->NetworkPosition = %(slave_pos)d;
 	*(__CIA402Node_%(location)s.ModesOfOperation) = 0x08;
     return 0;
 }
@@ -69,13 +67,15 @@
 
 void __retrieve_%(location)s()
 {
-%(fieldbus_interface_definition)s
-
 	IEC_UINT statusword_inactive = *(__CIA402Node_%(location)s.StatusWord) & __InactiveMask;
 	IEC_UINT statusword_active = *(__CIA402Node_%(location)s.StatusWord) & __ActiveMask;
 
 	if (__FirstTick) {
+		*__IW%(location)s_0 = __MK_Alloc_AXIS_REF();
+		__CIA402Node_%(location)s.axis = __MK_GetPublic_AXIS_REF(*__IW%(location)s_0);
+		__CIA402Node_%(location)s.axis->NetworkPosition = %(slave_pos)d;
 %(init_axis_params)s
+%(fieldbus_interface_definition)s
 		__FirstTick = 0;
 	}