branch | ethercat_from_kosmos |
changeset 2641 | c9deff128c37 |
parent 2165 | 02a2b5dee5e3 |
child 2643 | b98d9e08231f |
2192:09d5d1456616 | 2641:c9deff128c37 |
---|---|
8 # |
8 # |
9 # See COPYING file for copyrights details. |
9 # See COPYING file for copyrights details. |
10 |
10 |
11 import os |
11 import os |
12 import wx |
12 import wx |
13 |
13 import re |
14 mailbox_protocols = ["AoE", "EoE", "CoE", "FoE", "SoE", "VoE"] |
14 |
15 from lxml import objectify |
|
15 |
16 |
16 def ExtractHexDecValue(value): |
17 def ExtractHexDecValue(value): |
17 """ |
18 """ |
18 convert numerical value in string format into decimal or hex format. |
19 convert numerical value in string format into decimal or hex format. |
19 @param value : hex or decimal data |
20 @param value : hex or decimal data |
75 import commands |
76 import commands |
76 result = commands.getoutput("ethercat xml -p %d") |
77 result = commands.getoutput("ethercat xml -p %d") |
77 returnVal = result |
78 returnVal = result |
78 """ |
79 """ |
79 |
80 |
80 # ethercat sdos -p (slave position) |
81 # ethercat upload -p (slave position) -t (type) (index) (sub index) |
81 SLAVE_SDO = """ |
82 SDO_UPLOAD = """ |
82 import commands |
83 import commands |
83 result = commands.getoutput("ethercat sdos -p %d") |
84 sdo_data = [] |
84 returnVal =result |
85 input_data = "%s" |
85 """ |
86 slave_pos = %d |
86 |
87 command_string = "" |
87 # ethercat upload -p (slave position) (main index) (sub index) |
88 for sdo_token in input_data.split(","): |
88 GET_SLOW_SDO = """ |
89 if len(sdo_token) > 1: |
89 import commands |
90 sdo_token = sdo_token.strip() |
90 result = commands.getoutput("ethercat upload -p %d %s %s") |
91 type, idx, subidx = sdo_token.split(" ") |
91 returnVal =result |
92 command_string = "ethercat upload -p " + str(slave_pos) + " -t " + type + " " + idx + " " + subidx |
93 result = commands.getoutput(command_string) |
|
94 sdo_data.append(result) |
|
95 returnVal =sdo_data |
|
92 """ |
96 """ |
93 |
97 |
94 # ethercat download -p (slave position) (main index) (sub index) (value) |
98 # ethercat download -p (slave position) (main index) (sub index) (value) |
95 SDO_DOWNLOAD = """ |
99 SDO_DOWNLOAD = """ |
96 import commands |
100 import commands |
108 # ethercat reg_read -p (slave position) (address) (size) |
112 # ethercat reg_read -p (slave position) (address) (size) |
109 REG_READ = """ |
113 REG_READ = """ |
110 import commands |
114 import commands |
111 result = commands.getoutput("ethercat reg_read -p %d %s %s") |
115 result = commands.getoutput("ethercat reg_read -p %d %s %s") |
112 returnVal =result |
116 returnVal =result |
117 """ |
|
118 |
|
119 # ethercat reg_read -p (slave position) (address) (size) |
|
120 MULTI_REG_READ = """ |
|
121 import commands |
|
122 output = [] |
|
123 addr, size = range(2) |
|
124 slave_num = %d |
|
125 reg_info_str = "%s" |
|
126 reg_info_list = reg_info_str.split("|") |
|
127 for slave_idx in range(slave_num): |
|
128 for reg_info in reg_info_list: |
|
129 param = reg_info.split(",") |
|
130 result = commands.getoutput("ethercat reg_read -p " |
|
131 + str(slave_idx) + " " |
|
132 + param[addr] + " " |
|
133 + param[size]) |
|
134 output.append(str(slave_idx) + "," + param[addr] + "," + result) |
|
135 returnVal = output |
|
113 """ |
136 """ |
114 |
137 |
115 # ethercat sii_write -p (slave position) - (contents) |
138 # ethercat sii_write -p (slave position) - (contents) |
116 SII_WRITE = """ |
139 SII_WRITE = """ |
117 import subprocess |
140 import subprocess |
134 import commands |
157 import commands |
135 result = commands.getoutput("ethercat rescan -p %d") |
158 result = commands.getoutput("ethercat rescan -p %d") |
136 returnVal =result |
159 returnVal =result |
137 """ |
160 """ |
138 |
161 |
162 # ethercat pdos |
|
163 PDOS = """ |
|
164 import commands |
|
165 result = commands.getoutput("ethercat pdos -p 0") |
|
166 returnVal =result |
|
167 """ |
|
168 |
|
139 #-------------------------------------------------- |
169 #-------------------------------------------------- |
140 # Common Method For EtherCAT Management |
170 # Common Method For EtherCAT Management |
141 #-------------------------------------------------- |
171 #-------------------------------------------------- |
142 class _CommonSlave: |
172 class _CommonSlave: |
143 |
173 |
144 # ----- Data Structure for ethercat management ---- |
174 # ----- Data Structure for ethercat management ---- |
145 SlaveState = "" |
175 SlaveState = "" |
146 |
176 |
177 # SDO base data type for Ethercatmaster |
|
178 BaseDataTypes = { |
|
179 "bool": ["BOOLEAN", "BOOL", "BIT"], |
|
180 "uint8": ["BYTE", "USINT", "BIT1", "BIT2", "BIT3", "BIT4", "BIT5", "BIT6", |
|
181 "BIT7", "BIT8", "BITARR8", "UNSIGNED8"], |
|
182 "uint16": ["BITARR16", "UNSIGNED16", "UINT"], |
|
183 "uint32": ["BITARR32", "UNSIGNED24", "UINT24", "UNSIGNED32", "UDINT"], |
|
184 "uint64": ["UNSINED40", "UINT40", "UNSIGNED48", "UINT48", "UNSIGNED56", |
|
185 "UINT56", "UNSIGNED64", "ULINT"], |
|
186 "int8": ["INTEGER8", "SINT"], |
|
187 "int16": ["INTEGER16", "INT"], |
|
188 "int32": ["INTEGER24", "INT24", "INTEGER32", "DINT"], |
|
189 "int64": ["INTEGER40", "INT40", "INTEGER48", "INT48", "INTEGER56", "INT56", |
|
190 "INTEGER64", "LINT"], |
|
191 "float": ["REAL", "REAL32"], |
|
192 "double": ["LREAL", "REAL64"], |
|
193 "string": ["VISUBLE_STRING", "STRING(n)"], |
|
194 "octet_string": ["OCTET_STRING"], |
|
195 "unicode_string": ["UNICODE_STRING"] |
|
196 } |
|
197 |
|
147 # category of SDO data |
198 # category of SDO data |
148 DatatypeDescription, CommunicationObject, ManufacturerSpecific, \ |
199 DatatypeDescription, CommunicationObject, ManufacturerSpecific, \ |
149 ProfileSpecific, Reserved, AllSDOData = range(6) |
200 ProfileSpecific, Reserved, AllSDOData = range(6) |
150 |
201 |
151 # store the execution result of "ethercat sdos" command into SaveSDOData. |
202 # SDO data informations: index, sub-index, type, bit size, category-name |
152 SaveSDOData = [] |
203 SDOVariables = [] |
204 SDOSubEntryData = [] |
|
205 |
|
206 # defalut value of SDO data in XML |
|
207 # Not Used |
|
208 DefaultValueDic = {} |
|
153 |
209 |
154 # Flags for checking "write" permission of OD entries |
210 # Flags for checking "write" permission of OD entries |
155 CheckPREOP = False |
211 CheckPREOP = False |
156 CheckSAFEOP = False |
212 CheckSAFEOP = False |
157 CheckOP = False |
213 CheckOP = False |
178 @param controler: _EthercatSlaveCTN class in EthercatSlave.py |
234 @param controler: _EthercatSlaveCTN class in EthercatSlave.py |
179 """ |
235 """ |
180 self.Controler = controler |
236 self.Controler = controler |
181 |
237 |
182 self.ClearSDODataSet() |
238 self.ClearSDODataSet() |
183 |
239 |
184 #------------------------------------------------------------------------------- |
240 #------------------------------------------------------------------------------- |
185 # Used Master State |
241 # Used Master State |
186 #------------------------------------------------------------------------------- |
242 #------------------------------------------------------------------------------- |
187 def GetMasterState(self): |
243 def GetMasterState(self): |
188 """ |
244 """ |
189 Execute "ethercat master" command and parse the execution result |
245 Execute "ethercat master" command and parse the execution result |
190 @return MasterState |
246 @return MasterState |
191 """ |
247 """ |
192 |
|
193 # exectute "ethercat master" command |
248 # exectute "ethercat master" command |
194 error, return_val = self.Controler.RemoteExec(MASTER_STATE, return_val = None) |
249 error, return_val = self.Controler.RemoteExec(MASTER_STATE, return_val = None) |
195 master_state = {} |
250 master_state = {} |
196 # parse the reslut |
251 # parse the reslut |
197 for each_line in return_val.splitlines(): |
252 for each_line in return_val.splitlines(): |
224 (self.SlaveState) for "Slave State" |
279 (self.SlaveState) for "Slave State" |
225 return_val example : 0 0:0 PREOP + EL9800 (V4.30) (PIC24, SPI, ET1100) |
280 return_val example : 0 0:0 PREOP + EL9800 (V4.30) (PIC24, SPI, ET1100) |
226 """ |
281 """ |
227 error, return_val = self.Controler.RemoteExec(GET_SLAVE, return_val = None) |
282 error, return_val = self.Controler.RemoteExec(GET_SLAVE, return_val = None) |
228 self.SlaveState = return_val |
283 self.SlaveState = return_val |
229 return return_val |
284 return return_val |
230 |
285 |
231 #------------------------------------------------------------------------------- |
286 #------------------------------------------------------------------------------- |
232 # Used SDO Management |
287 # Used SDO Management |
233 #------------------------------------------------------------------------------- |
288 #------------------------------------------------------------------------------- |
234 def GetSlaveSDOFromSlave(self): |
|
235 """ |
|
236 Get SDO objects information of current slave using "ethercat sdos -p %d" command. |
|
237 Command example : "ethercat sdos -p 0" |
|
238 @return return_val : execution results of "ethercat sdos" command (need to be parsed later) |
|
239 """ |
|
240 error, return_val = self.Controler.RemoteExec(SLAVE_SDO%(self.Controler.GetSlavePos()), return_val = None) |
|
241 return return_val |
|
242 |
|
243 def SDODownload(self, data_type, idx, sub_idx, value): |
289 def SDODownload(self, data_type, idx, sub_idx, value): |
244 """ |
290 """ |
245 Set an SDO object value to user-specified value using "ethercat download" command. |
291 Set an SDO object value to user-specified value using "ethercat download" command. |
246 Command example : "ethercat download --type int32 -p 0 0x8020 0x12 0x00000000" |
292 Command example : "ethercat download --type int32 -p 0 0x8020 0x12 0x00000000" |
247 @param data_type : data type of SDO entry |
293 @param data_type : data type of SDO entry |
248 @param idx : index of the SDO entry |
294 @param idx : index of the SDO entry |
249 @param sub_idx : subindex of the SDO entry |
295 @param sub_idx : subindex of the SDO entry |
250 @param value : value of SDO entry |
296 @param value : value of SDO entry |
251 """ |
297 """ |
252 error, return_val = self.Controler.RemoteExec(SDO_DOWNLOAD%(data_type, self.Controler.GetSlavePos(), idx, sub_idx, value), return_val = None) |
298 valid_type = self.GetValidDataType(data_type) |
299 error, return_val = self.Controler.RemoteExec(SDO_DOWNLOAD%(valid_type, self.Controler.GetSlavePos(), idx, sub_idx, value), return_val = None) |
|
300 |
|
301 return return_val |
|
253 |
302 |
254 def BackupSDODataSet(self): |
303 def BackupSDODataSet(self): |
255 """ |
304 """ |
256 Back-up current SDO entry information to restore the SDO data |
305 Back-up current SDO entry information to restore the SDO data |
257 in case that the user cancels SDO update operation. |
306 in case that the user cancels SDO update operation. |
266 def ClearSDODataSet(self): |
315 def ClearSDODataSet(self): |
267 """ |
316 """ |
268 Clear the specified SDO entry information. |
317 Clear the specified SDO entry information. |
269 """ |
318 """ |
270 for count in range(6): |
319 for count in range(6): |
271 self.SaveSDOData.append([]) |
320 self.SDOVariables.append([]) |
272 |
321 |
322 def GetAllSDOValuesFromSlave(self): |
|
323 """ |
|
324 Get SDO values of All SDO entries. |
|
325 @return return_val: list of result of "SDO_UPLOAD" |
|
326 """ |
|
327 entry_infos = "" |
|
328 alldata_idx = len(self.SDOVariables) |
|
329 counter = 0 |
|
330 for category in self.SDOVariables: |
|
331 counter +=1 |
|
332 # for avoid redundant repetition |
|
333 if counter == alldata_idx: |
|
334 continue |
|
335 |
|
336 for entry in category: |
|
337 valid_type = self.GetValidDataType(entry["type"]) |
|
338 for_command_string = "%s %s %s ," % \ |
|
339 (valid_type, entry["idx"], entry["subIdx"]) |
|
340 entry_infos += for_command_string |
|
341 |
|
342 error, return_val = self.Controler.RemoteExec(SDO_UPLOAD%(entry_infos, self.Controler.GetSlavePos()), return_val = None) |
|
343 |
|
344 return return_val |
|
345 |
|
346 def GetSDOValuesFromSlave(self, entries_info): |
|
347 """ |
|
348 Get SDO values of some SDO entries. |
|
349 @param entries_info: dictionary of SDO entries that is wanted to know the value. |
|
350 @return return_val: list of result of "SDO_UPLOAD" |
|
351 """ |
|
352 entry_infos = "" |
|
353 |
|
354 entries_info_list = entries_info.items() |
|
355 entries_info_list.sort() |
|
356 |
|
357 for (idx, subIdx), entry in entries_info_list: |
|
358 valid_type = self.GetValidDataType(entry["type"]) |
|
359 for_command_string = "%s %s %s ," % \ |
|
360 (valid_type, str(idx), str(subIdx)) |
|
361 entry_infos += for_command_string |
|
362 |
|
363 error, return_val = self.Controler.RemoteExec(SDO_UPLOAD%(entry_infos, self.Controler.GetSlavePos()), return_val = None) |
|
364 |
|
365 return return_val |
|
366 |
|
367 def ExtractObjects(self): |
|
368 """ |
|
369 Extract object type items from imported ESI xml. |
|
370 And they are stuctured as dictionary. |
|
371 @return objects: dictionary of objects |
|
372 """ |
|
373 objects = {} |
|
374 |
|
375 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
|
376 type_infos = slave.getType() |
|
377 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
|
378 |
|
379 if device is not None : |
|
380 for dictionary in device.GetProfileDictionaries(): |
|
381 dictionary.load() |
|
382 for object in dictionary.getObjects().getObject(): |
|
383 object_index = ExtractHexDecValue(object.getIndex().getcontent()) |
|
384 objects[(object_index)] = object |
|
385 |
|
386 return objects |
|
387 |
|
388 def ExtractAllDataTypes(self): |
|
389 """ |
|
390 Extract all data types from imported ESI xml. |
|
391 @return dataTypes: dictionary of datatypes |
|
392 """ |
|
393 dataTypes = {} |
|
394 |
|
395 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
|
396 type_infos = slave.getType() |
|
397 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
|
398 |
|
399 for dictionary in device.GetProfileDictionaries(): |
|
400 dictionary.load() |
|
401 |
|
402 datatypes = dictionary.getDataTypes() |
|
403 if datatypes is not None: |
|
404 |
|
405 for datatype in datatypes.getDataType(): |
|
406 dataTypes[datatype.getName()] = datatype |
|
407 return dataTypes |
|
408 |
|
409 def IsBaseDataType(self, datatype): |
|
410 """ |
|
411 Check if the datatype is a base data type. |
|
412 @return baseTypeFlag: true if datatype is a base data type, unless false |
|
413 """ |
|
414 baseTypeFlag = False |
|
415 for baseDataTypeList in self.BaseDataTypes.values(): |
|
416 if datatype in baseDataTypeList: |
|
417 baseTypeFlag = True |
|
418 break |
|
419 return baseTypeFlag |
|
420 |
|
421 def GetBaseDataType(self, datatype): |
|
422 """ |
|
423 Get a base data type corresponding the datatype. |
|
424 @param datatype: Some data type (string format) |
|
425 @return base data type |
|
426 """ |
|
427 if self.IsBaseDataType(datatype): |
|
428 return datatype |
|
429 elif not datatype.find("STRING") == -1: |
|
430 return datatype |
|
431 else: |
|
432 datatypes = self.ExtractAllDataTypes() |
|
433 base_datatype = datatypes[datatype].getBaseType() |
|
434 return self.GetBaseDataType(base_datatype) |
|
435 |
|
436 def GetValidDataType(self, datatype): |
|
437 """ |
|
438 Convert the datatype into a data type that is possible to download/upload |
|
439 in etherlab master stack. |
|
440 @param datatype: Some data type (string format) |
|
441 @return base_type: vaild data type |
|
442 """ |
|
443 base_type = self.GetBaseDataType(datatype) |
|
444 |
|
445 if re.match("STRING\([0-9]*\)", datatype) is not None: |
|
446 return "string" |
|
447 else: |
|
448 for key, value in self.BaseDataTypes.items(): |
|
449 if base_type in value: |
|
450 return key |
|
451 return base_type |
|
452 |
|
453 # Not Used |
|
454 def GetAllEntriesList(self): |
|
455 """ |
|
456 Get All entries information that includes index, sub-index, name, |
|
457 type, bit size, PDO mapping, and default value. |
|
458 @return self.entries: dictionary of entry |
|
459 """ |
|
460 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
|
461 type_infos = slave.getType() |
|
462 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
|
463 self.entries = device.GetEntriesList() |
|
464 datatypes = self.ExtractAllDataTypes() |
|
465 objects = self.ExtractObjects() |
|
466 entries_list = self.entries.items() |
|
467 entries_list.sort() |
|
468 |
|
469 # append sub entries |
|
470 for (index, subidx), entry in entries_list: |
|
471 # entry_* is string type |
|
472 entry_type = entry["Type"] |
|
473 entry_index = entry["Index"] |
|
474 |
|
475 try: |
|
476 object_info = objects[index].getInfo() |
|
477 except: |
|
478 continue |
|
479 |
|
480 if object_info is not None: |
|
481 obj_content = object_info.getcontent() |
|
482 |
|
483 typeinfo = datatypes.get(entry_type, None) |
|
484 bitsize = typeinfo.getBitSize() |
|
485 type_content = typeinfo.getcontent() |
|
486 |
|
487 # ArrayInfo type |
|
488 if type_content is not None and type_content["name"] == "ArrayInfo": |
|
489 for arrayinfo in type_content["value"]: |
|
490 element_num = arrayinfo.getElements() |
|
491 first_subidx = arrayinfo.getLBound() |
|
492 for offset in range(element_num): |
|
493 new_subidx = int(first_subidx) + offset |
|
494 entry_subidx = hex(new_subidx) |
|
495 if obj_content["value"][new_subidx]["name"] == "SubItem": |
|
496 subitem = obj_content["value"][new_subidx]["value"] |
|
497 subname = subitem[new_subidx].getName() |
|
498 if subname is not None: |
|
499 entry_name = "%s - %s" % \ |
|
500 (ExtractName(objects[index].getName()), subname) |
|
501 else: |
|
502 entry_name = ExtractName(objects[index].getName()) |
|
503 self.entries[(index, new_subidx)] = { |
|
504 "Index": entry_index, |
|
505 "SubIndex": entry_subidx, |
|
506 "Name": entry_name, |
|
507 "Type": typeinfo.getBaseType(), |
|
508 "BitSize": str(bitsize/element_num), |
|
509 "Access": entry["Access"], |
|
510 "PDOMapping": entry["PDOMapping"]} |
|
511 try: |
|
512 value_info = subitem[new_subidx].getInfo().getcontent()\ |
|
513 ["value"][0]["value"][0] |
|
514 self.AppendDefaultValue(index, new_subidx, value_info) |
|
515 except: |
|
516 pass |
|
517 |
|
518 try: |
|
519 value_info = subitem[subidx].getInfo().getcontent()\ |
|
520 ["value"][0]["value"][0] |
|
521 self.AppendDefaultValue(index, subidx, value_info) |
|
522 except: |
|
523 pass |
|
524 |
|
525 # EnumInfo type |
|
526 elif type_content is not None and type_content["name"] == "EnumInfo": |
|
527 self.entries[(index, subidx)]["EnumInfo"] = {} |
|
528 |
|
529 for enuminfo in type_content["value"]: |
|
530 text = enuminfo.getText() |
|
531 enum = enuminfo.getEnum() |
|
532 self.entries[(index, subidx)]["EnumInfo"][str(enum)] = text |
|
533 |
|
534 self.entries[(index, subidx)]["DefaultValue"] = "0x00" |
|
535 |
|
536 # another types |
|
537 else: |
|
538 if subidx == 0x00: |
|
539 tmp_subidx = 0x00 |
|
540 |
|
541 try: |
|
542 if obj_content["value"][tmp_subidx]["name"] == "SubItem": |
|
543 sub_name = entry["Name"].split(" - ")[1] |
|
544 for num in range(len(obj_content["value"])): |
|
545 if sub_name == \ |
|
546 obj_content["value"][num]["value"][num].getName(): |
|
547 subitem_content = obj_content["value"][tmp_subidx]\ |
|
548 ["value"][tmp_subidx] |
|
549 value_info = subitem_content.getInfo().getcontent()\ |
|
550 ["value"][0]["value"][0] |
|
551 tmp_subidx += 1 |
|
552 break |
|
553 else: |
|
554 value_info = None |
|
555 |
|
556 else: |
|
557 value_info = \ |
|
558 obj_content["value"][tmp_subidx]["value"][tmp_subidx] |
|
559 |
|
560 self.AppendDefaultValue(index, subidx, value_info) |
|
561 |
|
562 except: |
|
563 pass |
|
564 |
|
565 return self.entries |
|
566 |
|
567 # Not Used |
|
568 def AppendDefaultValue(self, index, subidx, value_info=None): |
|
569 """ |
|
570 Get the default value from the ESI xml |
|
571 @param index: entry index |
|
572 @param subidx: entry sub index |
|
573 @param value_info: dictionary of infomation about default value |
|
574 |
|
575 """ |
|
576 # there is not default value. |
|
577 if value_info == None: |
|
578 return |
|
579 |
|
580 raw_value = value_info["value"] |
|
581 |
|
582 # default value is hex binary type. |
|
583 if value_info["name"] == "DefaultData": |
|
584 raw_value_bit = list(hex(raw_value).split("0x")[1]) |
|
585 |
|
586 datatype = self.GetValidDataType(self.entries[(index, subidx)]["Type"]) |
|
587 if datatype is "string" or datatype is "octet_string": |
|
588 |
|
589 if "L" in raw_value_bit: |
|
590 raw_value_bit.remove("L") |
|
591 |
|
592 default_value = "".join(raw_value_bit).decode("hex") |
|
593 |
|
594 elif datatype is "unicode_string": |
|
595 default_value = "".join(raw_value_bit).decode("hex").\ |
|
596 decode("utf-8") |
|
597 |
|
598 else: |
|
599 bit_num = len(raw_value_bit) |
|
600 # padding |
|
601 if not bit_num%2 == 0: |
|
602 raw_value_bit.insert(0, "0") |
|
603 |
|
604 default_value_bit = [] |
|
605 |
|
606 # little endian -> big endian |
|
607 for num in range(bit_num): |
|
608 if num%2 == 0: |
|
609 default_value_bit.insert(0, raw_value_bit[num]) |
|
610 default_value_bit.insert(1, raw_value_bit[num+1]) |
|
611 |
|
612 default_value = "0x%s" % "".join(default_value_bit) |
|
613 |
|
614 # default value is string type. |
|
615 # this case is not tested yet. |
|
616 elif value_info["name"] == "DefaultString": |
|
617 default_value = raw_value |
|
618 |
|
619 # default value is Hex or Dec type. |
|
620 elif value_info["name"] == "DefaultValue": |
|
621 default_value = "0x" + hex(ExtractHexDecValue(raw_value)) |
|
622 |
|
623 self.entries[(index, subidx)]["DefaultValue"] = default_value |
|
624 |
|
273 #------------------------------------------------------------------------------- |
625 #------------------------------------------------------------------------------- |
274 # Used PDO Monitoring |
626 # Used PDO Monitoring |
275 #------------------------------------------------------------------------------- |
627 #------------------------------------------------------------------------------- |
276 def RequestPDOInfo(self): |
628 def RequestPDOInfo(self): |
277 """ |
629 """ |
278 Load slave information from RootClass (XML data) and parse the information (calling SlavePDOData() method). |
630 Load slave information from RootClass (XML data) and parse the information |
631 (calling SlavePDOData() method). |
|
279 """ |
632 """ |
280 # Load slave information from ESI XML file (def EthercatMaster.py) |
633 # Load slave information from ESI XML file (def EthercatMaster.py) |
281 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
634 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
282 |
635 |
283 type_infos = slave.getType() |
636 type_infos = slave.getType() |
290 self.SavePDOData(device) |
643 self.SavePDOData(device) |
291 |
644 |
292 def SavePDOData(self, device): |
645 def SavePDOData(self, device): |
293 """ |
646 """ |
294 Parse PDO data and store the results in TXPDOCategory and RXPDOCategory |
647 Parse PDO data and store the results in TXPDOCategory and RXPDOCategory |
295 Tx(Rx)PDOCategory : index, name, entry number |
648 Tx(Rx)PDOCategory : index, name, entry number, exclude list, Sm |
296 Tx(Rx)Info : entry index, sub index, name, length, type |
649 Tx(Rx)Info : entry index, sub index, name, length, type |
297 @param device : Slave information extracted from ESI XML file |
650 @param device : Slave information extracted from ESI XML file |
298 """ |
651 """ |
299 # Parsing TXPDO entries |
652 # Parsing TXPDO entries |
300 for pdo, pdo_info in ([(pdo, "Inputs") for pdo in device.getTxPdo()]): |
653 for pdo, pdo_info in ([(pdo, "Inputs") for pdo in device.getTxPdo()]): |
301 # Save pdo_index, entry, and name of each entry |
654 # Save pdo_index, entry, and name of each entry |
302 pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent()) |
655 pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent()) |
303 entries = pdo.getEntry() |
656 entries = pdo.getEntry() |
304 pdo_name = ExtractName(pdo.getName()) |
657 pdo_name = ExtractName(pdo.getName()) |
305 |
658 excludes = pdo.getExclude() |
659 exclude_list = [] |
|
660 Sm = pdo.getSm() |
|
661 |
|
662 if excludes : |
|
663 for exclude in excludes: |
|
664 exclude_list.append(ExtractHexDecValue(exclude.getcontent())) |
|
665 |
|
306 # Initialize entry number count |
666 # Initialize entry number count |
307 count = 0 |
667 count = 0 |
308 |
668 |
309 # Parse entries |
669 # Parse entries |
310 for entry in entries: |
670 for entry in entries: |
311 # Save index and subindex |
671 # Save index and subindex |
312 index = ExtractHexDecValue(entry.getIndex().getcontent()) |
672 index = ExtractHexDecValue(entry.getIndex().getcontent()) |
313 subindex = ExtractHexDecValue(entry.getSubIndex()) |
673 subindex = ExtractHexDecValue(entry.getSubIndex()) |
315 if ExtractName(entry.getName()) is not None : |
675 if ExtractName(entry.getName()) is not None : |
316 entry_infos = { |
676 entry_infos = { |
317 "entry_index" : index, |
677 "entry_index" : index, |
318 "subindex" : subindex, |
678 "subindex" : subindex, |
319 "name" : ExtractName(entry.getName()), |
679 "name" : ExtractName(entry.getName()), |
320 "bitlen" : entry.getBitLen(), |
680 "bitlen" : entry.getBitLen()} |
321 "type" : entry.getDataType().getcontent() |
681 if entry.getDataType() is not None: |
322 } |
682 entry_infos["type"] = entry.getDataType().getcontent() |
323 self.TxPDOInfo.append(entry_infos) |
683 self.TxPDOInfo.append(entry_infos) |
324 count += 1 |
684 count += 1 |
325 |
685 |
326 categorys = {"pdo_index" : pdo_index, "name" : pdo_name, "number_of_entry" : count} |
686 categorys = {"pdo_index" : pdo_index, "name" : pdo_name, "sm" : Sm, |
687 "number_of_entry" : count, "exclude_list" : exclude_list} |
|
327 self.TxPDOCategory.append(categorys) |
688 self.TxPDOCategory.append(categorys) |
328 |
689 |
329 # Parsing RxPDO entries |
690 # Parsing RxPDO entries |
330 for pdo, pdo_info in ([(pdo, "Outputs") for pdo in device.getRxPdo()]): |
691 for pdo, pdo_info in ([(pdo, "Outputs") for pdo in device.getRxPdo()]): |
331 # Save pdo_index, entry, and name of each entry |
692 # Save pdo_index, entry, and name of each entry |
332 pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent()) |
693 pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent()) |
333 entries = pdo.getEntry() |
694 entries = pdo.getEntry() |
334 pdo_name = ExtractName(pdo.getName()) |
695 pdo_name = ExtractName(pdo.getName()) |
335 |
696 excludes = pdo.getExclude() |
697 exclude_list = [] |
|
698 Sm = pdo.getSm() |
|
699 |
|
700 if excludes : |
|
701 for exclude in excludes: |
|
702 exclude_list.append(ExtractHexDecValue(exclude.getcontent())) |
|
703 |
|
336 # Initialize entry number count |
704 # Initialize entry number count |
337 count = 0 |
705 count = 0 |
338 |
706 |
339 # Parse entries |
707 # Parse entries |
340 for entry in entries: |
708 for entry in entries: |
345 if ExtractName(entry.getName()) is not None : |
713 if ExtractName(entry.getName()) is not None : |
346 entry_infos = { |
714 entry_infos = { |
347 "entry_index" : index, |
715 "entry_index" : index, |
348 "subindex" : subindex, |
716 "subindex" : subindex, |
349 "name" : ExtractName(entry.getName()), |
717 "name" : ExtractName(entry.getName()), |
350 "bitlen" : str(entry.getBitLen()), |
718 "bitlen" : entry.getBitLen()} |
351 "type" : entry.getDataType().getcontent() |
719 if entry.getDataType() is not None: |
352 } |
720 entry_infos["type"] = entry.getDataType().getcontent() |
353 self.RxPDOInfo.append(entry_infos) |
721 self.RxPDOInfo.append(entry_infos) |
354 count += 1 |
722 count += 1 |
355 |
723 |
356 categorys = {"pdo_index" : pdo_index, "name" : pdo_name, "number_of_entry" : count} |
724 categorys = {"pdo_index" : pdo_index, "name" : pdo_name, "sm" : Sm, |
725 "number_of_entry" : count, "exclude_list" : exclude_list} |
|
357 self.RxPDOCategory.append(categorys) |
726 self.RxPDOCategory.append(categorys) |
358 |
727 |
359 def GetTxPDOCategory(self): |
728 def GetTxPDOCategory(self): |
360 """ |
729 """ |
361 Get TxPDOCategory data structure (Meta informaton of TxPDO). |
730 Get TxPDOCategory data structure (Meta informaton of TxPDO). |
390 |
759 |
391 def ClearDataSet(self): |
760 def ClearDataSet(self): |
392 """ |
761 """ |
393 Initialize PDO management data structure. |
762 Initialize PDO management data structure. |
394 """ |
763 """ |
395 self.TxPDOInfos = [] |
764 self.TxPDOInfo = [] |
396 self.TxPDOCategorys = [] |
765 self.TxPDOCategory = [] |
397 self.RxPDOInfos = [] |
766 self.RxPDOInfo = [] |
398 self.RxPDOCategorys = [] |
767 self.RxPDOCategory = [] |
399 |
768 |
400 #------------------------------------------------------------------------------- |
769 #------------------------------------------------------------------------------- |
401 # Used EEPROM Management |
770 # Used EEPROM Management |
402 #------------------------------------------------------------------------------- |
771 #------------------------------------------------------------------------------- |
403 # Base data types in ETG2000; format = {"Name": "BitSize"} |
772 # Base data types in ETG2000; format = {"Name": "BitSize"} |
458 |
827 |
459 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
828 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
460 type_infos = slave.getType() |
829 type_infos = slave.getType() |
461 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
830 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
462 |
831 |
832 #from decimal import Decimal |
|
833 |
|
463 # 'device' represents current slave device selected by user |
834 # 'device' represents current slave device selected by user |
464 if device is not None: |
835 if device is not None: |
465 for eeprom_element in device.getEeprom().getcontent(): |
836 # dir() method print available method list |
837 #print dir(device.getEeprom().getchildren()[1]) |
|
838 |
|
839 # success get subitem second object |
|
840 #print objectify.fromstring(device.getEeprom().getchildren()[1].tostring()).text |
|
841 |
|
842 for eeprom_element in device.getEeprom().getchildren(): |
|
466 # get EEPROM size; <Device>-<Eeprom>-<ByteSize> |
843 # get EEPROM size; <Device>-<Eeprom>-<ByteSize> |
467 if eeprom_element["name"] == "ByteSize": |
844 if eeprom_element.tag == "ByteSize": |
468 smartview_infos["eeprom_size"] = eeprom_element |
845 smartview_infos["eeprom_size"] = objectify.fromstring(eeprom_element.tostring()).text |
469 |
846 |
470 elif eeprom_element["name"] == "ConfigData": |
847 elif eeprom_element.tag == "ConfigData": |
471 configData_data = self.DecimalToHex(eeprom_element) |
848 # ConfigData Field Datatype??? |
849 #print type(objectify.fromstring(eeprom_element.tostring()).text) |
|
850 configData_data = self.DecimalToHex(objectify.fromstring(eeprom_element.tostring()).text) |
|
472 # get PDI type; <Device>-<Eeprom>-<ConfigData> address 0x00 |
851 # get PDI type; <Device>-<Eeprom>-<ConfigData> address 0x00 |
473 smartview_infos["pdi_type"] = int(configData_data[0:2], 16) |
852 smartview_infos["pdi_type"] = int(configData_data[0:2], 16) |
474 # get state of device emulation; <Device>-<Eeprom>-<ConfigData> address 0x01 |
853 # get state of device emulation; <Device>-<Eeprom>-<ConfigData> address 0x01 |
475 if "{:0>8b}".format(int(configData_data[2:4], 16))[7] == '1': |
854 if len(configData_data) > 3 and "{:0>8b}".format(int(configData_data[2:4], 16))[7] == '1': |
476 smartview_infos["device_emulation"] = "True" |
855 smartview_infos["device_emulation"] = "True" |
477 |
856 |
478 elif eeprom_element["name"] == "BootStrap": |
857 elif eeprom_element.tag == "BootStrap": |
479 bootstrap_data = "{:0>16x}".format(eeprom_element) |
858 bootstrap_data = "{:0>16x}".format(int(objectify.fromstring(eeprom_element.tostring()).text, 16)) |
480 # get bootstrap configuration; <Device>-<Eeprom>-<BootStrap> |
859 # get bootstrap configuration; <Device>-<Eeprom>-<BootStrap> |
481 for cfg, iter in [("mailbox_bootstrapconf_outstart", 0), |
860 for cfg, iter in [("mailbox_bootstrapconf_outstart", 0), |
482 ("mailbox_bootstrapconf_outlength", 1), |
861 ("mailbox_bootstrapconf_outlength", 1), |
483 ("mailbox_bootstrapconf_instart", 2), |
862 ("mailbox_bootstrapconf_instart", 2), |
484 ("mailbox_bootstrapconf_inlength", 3)]: |
863 ("mailbox_bootstrapconf_inlength", 3)]: |
485 smartview_infos[cfg] = str(int(bootstrap_data[4*iter+2:4*(iter+1)]+bootstrap_data[4*iter:4*iter+2], 16)) |
864 smartview_infos[cfg] = str(int(bootstrap_data[4*iter+2:4*(iter+1)]+bootstrap_data[4*iter:4*iter+2], 16)) |
486 |
865 |
866 """ |
|
867 for eeprom_element in device.getEeprom().getcontent()["value"]: |
|
868 # get EEPROM size; <Device>-<Eeprom>-<ByteSize> |
|
869 if eeprom_element["name"] == "ByteSize": |
|
870 smartview_infos["eeprom_size"] = eeprom_element["value"] |
|
871 |
|
872 elif eeprom_element["name"] == "ConfigData": |
|
873 configData_data = self.DecimalToHex(eeprom_element["value"]) |
|
874 # get PDI type; <Device>-<Eeprom>-<ConfigData> address 0x00 |
|
875 smartview_infos["pdi_type"] = int(configData_data[0:2], 16) |
|
876 # get state of device emulation; <Device>-<Eeprom>-<ConfigData> address 0x01 |
|
877 if "{:0>8b}".format(int(configData_data[2:4], 16))[7] == '1': |
|
878 smartview_infos["device_emulation"] = "True" |
|
879 |
|
880 elif eeprom_element["name"] == "BootStrap": |
|
881 bootstrap_data = "{:0>16x}".format(eeprom_element["value"]) |
|
882 # get bootstrap configuration; <Device>-<Eeprom>-<BootStrap> |
|
883 for cfg, iter in [("mailbox_bootstrapconf_outstart", 0), |
|
884 ("mailbox_bootstrapconf_outlength", 1), |
|
885 ("mailbox_bootstrapconf_instart", 2), |
|
886 ("mailbox_bootstrapconf_inlength", 3)]: |
|
887 smartview_infos[cfg] = str(int(bootstrap_data[4*iter+2:4*(iter+1)]+bootstrap_data[4*iter:4*iter+2], 16)) |
|
888 """ |
|
889 |
|
487 # get protocol (profile) types supported by mailbox; <Device>-<Mailbox> |
890 # get protocol (profile) types supported by mailbox; <Device>-<Mailbox> |
488 mb = device.getMailbox() |
891 for mailbox_protocol in ["VoE", "SoE", "FoE", "CoE", "EoE", "AoE"]: |
489 if mb is not None: |
892 if device.getMailbox() is not None and eval("device.getMailbox().get%s()"%mailbox_protocol) is not None: |
490 for mailbox_protocol in mailbox_protocols: |
893 smartview_infos["supported_mailbox"] += "%s, "%mailbox_protocol |
491 if getattr(mb,"get%s"%mailbox_protocol)() is not None: |
|
492 smartview_infos["supported_mailbox"] += "%s, "%mailbox_protocol |
|
493 smartview_infos["supported_mailbox"] = smartview_infos["supported_mailbox"].strip(", ") |
894 smartview_infos["supported_mailbox"] = smartview_infos["supported_mailbox"].strip(", ") |
494 |
895 |
495 # get standard configuration of mailbox; <Device>-<Sm> |
896 # get standard configuration of mailbox; <Device>-<Sm> |
496 for sm_element in device.getSm(): |
897 for sm_element in device.getSm(): |
497 if sm_element.getcontent() == "MBoxOut": |
898 if sm_element.getcontent() == "MBoxOut": |
502 smartview_infos["mailbox_standardconf_inlength"] = str(ExtractHexDecValue(sm_element.getDefaultSize())) |
903 smartview_infos["mailbox_standardconf_inlength"] = str(ExtractHexDecValue(sm_element.getDefaultSize())) |
503 else: |
904 else: |
504 pass |
905 pass |
505 |
906 |
506 # get device identity from <Device>-<Type> |
907 # get device identity from <Device>-<Type> |
507 # vendor ID; by default, pre-defined value in self.ModulesLibrary |
908 # vendor ID; by default, pre-defined value in self.ModulesLibrary |
508 # if device type in 'vendor' item equals to actual slave device type, set 'vendor_id' to vendor ID. |
909 # if device type in 'vendor' item equals to actual slave device type, set 'vendor_id' to vendor ID. |
509 for vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems(): |
910 for vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems(): |
510 for available_device in vendor["groups"][vendor["groups"].keys()[0]]["devices"]: |
911 for available_device in vendor["groups"][vendor["groups"].keys()[0]]["devices"]: |
511 if available_device[0] == type_infos["device_type"]: |
912 if available_device[0] == type_infos["device_type"]: |
512 smartview_infos["vendor_id"] = "0x" + "{:0>8x}".format(vendor_id) |
913 smartview_infos["vendor_id"] = "0x" + "{:0>8x}".format(vendor_id) |
513 |
914 |
514 # product code; |
915 # product code; |
515 if device.getType().getProductCode() is not None: |
916 if device.getType().getProductCode() is not None: |
516 product_code = device.getType().getProductCode() |
917 product_code = device.getType().getProductCode() |
517 smartview_infos["product_code"] = "0x"+"{:0>8x}".format(ExtractHexDecValue(product_code)) |
918 smartview_infos["product_code"] = "0x"+"{:0>8x}".format(ExtractHexDecValue(product_code)) |
518 |
919 |
519 # revision number; |
920 # revision number; |
520 if device.getType().getRevisionNo() is not None: |
921 if device.getType().getRevisionNo() is not None: |
521 revision_no = device.getType().getRevisionNo() |
922 revision_no = device.getType().getRevisionNo() |
522 smartview_infos["revision_no"] = "0x"+"{:0>8x}".format(ExtractHexDecValue(revision_no)) |
923 smartview_infos["revision_no"] = "0x"+"{:0>8x}".format(ExtractHexDecValue(revision_no)) |
523 |
924 |
524 # serial number; |
925 # serial number; |
525 if device.getType().getSerialNo() is not None: |
926 if device.getType().getSerialNo() is not None: |
526 serial_no = device.getType().getSerialNo() |
927 serial_no = device.getType().getSerialNo() |
527 smartview_infos["serial_no"] = "0x"+"{:0>8x}".format(ExtractHexDecValue(serial_no)) |
928 smartview_infos["serial_no"] = "0x"+"{:0>8x}".format(ExtractHexDecValue(serial_no)) |
528 |
929 |
529 return smartview_infos |
930 return smartview_infos |
535 """ |
936 """ |
536 Convert decimal value into hexadecimal representation. |
937 Convert decimal value into hexadecimal representation. |
537 @param decnum : decimal value |
938 @param decnum : decimal value |
538 @return hex_data : hexadecimal representation of input value in decimal |
939 @return hex_data : hexadecimal representation of input value in decimal |
539 """ |
940 """ |
540 value = "%x" % decnum |
941 value = "%x" % int(decnum, 16) |
541 value_len = len(value) |
942 value_len = len(value) |
542 if (value_len % 2) == 0: |
943 if (value_len % 2) == 0: |
543 hex_len = value_len |
944 hex_len = value_len |
544 else: |
945 else: |
545 hex_len = (value_len / 2) * 2 + 2 |
946 hex_len = (value_len / 2) * 2 + 2 |
546 |
947 |
547 hex_data = ("{:0>"+str(hex_len)+"x}").format(decnum) |
948 hex_data = ("{:0>"+str(hex_len)+"x}").format(int(decnum, 16)) |
548 |
949 |
549 return hex_data |
950 return hex_data |
550 |
951 |
551 def SiiRead(self): |
952 def SiiRead(self): |
552 """ |
953 """ |
666 |
1067 |
667 # 'device' is the slave device of the current EtherCAT slave plugin |
1068 # 'device' is the slave device of the current EtherCAT slave plugin |
668 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
1069 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
669 type_infos = slave.getType() |
1070 type_infos = slave.getType() |
670 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
1071 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
671 |
1072 |
672 if device is not None: |
1073 if device is not None: |
673 # get ConfigData for EEPROM offset 0x0000-0x000d; <Device>-<Eeprom>-<ConfigData> |
1074 # get ConfigData for EEPROM offset 0x0000-0x000d; <Device>-<Eeprom>-<ConfigData> |
674 for eeprom_element in device.getEeprom().getcontent(): |
1075 # Modify by jblee because of update IDE module (minidom -> lxml) |
675 if eeprom_element["name"] == "ConfigData": |
1076 for eeprom_element in device.getEeprom().getchildren(): |
676 data = self.DecimalToHex(eeprom_element) |
1077 if eeprom_element.tag == "ConfigData": |
1078 data = self.DecimalToHex(objectify.fromstring(eeprom_element.tostring()).text) |
|
677 eeprom += self.GenerateEEPROMList(data, 0, 28) |
1079 eeprom += self.GenerateEEPROMList(data, 0, 28) |
678 |
1080 |
679 # calculate CRC for EEPROM offset 0x000e-0x000f |
1081 # calculate CRC for EEPROM offset 0x000e-0x000f |
680 crc = 0x48 |
1082 crc = 0x48 |
681 for segment in eeprom: |
1083 for segment in eeprom: |
730 |
1132 |
731 # reserved for EEPROM offset 0x0026-0x0027; |
1133 # reserved for EEPROM offset 0x0026-0x0027; |
732 eeprom.append("00") |
1134 eeprom.append("00") |
733 eeprom.append("00") |
1135 eeprom.append("00") |
734 |
1136 |
1137 data = "" |
|
735 # get BootStrap for EEPROM offset 0x0028-0x002e; <Device>-<Eeprom>-<BootStrap> |
1138 # get BootStrap for EEPROM offset 0x0028-0x002e; <Device>-<Eeprom>-<BootStrap> |
736 data = "" |
1139 # Modify by jblee because of update IDE module (minidom -> lxml) |
737 for eeprom_element in device.getEeprom().getcontent(): |
1140 for eeprom_element in device.getEeprom().getchildren(): |
738 if eeprom_element["name"] == "BootStrap": |
1141 if eeprom_element.tag == "BootStrap": |
739 data = "{:0>16x}".format(eeprom_element) |
1142 data = "{:0>16x}".format(int(objectify.fromstring(eeprom_element.tostring()).text, 16)) |
740 eeprom += self.GenerateEEPROMList(data, 0, 16) |
1143 eeprom += self.GenerateEEPROMList(data, 0, 16) |
741 |
1144 |
742 # get Standard Mailbox for EEPROM offset 0x0030-0x0037; <Device>-<sm> |
1145 # get Standard Mailbox for EEPROM offset 0x0030-0x0037; <Device>-<sm> |
743 data = "" |
1146 data = "" |
1147 standard_receive_mailbox_offset = None |
|
1148 standard_receive_mailbox_size = None |
|
744 standard_send_mailbox_offset = None |
1149 standard_send_mailbox_offset = None |
745 standard_send_mailbox_size = None |
1150 standard_send_mailbox_size = None |
746 standard_receive_mailbox_offset = None |
|
747 standard_receive_mailbox_size = None |
|
748 for sm_element in device.getSm(): |
1151 for sm_element in device.getSm(): |
749 if sm_element.getcontent() == "MBoxOut": |
1152 if sm_element.getcontent() == "MBoxOut": |
750 standard_receive_mailbox_offset = "{:0>4x}".format(ExtractHexDecValue(sm_element.getStartAddress())) |
1153 standard_receive_mailbox_offset = "{:0>4x}".format(ExtractHexDecValue(sm_element.getStartAddress())) |
751 standard_receive_mailbox_size = "{:0>4x}".format(ExtractHexDecValue(sm_element.getDefaultSize())) |
1154 standard_receive_mailbox_size = "{:0>4x}".format(ExtractHexDecValue(sm_element.getDefaultSize())) |
752 elif sm_element.getcontent() == "MBoxIn": |
1155 elif sm_element.getcontent() == "MBoxIn": |
778 eeprom.append(standard_send_mailbox_size[2:4]) |
1181 eeprom.append(standard_send_mailbox_size[2:4]) |
779 eeprom.append(standard_send_mailbox_size[0:2]) |
1182 eeprom.append(standard_send_mailbox_size[0:2]) |
780 |
1183 |
781 # get supported mailbox protocols for EEPROM offset 0x0038-0x0039; |
1184 # get supported mailbox protocols for EEPROM offset 0x0038-0x0039; |
782 data = 0 |
1185 data = 0 |
783 mb = device.getMailbox() |
1186 if device.getMailbox() is not None: |
784 if mb is not None : |
1187 for mbox, bit in [(device.getMailbox().getAoE(), 0), |
785 for bit,mbprot in enumerate(mailbox_protocols): |
1188 (device.getMailbox().getEoE(), 1), |
786 if getattr(mb,"get%s"%mbprot)() is not None: |
1189 (device.getMailbox().getCoE(), 2), |
1190 (device.getMailbox().getFoE(), 3), |
|
1191 (device.getMailbox().getSoE(), 4), |
|
1192 (device.getMailbox().getVoE(), 5)]: |
|
1193 if mbox is not None: |
|
787 data += 1<<bit |
1194 data += 1<<bit |
788 data = "{:0>4x}".format(data) |
1195 data = "{:0>4x}".format(data) |
789 eeprom.append(data[2:4]) |
1196 eeprom.append(data[2:4]) |
790 eeprom.append(data[0:2]) |
1197 eeprom.append(data[0:2]) |
791 |
1198 |
792 # resereved for EEPROM offset 0x003a-0x007b; |
1199 # resereved for EEPROM offset 0x003a-0x007b; |
793 for i in range(0x007b-0x003a+0x0001): |
1200 for i in range(0x007b-0x003a+0x0001): |
794 eeprom.append("00") |
1201 eeprom.append("00") |
795 |
1202 |
796 # get EEPROM size for EEPROM offset 0x007c-0x007d; |
1203 # get EEPROM size for EEPROM offset 0x007c-0x007d; |
1204 # Modify by jblee because of update IDE module (minidom -> lxml) |
|
797 data = "" |
1205 data = "" |
798 for eeprom_element in device.getEeprom().getcontent(): |
1206 for eeprom_element in device.getEeprom().getchildren(): |
799 if eeprom_element["name"] == "ByteSize": |
1207 if eeprom_element.tag == "ByteSize": |
800 eeprom_size = int(str(eeprom_element)) |
1208 eeprom_size = int(objectify.fromstring(eeprom_element.tostring()).text) |
801 data = "{:0>4x}".format(int(eeprom_element)/1024*8-1) |
1209 data = "{:0>4x}".format(eeprom_size/1024*8-1) |
802 |
1210 |
803 if data == "": |
1211 if data == "": |
804 eeprom.append("00") |
1212 eeprom.append("00") |
805 eeprom.append("00") |
1213 eeprom.append("00") |
806 else: |
1214 else: |
807 eeprom.append(data[2:4]) |
1215 eeprom.append(data[2:4]) |
808 eeprom.append(data[0:2]) |
1216 eeprom.append(data[0:2]) |
809 |
1217 |
810 # Version for EEPROM 0x007e-0x007f; |
1218 # Version for EEPROM 0x007e-0x007f; |
811 # According to "EtherCAT Slave Device Description(V0.3.0)" |
1219 # According to "EtherCAT Slave Device Description(V0.3.0)" |
812 eeprom.append("01") |
1220 eeprom.append("01") |
813 eeprom.append("00") |
1221 eeprom.append("00") |
814 |
1222 |
815 # append String Category data |
1223 # append String Category data |
816 for data in self.ExtractEEPROMStringCategory(device): |
1224 for data in self.ExtractEEPROMStringCategory(device): |
875 groupnameflag = False |
1283 groupnameflag = False |
876 devnameflag = False |
1284 devnameflag = False |
877 imageflag = False |
1285 imageflag = False |
878 |
1286 |
879 # vendor specific data |
1287 # vendor specific data |
880 # element1; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Type> |
1288 # element1; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Type> |
881 # vendor_specific_data : vendor specific data (binary type) |
1289 # vendor_specific_data : vendor specific data (binary type) |
1290 # Modify by jblee because of update IDE module (minidom -> lxml) |
|
882 vendor_specific_data = "" |
1291 vendor_specific_data = "" |
883 # vendor_spec_strings : list of vendor specific "strings" for preventing duplicated strings |
1292 # vendor_spec_strings : list of vendor specific "strings" for preventing duplicated strings |
884 vendor_spec_strings = [] |
1293 vendor_spec_strings = [] |
885 for element in device.getType().getcontent(): |
1294 for element in device.getType().getcontent(): |
886 data += element |
1295 data += element |
887 if data is not "" and type(data) == unicode: |
1296 # retrun type change unicode -> str |
1297 if data is not "" and type(data) == str: |
|
888 for vendor_spec_string in vendor_spec_strings: |
1298 for vendor_spec_string in vendor_spec_strings: |
889 if data == vendor_spec_string: |
1299 if data == vendor_spec_string: |
890 self.OrderIdx = vendor_spec_strings.index(data)+1 |
1300 self.OrderIdx = vendor_spec_strings.index(data)+1 |
891 typeflag = True |
1301 typeflag = True |
892 break |
1302 break |
899 vendor_specific_data += "{:0>2x}".format(len(data)) |
1309 vendor_specific_data += "{:0>2x}".format(len(data)) |
900 for character in range(len(data)): |
1310 for character in range(len(data)): |
901 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1311 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
902 data = "" |
1312 data = "" |
903 |
1313 |
904 # element2-1; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<GroupType> |
1314 # element2-1; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<GroupType> |
1315 # Modify by jblee because of update IDE module (minidom -> lxml) |
|
905 data = device.getGroupType() |
1316 data = device.getGroupType() |
906 if data is not None and type(data) == unicode: |
1317 # retrun type change unicode -> str |
1318 if data is not None and type(data) == str: |
|
907 for vendor_spec_string in vendor_spec_strings: |
1319 for vendor_spec_string in vendor_spec_strings: |
908 if data == vendor_spec_string: |
1320 if data == vendor_spec_string: |
909 self.GroupIdx = vendor_spec_strings.index(data)+1 |
1321 self.GroupIdx = vendor_spec_strings.index(data)+1 |
910 grouptypeflag = True |
1322 grouptypeflag = True |
911 break |
1323 break |
918 self.GroupIdx = count |
1330 self.GroupIdx = count |
919 vendor_specific_data += "{:0>2x}".format(len(data)) |
1331 vendor_specific_data += "{:0>2x}".format(len(data)) |
920 for character in range(len(data)): |
1332 for character in range(len(data)): |
921 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1333 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
922 |
1334 |
923 # element2-2; <EtherCATInfo>-<Groups>-<Group>-<Type> |
1335 # element2-2; <EtherCATInfo>-<Groups>-<Group>-<Type> |
924 if grouptypeflag is False: |
1336 if grouptypeflag is False: |
925 if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None: |
1337 if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None: |
926 for vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems(): |
1338 for vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems(): |
927 for group_type, group_etc in vendor["groups"].iteritems(): |
1339 for group_type, group_etc in vendor["groups"].iteritems(): |
928 for device_item in group_etc["devices"]: |
1340 for device_item in group_etc["devices"]: |
943 self.GroupIdx = count |
1355 self.GroupIdx = count |
944 vendor_specific_data += "{:0>2x}".format(len(data)) |
1356 vendor_specific_data += "{:0>2x}".format(len(data)) |
945 for character in range(len(data)): |
1357 for character in range(len(data)): |
946 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1358 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
947 data = "" |
1359 data = "" |
948 |
1360 |
949 # element3; <EtherCATInfo>-<Descriptions>-<Groups>-<Group>-<Name(LcId is "1033")> |
1361 # element3; <EtherCATInfo>-<Descriptions>-<Groups>-<Group>-<Name(LcId is "1033")> |
1362 # Modify by jblee because of update IDE module (minidom -> lxml) |
|
1363 if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None: |
|
1364 LcId_obj = self.Controler.CTNParent.CTNParent.ModulesLibrary.LcId_data |
|
1365 data = LcId_obj.getcontent() |
|
1366 |
|
1367 # retrun type change unicode -> str |
|
1368 if data is not "" and type(data) == str: |
|
1369 for vendor_spec_string in vendor_spec_strings: |
|
1370 if data == vendor_spec_string: |
|
1371 groupnameflag = True |
|
1372 break |
|
1373 if groupnameflag is False: |
|
1374 count += 1 |
|
1375 self.Strings.append(data) |
|
1376 vendor_spec_strings.append(data) |
|
1377 groupnameflag = True |
|
1378 vendor_specific_data += "{:0>2x}".format(len(data)) |
|
1379 for character in range(len(data)): |
|
1380 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
|
1381 |
|
1382 """ |
|
1383 # element3; <EtherCATInfo>-<Descriptions>-<Groups>-<Group>-<Name(LcId is "1033")> |
|
950 if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None: |
1384 if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None: |
951 for vendorId, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems(): |
1385 for vendorId, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems(): |
952 for group_type, group_etc in vendor["groups"].iteritems(): |
1386 for group_type, group_etc in vendor["groups"].iteritems(): |
953 for device_item in group_etc["devices"]: |
1387 for device_item in group_etc["devices"]: |
954 if device == device_item[1]: |
1388 if device == device_item[1]: |
964 vendor_spec_strings.append(data) |
1398 vendor_spec_strings.append(data) |
965 groupnameflag = True |
1399 groupnameflag = True |
966 vendor_specific_data += "{:0>2x}".format(len(data)) |
1400 vendor_specific_data += "{:0>2x}".format(len(data)) |
967 for character in range(len(data)): |
1401 for character in range(len(data)): |
968 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1402 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1403 """ |
|
1404 |
|
969 data = "" |
1405 data = "" |
970 |
1406 |
971 # element4; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Name(LcId is "1033" or "1"?)> |
1407 # element4; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Name(LcId is "1033" or "1"?)> |
1408 # Modify by jblee because of update IDE module (minidom -> lxml) |
|
972 for element in device.getName(): |
1409 for element in device.getName(): |
973 if element.getLcId() == 1 or element.getLcId()==1033: |
1410 if element.getLcId() == 1 or element.getLcId()==1033: |
974 data = element.getcontent() |
1411 data = element.getcontent() |
975 if data is not "" and type(data) == unicode: |
1412 # retrun type change unicode -> str |
1413 if data is not "" and type(data) == str: |
|
976 for vendor_spec_string in vendor_spec_strings: |
1414 for vendor_spec_string in vendor_spec_strings: |
977 if data == vendor_spec_string: |
1415 if data == vendor_spec_string: |
978 self.NameIdx = vendor_spec_strings.index(data)+1 |
1416 self.NameIdx = vendor_spec_strings.index(data)+1 |
979 devnameflag = True |
1417 devnameflag = True |
980 break |
1418 break |
985 devnameflag = True |
1423 devnameflag = True |
986 self.NameIdx = count |
1424 self.NameIdx = count |
987 vendor_specific_data += "{:0>2x}".format(len(data)) |
1425 vendor_specific_data += "{:0>2x}".format(len(data)) |
988 for character in range(len(data)): |
1426 for character in range(len(data)): |
989 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1427 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1428 |
|
990 data = "" |
1429 data = "" |
991 |
1430 |
992 # element5-1; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Image16x14> |
1431 # element5-1; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Image16x14> |
993 if device.getcontent() is not None: |
1432 if device.getcontent() is not None: |
994 data = device.getcontent() |
1433 #data = device.getcontent()["value"] |
995 if data is not None and type(data) == unicode: |
1434 # mod by jblee 151224 |
1435 # xml module change minidom -> lxml |
|
1436 # use lxml objectify module |
|
1437 data = objectify.fromstring(device.getcontent().tostring()).text |
|
1438 # retrun type change unicode -> str |
|
1439 if data is not None and type(data) == str: |
|
996 for vendor_spec_string in vendor_spec_strings: |
1440 for vendor_spec_string in vendor_spec_strings: |
997 if data == vendor_spec_string: |
1441 if data == vendor_spec_string: |
998 self.ImgIdx = vendor_spec_strings.index(data)+1 |
1442 self.ImgIdx = vendor_spec_strings.index(data)+1 |
999 imageflag = True |
1443 imageflag = True |
1000 break |
1444 break |
1005 imageflag = True |
1449 imageflag = True |
1006 self.ImgIdx = count |
1450 self.ImgIdx = count |
1007 vendor_specific_data += "{:0>2x}".format(len(data)) |
1451 vendor_specific_data += "{:0>2x}".format(len(data)) |
1008 for character in range(len(data)): |
1452 for character in range(len(data)): |
1009 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1453 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1010 |
1454 |
1011 # element5-2; <EtherCATInfo>-<Descriptions>-<Groups>-<Group>-<Image16x14> |
1455 # element5-2; <EtherCATInfo>-<Descriptions>-<Groups>-<Group>-<Image16x14> |
1456 # Modify by jblee because of update IDE module (minidom -> lxml) |
|
1457 if imageflag is False: |
|
1458 if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None: |
|
1459 data_obj = self.Controler.CTNParent.CTNParent.ModulesLibrary.Image16x14_data |
|
1460 data = data_obj.text |
|
1461 |
|
1462 # retrun type change unicode -> str |
|
1463 if data is not None and type(data) == str: |
|
1464 for vendor_spec_string in vendor_spec_strings: |
|
1465 if data == vendor_spec_string: |
|
1466 self.ImgIdx = vendor_spec_strings.index(data)+1 |
|
1467 imageflag = True |
|
1468 break |
|
1469 if imageflag is False: |
|
1470 count += 1 |
|
1471 self.Strings.append(data) |
|
1472 vendor_spec_strings.append(data) |
|
1473 imageflag = True |
|
1474 self.ImgIdx = count |
|
1475 vendor_specific_data += "{:0>2x}".format(len(data)) |
|
1476 for character in range(len(data)): |
|
1477 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
|
1478 |
|
1479 """ |
|
1480 # element5-2; <EtherCATInfo>-<Descriptions>-<Groups>-<Group>-<Image16x14> |
|
1012 if imageflag is False: |
1481 if imageflag is False: |
1013 if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None: |
1482 if self.Controler.CTNParent.CTNParent.ModulesLibrary.Library is not None: |
1014 for vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems(): |
1483 for vendor_id, vendor in self.Controler.CTNParent.CTNParent.ModulesLibrary.Library.iteritems(): |
1015 for group_type, group_etc in vendor["groups"].iteritems(): |
1484 for group_type, group_etc in vendor["groups"].iteritems(): |
1016 for device_item in group_etc["devices"]: |
1485 for device_item in group_etc["devices"]: |
1017 if device == device_item[1]: |
1486 if device == device_item[1]: |
1018 data = group_etc |
1487 print group_etc |
1019 if data is not None and type(data) == unicode: |
1488 data = group_etc["value"] |
1489 # retrun type change unicode -> str |
|
1490 if data is not None and type(data) == str: |
|
1020 for vendor_spec_string in vendor_spec_strings: |
1491 for vendor_spec_string in vendor_spec_strings: |
1021 if data == vendor_spec_string: |
1492 if data == vendor_spec_string: |
1022 self.ImgIdx = vendor_spec_strings.index(data)+1 |
1493 self.ImgIdx = vendor_spec_strings.index(data)+1 |
1023 imageflag = True |
1494 imageflag = True |
1024 break |
1495 break |
1029 imageflag = True |
1500 imageflag = True |
1030 self.ImgIdx = count |
1501 self.ImgIdx = count |
1031 vendor_specific_data += "{:0>2x}".format(len(data)) |
1502 vendor_specific_data += "{:0>2x}".format(len(data)) |
1032 for character in range(len(data)): |
1503 for character in range(len(data)): |
1033 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1504 vendor_specific_data += "{:0>2x}".format(ord(data[character])) |
1505 """ |
|
1506 |
|
1034 data = "" |
1507 data = "" |
1035 |
|
1036 # DC related elements |
1508 # DC related elements |
1037 # <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Dc>-<OpMode>-<Name> |
1509 # <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Dc>-<OpMode>-<Name> |
1038 dc_related_elements = "" |
1510 dc_related_elements = "" |
1039 if device.getDc() is not None: |
1511 if device.getDc() is not None: |
1040 for element in device.getDc().getOpMode(): |
1512 for element in device.getDc().getOpMode(): |
1041 data = element.getName() |
1513 data = element.getName() |
1042 if data is not "": |
1514 if data is not "": |
1046 for character in range(len(data)): |
1518 for character in range(len(data)): |
1047 dc_related_elements += "{:0>2x}".format(ord(data[character])) |
1519 dc_related_elements += "{:0>2x}".format(ord(data[character])) |
1048 data = "" |
1520 data = "" |
1049 |
1521 |
1050 # Input elements(TxPDO) |
1522 # Input elements(TxPDO) |
1051 # <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<TxPdo>; Name |
1523 # <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<TxPdo>; Name |
1052 input_elements = "" |
1524 input_elements = "" |
1053 inputs = [] |
1525 inputs = [] |
1054 for element in device.getTxPdo(): |
1526 for element in device.getTxPdo(): |
1055 for name in element.getName(): |
1527 for name in element.getName(): |
1056 data = name.getcontent() |
1528 data = name.getcontent() |
1079 for character in range(len(data)): |
1551 for character in range(len(data)): |
1080 input_elements += "{:0>2x}".format(ord(data[character])) |
1552 input_elements += "{:0>2x}".format(ord(data[character])) |
1081 data = "" |
1553 data = "" |
1082 |
1554 |
1083 # Output elements(RxPDO) |
1555 # Output elements(RxPDO) |
1084 # <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<RxPdo>; Name |
1556 # <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<RxPdo>; Name |
1085 output_elements = "" |
1557 output_elements = "" |
1086 outputs = [] |
1558 outputs = [] |
1087 for element in device.getRxPdo(): |
1559 for element in device.getRxPdo(): |
1088 for name in element.getName(): |
1560 for name in element.getName(): |
1089 data = name.getcontent() |
1561 data = name.getcontent() |
1112 for character in range(len(data)): |
1584 for character in range(len(data)): |
1113 output_elements += "{:0>2x}".format(ord(data[character])) |
1585 output_elements += "{:0>2x}".format(ord(data[character])) |
1114 data = "" |
1586 data = "" |
1115 |
1587 |
1116 # form eeprom data |
1588 # form eeprom data |
1117 # category header |
1589 # category header |
1118 eeprom.append("0a") |
1590 eeprom.append("0a") |
1119 eeprom.append("00") |
1591 eeprom.append("00") |
1120 # category length (word); 1 word is 4 bytes. "+2" is the length of string's total number |
1592 # category length (word); 1 word is 4 bytes. "+2" is the length of string's total number |
1121 length = len(vendor_specific_data + dc_related_elements + input_elements + output_elements) + 2 |
1593 length = len(vendor_specific_data + dc_related_elements + input_elements + output_elements) + 2 |
1122 if length%4 == 0: |
1594 if length%4 == 0: |
1123 pass |
1595 pass |
1124 else: |
1596 else: |
1125 length +=length%4 |
1597 length +=length%4 |
1126 padflag = True |
1598 padflag = True |
1127 eeprom.append("{:0>4x}".format(length/4)[2:4]) |
1599 eeprom.append("{:0>4x}".format(length/4)[2:4]) |
1128 eeprom.append("{:0>4x}".format(length/4)[0:2]) |
1600 eeprom.append("{:0>4x}".format(length/4)[0:2]) |
1129 # total numbers of strings |
1601 # total numbers of strings |
1130 eeprom.append("{:0>2x}".format(count)) |
1602 eeprom.append("{:0>2x}".format(count)) |
1131 for element in [vendor_specific_data, |
1603 for element in [vendor_specific_data, |
1132 dc_related_elements, |
1604 dc_related_elements, |
1133 input_elements, |
1605 input_elements, |
1134 output_elements]: |
1606 output_elements]: |
1169 eeprom.append("{:0>2x}".format(self.OrderIdx)) |
1641 eeprom.append("{:0>2x}".format(self.OrderIdx)) |
1170 eeprom.append("{:0>2x}".format(self.NameIdx)) |
1642 eeprom.append("{:0>2x}".format(self.NameIdx)) |
1171 |
1643 |
1172 # word 3 : Physical Layer Port info. and CoE Details |
1644 # word 3 : Physical Layer Port info. and CoE Details |
1173 eeprom.append("01") # Physical Layer Port info - assume 01 |
1645 eeprom.append("01") # Physical Layer Port info - assume 01 |
1174 # CoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE> |
1646 # CoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE> |
1175 coe_details = 0 |
1647 coe_details = 0 |
1176 mb = device.getMailbox() |
1648 if device.getMailbox() is not None and device.getMailbox().getCoE() is not None: |
1177 coe_details = 1 # sdo enabled |
1649 coe_details = 1 # sdo enabled |
1178 if mb is not None : |
1650 for attr, bit in [(device.getMailbox().getCoE().getSdoInfo(), 1), |
1179 coe = mb.getCoE() |
1651 (device.getMailbox().getCoE().getPdoAssign(), 2), |
1180 if coe is not None: |
1652 (device.getMailbox().getCoE().getPdoConfig(), 3), |
1181 for bit,flag in enumerate(["SdoInfo", "PdoAssign", "PdoConfig", |
1653 (device.getMailbox().getCoE().getPdoUpload(), 4), |
1182 "PdoUpload", "CompleteAccess"]): |
1654 (device.getMailbox().getCoE().getCompleteAccess(), 5)]: |
1183 if getattr(coe,"get%s"%flag)() is not None: |
1655 if attr==1 or attr==True: |
1184 coe_details += 1<<bit |
1656 coe_details += 1<<bit |
1185 eeprom.append("{:0>2x}".format(coe_details)) |
1657 eeprom.append("{:0>2x}".format(coe_details)) |
1186 |
1658 |
1187 # word 4 : FoE Details and EoE Details |
1659 # word 4 : FoE Details and EoE Details |
1188 # FoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<FoE> |
1660 # FoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<FoE> |
1189 if mb is not None and mb.getFoE() is not None: |
1661 if device.getMailbox() is not None and device.getMailbox().getFoE() is not None: |
1190 eeprom.append("01") |
1662 eeprom.append("01") |
1191 else: |
1663 else: |
1192 eeprom.append("00") |
1664 eeprom.append("00") |
1193 # EoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<EoE> |
1665 # EoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<EoE> |
1194 if mb is not None and mb.getEoE() is not None: |
1666 if device.getMailbox() is not None and device.getMailbox().getEoE() is not None: |
1195 eeprom.append("01") |
1667 eeprom.append("01") |
1196 else: |
1668 else: |
1197 eeprom.append("00") |
1669 eeprom.append("00") |
1198 |
1670 |
1199 # word 5 : SoE Channels(reserved) and DS402 Channels |
1671 # word 5 : SoE Channels(reserved) and DS402 Channels |
1200 # SoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<SoE> |
1672 # SoE Details; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<SoE> |
1201 if mb is not None and mb.getSoE() is not None: |
1673 if device.getMailbox() is not None and device.getMailbox().getSoE() is not None: |
1202 eeprom.append("01") |
1674 eeprom.append("01") |
1203 else: |
1675 else: |
1204 eeprom.append("00") |
1676 eeprom.append("00") |
1205 # DS402Channels; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE>: DS402Channels |
1677 # DS402Channels; <EtherCATInfo>-<Descriptions>-<Devices>-<Device>-<Mailbox>-<CoE>: DS402Channels |
1206 ds402ch = False |
1678 if device.getMailbox() is not None and \ |
1207 if mb is not None : |
1679 (device.getMailbox().getCoE().getDS402Channels() == True \ |
1208 coe = mb.getCoE() |
1680 or device.getMailbox().getCoE().getDS402Channels() == 1): |
1209 if coe is not None : |
1681 eeprom.append("01") |
1210 ds402ch = coe.getDS402Channels() |
1682 else: |
1211 eeprom.append("01" if ds402ch in [True,1] else "00") |
1683 eeprom.append("00") |
1212 |
1684 |
1213 # word 6 : SysmanClass(reserved) and Flags |
1685 # word 6 : SysmanClass(reserved) and Flags |
1214 eeprom.append("00") # reserved |
1686 eeprom.append("00") # reserved |
1215 # Flags |
1687 # Flags |
1216 en_safeop = False |
1688 en_safeop = False |
1217 en_lrw = False |
1689 en_lrw = False |
1218 if device.getType().getTcCfgModeSafeOp() == True \ |
1690 if device.getType().getTcCfgModeSafeOp() == True \ |
1219 or device.getType().getTcCfgModeSafeOp() == 1: |
1691 or device.getType().getTcCfgModeSafeOp() == 1: |
1220 en_safeop = True |
1692 en_safeop = True |
1270 if fmmu.getcontent() == "MBoxState": |
1742 if fmmu.getcontent() == "MBoxState": |
1271 data += "03" |
1743 data += "03" |
1272 |
1744 |
1273 # construct of EEPROM data |
1745 # construct of EEPROM data |
1274 if data is not "": |
1746 if data is not "": |
1275 # category header |
1747 # category header |
1276 eeprom.append("28") |
1748 eeprom.append("28") |
1277 eeprom.append("00") |
1749 eeprom.append("00") |
1278 # category length |
1750 # category length |
1279 if count%2 == 1: |
1751 if count%2 == 1: |
1280 padflag = True |
1752 padflag = True |
1281 eeprom.append("{:0>4x}".format((count+1)/2)[2:4]) |
1753 eeprom.append("{:0>4x}".format((count+1)/2)[2:4]) |
1282 eeprom.append("{:0>4x}".format((count+1)/2)[0:2]) |
1754 eeprom.append("{:0>4x}".format((count+1)/2)[0:2]) |
1283 else: |
1755 else: |
1287 if data == "": |
1759 if data == "": |
1288 eeprom.append("00") |
1760 eeprom.append("00") |
1289 else: |
1761 else: |
1290 eeprom.append(data[0:2]) |
1762 eeprom.append(data[0:2]) |
1291 data = data[2:len(data)] |
1763 data = data[2:len(data)] |
1292 # padding if length is odd bytes |
1764 # padding if length is odd bytes |
1293 if padflag is True: |
1765 if padflag is True: |
1294 eeprom.append("ff") |
1766 eeprom.append("ff") |
1295 |
1767 |
1296 return eeprom |
1768 return eeprom |
1297 |
1769 |
1319 else: |
1791 else: |
1320 data += "00" |
1792 data += "00" |
1321 data += number[sm.getcontent()] |
1793 data += number[sm.getcontent()] |
1322 |
1794 |
1323 if data is not "": |
1795 if data is not "": |
1324 # category header |
1796 # category header |
1325 eeprom.append("29") |
1797 eeprom.append("29") |
1326 eeprom.append("00") |
1798 eeprom.append("00") |
1327 # category length |
1799 # category length |
1328 eeprom.append("{:0>4x}".format(len(data)/4)[2:4]) |
1800 eeprom.append("{:0>4x}".format(len(data)/4)[2:4]) |
1329 eeprom.append("{:0>4x}".format(len(data)/4)[0:2]) |
1801 eeprom.append("{:0>4x}".format(len(data)/4)[0:2]) |
1330 for i in range(len(data)/2): |
1802 for i in range(len(data)/2): |
1331 if data == "": |
1803 if data == "": |
1332 eeprom.append("00") |
1804 eeprom.append("00") |
1349 en_fixed = False |
1821 en_fixed = False |
1350 en_mandatory = False |
1822 en_mandatory = False |
1351 en_virtual = False |
1823 en_virtual = False |
1352 |
1824 |
1353 for element in eval("device.get%s()"%pdotype): |
1825 for element in eval("device.get%s()"%pdotype): |
1354 # PDO Index |
1826 # PDO Index |
1355 data += "{:0>4x}".format(ExtractHexDecValue(element.getIndex().getcontent()))[2:4] |
1827 data += "{:0>4x}".format(ExtractHexDecValue(element.getIndex().getcontent()))[2:4] |
1356 data += "{:0>4x}".format(ExtractHexDecValue(element.getIndex().getcontent()))[0:2] |
1828 data += "{:0>4x}".format(ExtractHexDecValue(element.getIndex().getcontent()))[0:2] |
1357 # Number of Entries |
1829 # Number of Entries |
1358 data += "{:0>2x}".format(len(element.getEntry())) |
1830 data += "{:0>2x}".format(len(element.getEntry())) |
1359 # About Sync Manager |
1831 # About Sync Manager |
1360 if element.getSm() is not None: |
1832 if element.getSm() is not None: |
1361 data += "{:0>2x}".format(element.getSm()) |
1833 data += "{:0>2x}".format(element.getSm()) |
1362 else: |
1834 else: |
1363 data += "ff" |
1835 data += "ff" |
1364 # Reference to DC Synch (according to ET1100 documentation) - assume 0 |
1836 # Reference to DC Synch (according to ET1100 documentation) - assume 0 |
1365 data += "00" |
1837 data += "00" |
1366 # Name Index |
1838 # Name Index |
1367 objname = "" |
1839 objname = "" |
1368 for name in element.getName(): |
1840 for name in element.getName(): |
1369 objname = name.getcontent() |
1841 objname = name.getcontent() |
1370 for name in self.Strings: |
1842 for name in self.Strings: |
1371 count += 1 |
1843 count += 1 |
1374 if len(self.Strings)+1 == count: |
1846 if len(self.Strings)+1 == count: |
1375 data += "00" |
1847 data += "00" |
1376 else: |
1848 else: |
1377 data += "{:0>2x}".format(count) |
1849 data += "{:0>2x}".format(count) |
1378 count = 0 |
1850 count = 0 |
1379 # Flags; by Fixed, Mandatory, Virtual attributes ? |
1851 # Flags; by Fixed, Mandatory, Virtual attributes ? |
1380 if element.getFixed() == True or 1: |
1852 if element.getFixed() == True or 1: |
1381 en_fixed = True |
1853 en_fixed = True |
1382 if element.getMandatory() == True or 1: |
1854 if element.getMandatory() == True or 1: |
1383 en_mandatory = True |
1855 en_mandatory = True |
1384 if element.getVirtual() == True or element.getVirtual(): |
1856 if element.getVirtual() == True or element.getVirtual(): |
1385 en_virtual = True |
1857 en_virtual = True |
1386 data += str(int(en_fixed)) + str(int(en_mandatory)) + str(int(en_virtual)) + "0" |
1858 data += str(int(en_fixed)) + str(int(en_mandatory)) + str(int(en_virtual)) + "0" |
1387 |
1859 |
1388 for entry in element.getEntry(): |
1860 for entry in element.getEntry(): |
1389 # Entry Index |
1861 # Entry Index |
1390 data += "{:0>4x}".format(ExtractHexDecValue(entry.getIndex().getcontent()))[2:4] |
1862 data += "{:0>4x}".format(ExtractHexDecValue(entry.getIndex().getcontent()))[2:4] |
1391 data += "{:0>4x}".format(ExtractHexDecValue(entry.getIndex().getcontent()))[0:2] |
1863 data += "{:0>4x}".format(ExtractHexDecValue(entry.getIndex().getcontent()))[0:2] |
1392 # Subindex |
1864 # Subindex |
1393 data += "{:0>2x}".format(int(entry.getSubIndex())) |
1865 data += "{:0>2x}".format(int(entry.getSubIndex())) |
1394 # Entry Name Index |
1866 # Entry Name Index |
1395 objname = "" |
1867 objname = "" |
1396 for name in entry.getName(): |
1868 for name in entry.getName(): |
1397 objname = name.getcontent() |
1869 objname = name.getcontent() |
1398 for name in self.Strings: |
1870 for name in self.Strings: |
1399 count += 1 |
1871 count += 1 |
1402 if len(self.Strings)+1 == count: |
1874 if len(self.Strings)+1 == count: |
1403 data += "00" |
1875 data += "00" |
1404 else: |
1876 else: |
1405 data += "{:0>2x}".format(count) |
1877 data += "{:0>2x}".format(count) |
1406 count = 0 |
1878 count = 0 |
1407 # DataType |
1879 # DataType |
1408 if entry.getDataType() is not None: |
1880 if entry.getDataType() is not None: |
1409 if entry.getDataType().getcontent() in self.BaseDataTypeDict: |
1881 if entry.getDataType().getcontent() in self.BaseDataTypeDict: |
1410 data += self.BaseDataTypeDict[entry.getDataType().getcontent()] |
1882 data += self.BaseDataTypeDict[entry.getDataType().getcontent()] |
1411 else: |
1883 else: |
1412 data += "00" |
1884 data += "00" |
1413 else: |
1885 else: |
1414 data += "00" |
1886 data += "00" |
1415 # BitLen |
1887 # BitLen |
1416 if entry.getBitLen() is not None: |
1888 if entry.getBitLen() is not None: |
1417 data += "{:0>2x}".format(int(entry.getBitLen())) |
1889 data += "{:0>2x}".format(int(entry.getBitLen())) |
1418 else: |
1890 else: |
1419 data += "00" |
1891 data += "00" |
1420 # Flags; by Fixed attributes ? |
1892 # Flags; by Fixed attributes ? |
1421 en_fixed = False |
1893 en_fixed = False |
1422 if entry.getFixed() == True or entry.getFixed() == 1: |
1894 if entry.getFixed() == True or entry.getFixed() == 1: |
1423 en_fixed = True |
1895 en_fixed = True |
1424 data += str(int(en_fixed)) + "000" |
1896 data += str(int(en_fixed)) + "000" |
1425 |
1897 |
1426 if data is not "": |
1898 if data is not "": |
1427 # category header |
1899 # category header |
1428 if pdotype == "TxPdo": |
1900 if pdotype == "TxPdo": |
1429 eeprom.append("32") |
1901 eeprom.append("32") |
1430 elif pdotype == "RxPdo": |
1902 elif pdotype == "RxPdo": |
1431 eeprom.append("33") |
1903 eeprom.append("33") |
1432 else: |
1904 else: |
1433 eeprom.append("00") |
1905 eeprom.append("00") |
1434 eeprom.append("00") |
1906 eeprom.append("00") |
1435 # category length |
1907 # category length |
1436 eeprom.append("{:0>4x}".format(len(data)/4)[2:4]) |
1908 eeprom.append("{:0>4x}".format(len(data)/4)[2:4]) |
1437 eeprom.append("{:0>4x}".format(len(data)/4)[0:2]) |
1909 eeprom.append("{:0>4x}".format(len(data)/4)[0:2]) |
1438 data = str(data.lower()) |
1910 data = str(data.lower()) |
1439 for i in range(len(data)/2): |
1911 for i in range(len(data)/2): |
1440 if data == "": |
1912 if data == "": |
1457 namecount = 0 |
1929 namecount = 0 |
1458 |
1930 |
1459 if device.getDc() is not None: |
1931 if device.getDc() is not None: |
1460 for element in device.getDc().getOpMode(): |
1932 for element in device.getDc().getOpMode(): |
1461 count += 1 |
1933 count += 1 |
1462 # assume that word 1-7 are 0x0000 |
1934 # assume that word 1-7 are 0x0000 |
1463 data += "0000" |
1935 data += "0000" |
1464 data += "0000" |
1936 data += "0000" |
1465 data += "0000" |
1937 data += "0000" |
1466 data += "0000" |
1938 data += "0000" |
1467 data += "0000" |
1939 data += "0000" |
1468 data += "0000" |
1940 data += "0000" |
1469 data += "0000" |
1941 data += "0000" |
1470 # word 8-10 |
1942 # word 8-10 |
1471 # AssignActivate |
1943 # AssignActivate |
1472 if element.getAssignActivate() is not None: |
1944 if element.getAssignActivate() is not None: |
1473 data += "{:0>4x}".format(ExtractHexDecValue(element.getAssignActivate()))[2:4] |
1945 data += "{:0>4x}".format(ExtractHexDecValue(element.getAssignActivate()))[2:4] |
1474 data += "{:0>4x}".format(ExtractHexDecValue(element.getAssignActivate()))[0:2] |
1946 data += "{:0>4x}".format(ExtractHexDecValue(element.getAssignActivate()))[0:2] |
1475 else: |
1947 else: |
1476 data += "0000" |
1948 data += "0000" |
1477 # Factor of CycleTimeSync0 ? and default is 1? |
1949 # Factor of CycleTimeSync0 ? and default is 1? |
1478 if element.getCycleTimeSync0() is not None: |
1950 if element.getCycleTimeSync0() is not None: |
1479 if element.getCycleTimeSync0().getFactor() is not None: |
1951 if element.getCycleTimeSync0().getFactor() is not None: |
1480 data += "{:0>2x}".format(int(element.getCycleTimeSync0().getFactor())) |
1952 data += "{:0>2x}".format(int(element.getCycleTimeSync0().getFactor())) |
1481 data += "00" |
1953 data += "00" |
1482 else: |
1954 else: |
1483 data += "0100" |
1955 data += "0100" |
1484 else: |
1956 else: |
1485 data += "0100" |
1957 data += "0100" |
1486 # Index of Name in STRINGS Category |
1958 # Index of Name in STRINGS Category |
1487 # Name Index |
1959 # Name Index |
1488 objname = "" |
1960 objname = "" |
1489 for name in element.getName(): |
1961 for name in element.getName(): |
1490 objname += name |
1962 objname += name |
1491 for name in self.Strings: |
1963 for name in self.Strings: |
1492 namecount += 1 |
1964 namecount += 1 |
1496 data += "00" |
1968 data += "00" |
1497 else: |
1969 else: |
1498 data += "{:0>2x}".format(namecount) |
1970 data += "{:0>2x}".format(namecount) |
1499 namecount = 0 |
1971 namecount = 0 |
1500 data += "00" |
1972 data += "00" |
1501 # assume that word 11-12 are 0x0000 |
1973 # assume that word 11-12 are 0x0000 |
1502 data += "0000" |
1974 data += "0000" |
1503 data += "0000" |
1975 data += "0000" |
1504 |
1976 |
1505 if data is not "": |
1977 if data is not "": |
1506 # category header |
1978 # category header |
1507 eeprom.append("3c") |
1979 eeprom.append("3c") |
1508 eeprom.append("00") |
1980 eeprom.append("00") |
1509 # category length |
1981 # category length |
1510 eeprom.append("{:0>4x}".format(len(data)/4)[2:4]) |
1982 eeprom.append("{:0>4x}".format(len(data)/4)[2:4]) |
1511 eeprom.append("{:0>4x}".format(len(data)/4)[0:2]) |
1983 eeprom.append("{:0>4x}".format(len(data)/4)[0:2]) |
1512 data = str(data.lower()) |
1984 data = str(data.lower()) |
1513 for i in range(len(data)/2): |
1985 for i in range(len(data)/2): |
1514 if data == "": |
1986 if data == "": |
1531 @return return_val : register data |
2003 @return return_val : register data |
1532 """ |
2004 """ |
1533 error, return_val = self.Controler.RemoteExec(REG_READ%(self.Controler.GetSlavePos(), offset, length), return_val = None) |
2005 error, return_val = self.Controler.RemoteExec(REG_READ%(self.Controler.GetSlavePos(), offset, length), return_val = None) |
1534 return return_val |
2006 return return_val |
1535 |
2007 |
2008 def MultiRegRead(self, slave_num, reg_infos): |
|
2009 """ |
|
2010 |
|
2011 @slave_num: |
|
2012 @param addr_info: |
|
2013 @return return_val: |
|
2014 """ |
|
2015 reg_info_str = "" |
|
2016 for reg_info in reg_infos: |
|
2017 reg_info_str = reg_info_str + "%s|" % reg_info |
|
2018 reg_info_str = reg_info_str.strip("|") |
|
2019 |
|
2020 error, return_val = self.Controler.RemoteExec(\ |
|
2021 MULTI_REG_READ%(slave_num, reg_info_str), |
|
2022 return_val = None) |
|
2023 |
|
2024 return return_val |
|
2025 |
|
1536 def RegWrite(self, address, data): |
2026 def RegWrite(self, address, data): |
1537 """ |
2027 """ |
1538 Write data to slave ESC register using "ethercat reg_write -p %d %s %s" command. |
2028 Write data to slave ESC register using "ethercat reg_write -p %d %s %s" command. |
1539 Command example : "ethercat reg_write -p 0 0x0c04 0x0001" |
2029 Command example : "ethercat reg_write -p 0 0x0c04 0x0001" |
1540 @param address : register address |
2030 @param address : register address |
1548 """ |
2038 """ |
1549 Synchronize EEPROM data in master controller with the data in slave device after EEPROM write. |
2039 Synchronize EEPROM data in master controller with the data in slave device after EEPROM write. |
1550 Command example : "ethercat rescan -p 0" |
2040 Command example : "ethercat rescan -p 0" |
1551 """ |
2041 """ |
1552 error, return_val = self.Controler.RemoteExec(RESCAN%(self.Controler.GetSlavePos()), return_val = None) |
2042 error, return_val = self.Controler.RemoteExec(RESCAN%(self.Controler.GetSlavePos()), return_val = None) |
2043 |
|
2044 #------------------------------------------------------------------------------- |
|
2045 # Used DC Configuration |
|
2046 #------------------------------------------------------------------------------- |
|
2047 def LoadESIData(self): |
|
2048 return_data = [] |
|
2049 slave = self.Controler.CTNParent.GetSlave(self.Controler.GetSlavePos()) |
|
2050 type_infos = slave.getType() |
|
2051 device, alignment = self.Controler.CTNParent.GetModuleInfos(type_infos) |
|
2052 if device.getDc() is not None: |
|
2053 for OpMode in device.getDc().getOpMode(): |
|
2054 temp_data = { |
|
2055 "desc" : OpMode.getDesc() if OpMode.getDesc() is not None else "Unused", |
|
2056 "assign_activate" : OpMode.getAssignActivate() \ |
|
2057 if OpMode.getAssignActivate() is not None else "#x0000", |
|
2058 "cycletime_sync0" : OpMode.getCycleTimeSync0().getcontent() \ |
|
2059 if OpMode.getCycleTimeSync0() is not None else None, |
|
2060 "shifttime_sync0" : OpMode.getShiftTimeSync0().getcontent() \ |
|
2061 if OpMode.getShiftTimeSync0() is not None else None, |
|
2062 "cycletime_sync1" : OpMode.getShiftTimeSync1().getcontent() \ |
|
2063 if OpMode.getShiftTimeSync1() is not None else None, |
|
2064 "shifttime_sync1" : OpMode.getShiftTimeSync1().getcontent() \ |
|
2065 if OpMode.getShiftTimeSync1() is not None else None |
|
2066 } |
|
2067 |
|
2068 if OpMode.getCycleTimeSync0() is not None: |
|
2069 temp_data["cycletime_sync0_factor"] = OpMode.getCycleTimeSync0().getFactor() |
|
2070 |
|
2071 if OpMode.getCycleTimeSync1() is not None: |
|
2072 temp_data["cycletime_sync1_factor"] = OpMode.getCycleTimeSync1().getFactor() |
|
2073 |
|
2074 return_data.append(temp_data) |
|
2075 |
|
2076 return return_data |
|
1553 |
2077 |
1554 #------------------------------------------------------------------------------- |
2078 #------------------------------------------------------------------------------- |
1555 # Common Use Methods |
2079 # Common Use Methods |
1556 #------------------------------------------------------------------------------- |
2080 #------------------------------------------------------------------------------- |
1557 def CheckConnect(self, cyclic_flag): |
2081 def CheckConnect(self, cyclic_flag): |
1558 """ |
2082 """ |
1559 Check connection status (1) between Beremiz and the master (2) between the master and the slave. |
2083 Check connection status (1) between Beremiz and the master (2) between the master and the slave. |
1560 @param cyclic_flag: 0 - one shot, 1 - periodic |
2084 @param cyclic_flag: 0 - one shot, 1 - periodic |
1561 @return True or False |
2085 @return True or False |
1562 """ |
2086 """ |
1563 if self.Controler.GetCTRoot()._connector is not None: |
2087 if self.Controler.GetCTRoot()._connector is not None: |
1564 # Check connection between the master and the slave. |
2088 # Check connection between the master and the slave. |
1565 # Command example : "ethercat xml -p 0" |
2089 # Command example : "ethercat xml -p 0" |
1566 error, return_val = self.Controler.RemoteExec(SLAVE_XML%(self.Controler.GetSlavePos()), return_val = None) |
2090 error, return_val = self.Controler.RemoteExec(SLAVE_XML%(self.Controler.GetSlavePos()), return_val = None) |
1567 number_of_lines = return_val.split("\n") |
2091 number_of_lines = return_val.split("\n") |