python rti dds API调试
参考官网:RTI Connext DDS Python AP
一、 执行configuration.py失败
运行 configuration.py 脚本遇到的问题
python configure.py <platform> platform: ubuntu: x64Linux3gcc5.4.0 windows: x64Win64VS2017
1.检查rti安装目录下是否有该文件,如果没有则重新安装rti
Windows:xxx\rti_connext_dds-6.1.0\lib\x64Win64VS2017
Linux:/home/dongxuchai/rti_workspace/6.1.0/lib/x64Linux3gcc5.4.0
2.检查环境变量是否有NDDSHOME
Windows:设置在系统环境变量中(如:xxx\rti_connext_dds-6.1.0)
Linux:export NDDSHOME=/home/dongxuchai/rti_connext_dds-6.1.0/
二、idl转换成xml
rtiddsgen -convertToXml your_types.idl
INFO com.rti.ndds.nddsgen.Main Running rtiddsgen version 3.1.0, please wait ...
ERROR com.rti.ndds.nddsgen.Main Fail: java.lang.Exception: The preprocessor 'CL.EXE' cannot be found in your path.
可以先通过everything查找是否有cl.exe程序,cl.exe程序是visual studio里面C++开发包含的一个程序
如果安装了visual studio依然报错,可以尝试切换成visual studio 2017版本
三、多个idl转成xml
python dds使用的数据格式是XML,idl之间存在相互依赖关系,在使用python实现dds通信的时候需要需要把多个idl合成一个XML
import argparse import os import sys import xml.etree.ElementTree as ElementTree class IDLToXML: generator = '/home/cdx/rti_connext_dds-6.1.1/bin/rtiddsgen' def __init__(self, directory, destination): self.directory_ = directory self.destination_ = destination self.include_list_ = [] print(self.directory_, self.destination_) if not os.path.isdir(self.destination_): os.mkdir(self.destination_) def FindIDLs(self, directory): idl_files = [] for root, folders, files in os.walk(directory): print(directory, root.replace(directory + os.sep, '')) for file in files: if os.path.splitext(file)[-1] == '.idl': idl_files.append((root.replace(directory + os.sep, ''), file)) return idl_files def ToXML(self, sub_root, sub_dir, file): xml_file = self.destination_ + os.sep + sub_dir + os.sep + file content = ElementTree.parse(xml_file) if xml_file in self.include_list_: return self.include_list_.append(xml_file) for node in list(content.getroot()): if node.tag.find('include') == -1: sub_root.append(node) else: self.ToXML(sub_root, sub_dir, node.attrib['file']) def run(self): root = ElementTree.Element('dds') root.text = '\n' tree = ElementTree.ElementTree(root) sub_root = ElementTree.Element('types') sub_root.text = '\n' root.append(sub_root) idl_files = self.FindIDLs(self.directory_) xml_files = [] for sub_dir, file in idl_files: xml_file_dir = self.destination_ + os.sep + sub_dir os.makedirs(xml_file_dir, exist_ok=True) cmd = '{0} -convertToXml {1} -d {2}'.format(self.generator, '\"{0}\"'.format(self.directory_ + os.sep + sub_dir + os.sep + file), xml_file_dir) print('---- Converting ' + file + ' ----') os.system(cmd) xml_files.append((sub_dir, os.path.splitext(file)[0] + '.xml')) for sub_dir, file in xml_files: self.include_list_.clear() self.ToXML(sub_root, sub_dir, file) os.system('rm -r {0}{1}*'.format(self.destination_, os.sep)) tree.write(self.destination_ + os.sep + os.path.basename(self.directory_) + '.xml', encoding='utf-8', xml_declaration=True) if __name__ == '__main__': test = IDLToXML(directory=sys.argv[1], destination=sys.argv[2]) test.run()