|
14 | 14 | logger = logging.getLogger(__name__) |
15 | 15 |
|
16 | 16 |
|
| 17 | +def export_od(od, dest:Union[str,TextIO,None]=None, doc_type:Optional[str]=None): |
| 18 | + """ Export :class: ObjectDictionary to a file. |
| 19 | +
|
| 20 | + :param od: |
| 21 | + :class: ObjectDictionary object to be exported |
| 22 | + :param dest: |
| 23 | + export destination. filename, or file-like object or None. |
| 24 | + if None, the document is returned as string |
| 25 | + :param doc_type: type of document to export. |
| 26 | + If a filename is given for dest, this default to the file extension. |
| 27 | + Otherwise, this defaults to "eds" |
| 28 | + :rtype: str or None |
| 29 | + """ |
| 30 | + |
| 31 | + doctypes = {"eds", "dcf"} |
| 32 | + if type(dest) is str: |
| 33 | + if doc_type is None: |
| 34 | + for t in doctypes: |
| 35 | + if dest.endswith(f".{t}"): |
| 36 | + doc_type = t |
| 37 | + break |
| 38 | + |
| 39 | + if doc_type is None: |
| 40 | + doc_type = "eds" |
| 41 | + dest = open(dest, 'w') |
| 42 | + assert doc_type in doctypes |
| 43 | + |
| 44 | + if doc_type == "eds": |
| 45 | + from . import eds |
| 46 | + return eds.export_eds(od, dest) |
| 47 | + elif doc_type == "dcf": |
| 48 | + from . import eds |
| 49 | + return eds.export_dcf(od, dest) |
| 50 | + |
| 51 | + |
17 | 52 | def import_od( |
18 | 53 | source: Union[str, TextIO, None], |
19 | 54 | node_id: Optional[int] = None, |
@@ -54,10 +89,13 @@ class ObjectDictionary(MutableMapping): |
54 | 89 | def __init__(self): |
55 | 90 | self.indices = {} |
56 | 91 | self.names = {} |
| 92 | + self.comments = "" |
57 | 93 | #: Default bitrate if specified by file |
58 | 94 | self.bitrate: Optional[int] = None |
59 | 95 | #: Node ID if specified by file |
60 | 96 | self.node_id: Optional[int] = None |
| 97 | + #: Some information about the device |
| 98 | + self.device_information = DeviceInformation() |
61 | 99 |
|
62 | 100 | def __getitem__( |
63 | 101 | self, index: Union[int, str] |
@@ -280,6 +318,9 @@ def __init__(self, name: str, index: int, subindex: int = 0): |
280 | 318 | self.bit_definitions: Dict[str, List[int]] = {} |
281 | 319 | #: Storage location of index |
282 | 320 | self.storage_location = None |
| 321 | + #: Can this variable be mapped to a PDO |
| 322 | + self.pdo_mappable = False |
| 323 | + |
283 | 324 |
|
284 | 325 | def __eq__(self, other: "Variable") -> bool: |
285 | 326 | return (self.index == other.index and |
@@ -418,5 +459,24 @@ def encode_bits(self, original_value: int, bits: List[int], bit_value: int): |
418 | 459 | return temp |
419 | 460 |
|
420 | 461 |
|
| 462 | +class DeviceInformation: |
| 463 | + def __init__(self): |
| 464 | + self.allowed_baudrates = set() |
| 465 | + self.vendor_name:Optional[str] = None |
| 466 | + self.vendor_number:Optional[int] = None |
| 467 | + self.product_name:Optional[str] = None |
| 468 | + self.product_number:Optional[int] = None |
| 469 | + self.revision_number:Optional[int] = None |
| 470 | + self.order_code:Optional[str] = None |
| 471 | + self.simple_boot_up_master:Optional[bool] = None |
| 472 | + self.simple_boot_up_slave:Optional[bool] = None |
| 473 | + self.granularity:Optional[int] = None |
| 474 | + self.dynamic_channels_supported:Optional[bool] = None |
| 475 | + self.group_messaging:Optional[bool] = None |
| 476 | + self.nr_of_RXPDO:Optional[bool] = None |
| 477 | + self.nr_of_TXPDO:Optional[bool] = None |
| 478 | + self.LSS_supported:Optional[bool] = None |
| 479 | + |
| 480 | + |
421 | 481 | class ObjectDictionaryError(Exception): |
422 | 482 | """Unsupported operation with the current Object Dictionary.""" |
0 commit comments