28 <xsd:complexType> |
28 <xsd:complexType> |
29 <xsd:attribute name="CAN_Device" type="xsd:string" use="required"/> |
29 <xsd:attribute name="CAN_Device" type="xsd:string" use="required"/> |
30 <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="required"/> |
30 <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="required"/> |
31 <xsd:attribute name="NodeId" type="xsd:string" use="required"/> |
31 <xsd:attribute name="NodeId" type="xsd:string" use="required"/> |
32 <xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/> |
32 <xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/> |
|
33 <xsd:attribute name="Sync_Align_Ratio" use="optional" default="50"> |
|
34 <xsd:simpleType> |
|
35 <xsd:restriction base="xsd:integer"> |
|
36 <xsd:minInclusive value="1"/> |
|
37 <xsd:maxInclusive value="99"/> |
|
38 </xsd:restriction> |
|
39 </xsd:simpleType> |
|
40 </xsd:attribute> |
33 </xsd:complexType> |
41 </xsd:complexType> |
34 </xsd:element> |
42 </xsd:element> |
35 </xsd:schema> |
43 </xsd:schema> |
36 """ |
44 """ |
37 |
45 |
101 return self.ChangesToSave or self.OneFileHasChanged() |
109 return self.ChangesToSave or self.OneFileHasChanged() |
102 |
110 |
103 def OnPlugSave(self): |
111 def OnPlugSave(self): |
104 return self.SaveCurrentInFile(self.GetSlaveODPath()) |
112 return self.SaveCurrentInFile(self.GetSlaveODPath()) |
105 |
113 |
106 def PlugGenerate_C(self, buildpath, locations, logger): |
114 def PlugGenerate_C(self, buildpath, locations): |
107 """ |
115 """ |
108 Generate C code |
116 Generate C code |
109 @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
117 @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
110 @param locations: List of complete variables locations \ |
118 @param locations: List of complete variables locations \ |
111 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
119 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
156 # TODO change netname when name change |
164 # TODO change netname when name change |
157 NodeList.__init__(self, manager, self.BaseParams.getName()) |
165 NodeList.__init__(self, manager, self.BaseParams.getName()) |
158 self.LoadProject(self.PlugPath()) |
166 self.LoadProject(self.PlugPath()) |
159 |
167 |
160 _View = None |
168 _View = None |
161 def _OpenView(self, logger): |
169 def _OpenView(self): |
162 if not self._View: |
170 if not self._View: |
163 def _onclose(): |
171 def _onclose(): |
164 self._View = None |
172 self._View = None |
165 def _onsave(): |
173 def _onsave(): |
166 self.GetPlugRoot().SaveProject() |
174 self.GetPlugRoot().SaveProject() |
169 self._View.SetBusId(self.GetCurrentLocation()) |
177 self._View.SetBusId(self.GetCurrentLocation()) |
170 self._View._onclose = _onclose |
178 self._View._onclose = _onclose |
171 self._View._onsave = _onsave |
179 self._View._onsave = _onsave |
172 self._View.Show() |
180 self._View.Show() |
173 |
181 |
174 def _ShowMasterGenerated(self, logger): |
182 def _ShowMasterGenerated(self): |
175 buildpath = self._getBuildPath() |
183 buildpath = self._getBuildPath() |
176 # Eventually create build dir |
184 # Eventually create build dir |
177 if not os.path.exists(buildpath): |
185 if not os.path.exists(buildpath): |
178 logger.write_error("Error: No PLC built\n") |
186 self.logger.write_error("Error: No PLC built\n") |
179 return |
187 return |
180 |
188 |
181 masterpath = os.path.join(buildpath, "MasterGenerated.od") |
189 masterpath = os.path.join(buildpath, "MasterGenerated.od") |
182 if not os.path.exists(masterpath): |
190 if not os.path.exists(masterpath): |
183 logger.write_error("Error: No Master generated\n") |
191 self.logger.write_error("Error: No Master generated\n") |
184 return |
192 return |
185 |
193 |
186 new_dialog = objdictedit(None, filesOpen=[masterpath]) |
194 new_dialog = objdictedit(None, filesOpen=[masterpath]) |
187 new_dialog.Show() |
195 new_dialog.Show() |
188 |
196 |
205 |
213 |
206 def OnPlugSave(self): |
214 def OnPlugSave(self): |
207 self.SetRoot(self.PlugPath()) |
215 self.SetRoot(self.PlugPath()) |
208 return self.SaveProject() is not None |
216 return self.SaveProject() is not None |
209 |
217 |
210 def PlugGenerate_C(self, buildpath, locations, logger): |
218 def PlugGenerate_C(self, buildpath, locations): |
211 """ |
219 """ |
212 Generate C code |
220 Generate C code |
213 @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
221 @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
214 @param locations: List of complete variables locations \ |
222 @param locations: List of complete variables locations \ |
215 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
223 [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
262 if DLL_LIST is not None: |
270 if DLL_LIST is not None: |
263 child["type"] = DLL_LIST |
271 child["type"] = DLL_LIST |
264 return infos |
272 return infos |
265 return infos |
273 return infos |
266 |
274 |
267 def PlugGenerate_C(self, buildpath, locations, logger): |
275 def PlugGenerate_C(self, buildpath, locations): |
268 |
276 |
269 format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), |
277 format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), |
270 "candriver" : self.CanFestivalInstance.getCAN_Driver(), |
278 "candriver" : self.CanFestivalInstance.getCAN_Driver(), |
271 "nodes_includes" : "", |
279 "nodes_includes" : "", |
272 "board_decls" : "", |
280 "board_decls" : "", |
326 format_dict["slavebootup_register"] += ( |
334 format_dict["slavebootup_register"] += ( |
327 "%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n"%(nodename,nodename)) |
335 "%s_Data.post_SlaveBootup = %s_post_SlaveBootup;\n"%(nodename,nodename)) |
328 else: |
336 else: |
329 # Slave node |
337 # Slave node |
330 align = child_data.getSync_Align() |
338 align = child_data.getSync_Align() |
|
339 align_ratio=child_data.getSync_Align_Ratio() |
331 if align > 0: |
340 if align > 0: |
332 format_dict["post_sync"] += ( |
341 format_dict["post_sync"] += ( |
333 "static int %s_CalCount = 0;\n"%(nodename)+ |
342 "static int %s_CalCount = 0;\n"%(nodename)+ |
334 "static void %s_post_sync(CO_Data* d){\n"%(nodename)+ |
343 "static void %s_post_sync(CO_Data* d){\n"%(nodename)+ |
335 " if(%s_CalCount < %d){\n"%(nodename, align)+ |
344 " if(%s_CalCount < %d){\n"%(nodename, align)+ |
336 " %s_CalCount++;\n"%(nodename)+ |
345 " %s_CalCount++;\n"%(nodename)+ |
337 " align_tick(1);\n"+ |
346 " align_tick(-1);\n"+ |
338 " }else{\n"+ |
347 " }else{\n"+ |
339 " align_tick(0);\n"+ |
348 " align_tick(%d);\n"%(align_ratio)+ |
340 " }\n"+ |
349 " }\n"+ |
341 "}\n") |
350 "}\n") |
342 format_dict["post_sync_register"] += ( |
351 format_dict["post_sync_register"] += ( |
343 "%s_Data.post_sync = %s_post_sync;\n"%(nodename,nodename)) |
352 "%s_Data.post_sync = %s_post_sync;\n"%(nodename,nodename)) |
344 format_dict["nodes_init"] += 'NODE_SLAVE_INIT(%s, %s)\n '%( |
353 format_dict["nodes_init"] += 'NODE_SLAVE_INIT(%s, %s)\n '%( |