wdv4szh@SZH6-C-000AV:~/jw_code/can-tools$ python3 can_martix.py ldf is not supported xls is not supported Traceback (most recent call last): File "can_martix.py", line 4, in <module> db = canmatrix.formats.load("path/to/your/arxml/file.arxml", "arxml") File "/home/wdv4szh/.local/lib/python3.8/site-packages/canmatrix/formats/__init__.py", line 88, in load dbs = module_instance.load(file_object, **options) # type: ignore File "/home/wdv4szh/.local/lib/python3.8/site-packages/canmatrix/formats/arxml.py", line 1937, in load ea.open(file) File "/home/wdv4szh/.local/lib/python3.8/site-packages/canmatrix/formats/arxml.py", line 78, in open self.tree = lxml.etree.parse(filename) File "src/lxml/etree.pyx", line 3519, in lxml.etree.parse File "src/lxml/parser.pxi", line 1839, in lxml.etree._parseDocument File "src/lxml/parser.pxi", line 1865, in lxml.etree._parseDocumentFromURL File "src/lxml/parser.pxi", line 1769, in lxml.etree._parseDocFromFile File "src/lxml/parser.pxi", line 1163, in lxml.etree._BaseParser._parseDocFromFile File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult File "src/lxml/parser.pxi", line 638, in lxml.etree._raiseParseError OSError: Error reading file 'path/to/your/arxml/file.arxml': failed to load external entity "path/to/your/arxml/file.arxml" wdv4szh@SZH6-C-000AV:~/jw_code/can-tools$
时间: 2023-12-17 12:03:32 浏览: 199
根据您提供的错误信息,看起来在加载ARXML文件时出现了问题。错误消息中指示无法读取文件 'path/to/your/arxml/file.arxml',因为它无法找到外部实体。
请确保您提供的文件路径是正确的,并且文件实际存在于指定的位置。您需要将 `"path/to/your/arxml/file.arxml"` 替换为实际的文件路径。
以下是修正后的代码示例:
```python
from canmatrix import *
# 加载ARXML文件
db = canmatrix.formats.load("/home/wdv4szh/jw_code/hello_world/adcc_someip_services_interfaces_test.arxml", "arxml")
# 定义输出C++代码的文件路径
output_file = "/home/wdv4szh/jw_code/hello_world/mytest.cpp"
# 生成C++代码
with open(output_file, "w") as f:
f.write(db.as_c_source())
print("ARXML转换为C++代码成功!")
```
请将 `"/home/wdv4szh/jw_code/hello_world/adcc_someip_services_interfaces_test.arxml"` 替换为实际的ARXML文件路径。
如果您仍然遇到问题,请确保您的文件路径正确,并检查文件是否存在。如果问题仍然存在,请提供更多详细信息,以便我可以更好地帮助您解决问题。
阅读全文