etherlab/etherlab.py
changeset 2109 86832a0e113d
parent 2107 6f9aa410a997
child 2111 f2cffda17d00
equal deleted inserted replaced
2108:6bcfd50d5a47 2109:86832a0e113d
   172                  "location": self.GetFullIEC_Channel(),
   172                  "location": self.GetFullIEC_Channel(),
   173                  "children": self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName())
   173                  "children": self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName())
   174         }
   174         }
   175 
   175 
   176     def CTNGenerate_C(self, buildpath, locations):
   176     def CTNGenerate_C(self, buildpath, locations):
   177         """
       
   178         Generate C code
       
   179         @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
       
   180         @param locations: List of complete variables locations \
       
   181             [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
       
   182             "NAME" : name of the variable (generally "__IW0_1_2" style)
       
   183             "DIR" : direction "Q","I" or "M"
       
   184             "SIZE" : size "X", "B", "W", "D", "L"
       
   185             "LOC" : tuple of interger for IEC location (0,1,2,...)
       
   186             }, ...]
       
   187         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
       
   188         """
       
   189         return [],"",False
   177         return [],"",False
   190 
   178 
   191 #--------------------------------------------------
   179 #--------------------------------------------------
   192 #                 Ethercat CIA402 Node
   180 #                 Ethercat CIA402 Node
   193 #--------------------------------------------------
   181 #--------------------------------------------------
   313             dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
   301             dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
   314             dragSource.SetData(data)
   302             dragSource.SetData(data)
   315             dragSource.DoDragDrop()
   303             dragSource.DoDragDrop()
   316         
   304         
   317         def CTNGenerate_C(self, buildpath, locations):
   305         def CTNGenerate_C(self, buildpath, locations):
   318             """
       
   319             Generate C code
       
   320             @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
       
   321             @param locations: List of complete variables locations \
       
   322                 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
       
   323                 "NAME" : name of the variable (generally "__IW0_1_2" style)
       
   324                 "DIR" : direction "Q","I" or "M"
       
   325                 "SIZE" : size "X", "B", "W", "D", "L"
       
   326                 "LOC" : tuple of interger for IEC location (0,1,2,...)
       
   327                 }, ...]
       
   328             @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
       
   329             """
       
   330             current_location = self.GetCurrentLocation()
   306             current_location = self.GetCurrentLocation()
   331             
   307             
   332             location_str = "_".join(map(lambda x:str(x), current_location))
   308             location_str = "_".join(map(lambda x:str(x), current_location))
   333             
   309             
   334             plc_cia402node_filepath = os.path.join(os.path.split(__file__)[0], "plc_cia402node.c")
   310             plc_cia402node_filepath = os.path.join(os.path.split(__file__)[0], "plc_cia402node.c")
  1100          "tooltip" : _("Scan Network"),
  1076          "tooltip" : _("Scan Network"),
  1101          "method" : "_ScanNetwork"},
  1077          "method" : "_ScanNetwork"},
  1102     ]
  1078     ]
  1103 
  1079 
  1104     def CTNGenerate_C(self, buildpath, locations):
  1080     def CTNGenerate_C(self, buildpath, locations):
  1105         """
       
  1106         Generate C code
       
  1107         @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
       
  1108         @param locations: List of complete variables locations \
       
  1109             [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
       
  1110             "NAME" : name of the variable (generally "__IW0_1_2" style)
       
  1111             "DIR" : direction "Q","I" or "M"
       
  1112             "SIZE" : size "X", "B", "W", "D", "L"
       
  1113             "LOC" : tuple of interger for IEC location (0,1,2,...)
       
  1114             }, ...]
       
  1115         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
       
  1116         """
       
  1117         current_location = self.GetCurrentLocation()
  1081         current_location = self.GetCurrentLocation()
  1118         
  1082         
  1119         slaves = self.GetSlaves()
  1083         slaves = self.GetSlaves()
  1120         for slave_pos in slaves:
  1084         for slave_pos in slaves:
  1121             slave = self.GetSlave(slave_pos)
  1085             slave = self.GetSlave(slave_pos)
  1211 
  1175 
  1212 SLAVE_OUTPUT_PDO_DEFAULT_VALUE = """
  1176 SLAVE_OUTPUT_PDO_DEFAULT_VALUE = """
  1213     {
  1177     {
  1214         uint8_t value[%(data_size)d];
  1178         uint8_t value[%(data_size)d];
  1215         if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
  1179         if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
  1216             SLOGF(LOG_CRITICAL, "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);
  1180             SLOGF(LOG_CRITICAL, "Failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%ud\\n", abort_code);
  1217             return -1;
  1181             return -1;
  1218         }
  1182         }
  1219         %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
  1183         %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
  1220     }
  1184     }
  1221 """
  1185 """