目的:中间件将CAN总线信号转成dds信号发出,为测试中间件的准确性,模拟发送CAN信号,并模拟dds接收器接收信号,将发送和接收的数据比较
1.安装XL Driver Library,必须安装,里面包含各种网络接口,可上官网下载
XL Driver Library 20.30.14
通过XL-Driver-Library访问Vector网络接口
2.下载develop分支代码并安装
仓库:https://github.com/hardbyte/python-can3.安装python-can
Building & Installing
The project can be built with:- pip install wheel
- python setup.py sdist bdist_wheel
复制代码 The project can be installed in editable mode with:4.找到安装的python-can包,找到vector文件夹,修改vxlapi.py 140行
- # CAN FD configuration structure
- class XLcanFdConf(ctypes.Structure):
- _fields_ = [('arbitrationBitRate', ctypes.c_uint), ('sjwAbr', ctypes.c_uint),
- ('tseg1Abr', ctypes.c_uint), ('tseg2Abr', ctypes.c_uint),
- ('dataBitRate', ctypes.c_uint), ('sjwDbr', ctypes.c_uint),
- ('tseg1Dbr', ctypes.c_uint), ('tseg2Dbr', ctypes.c_uint),
- ('options', ctypes.c_uint), # 手动增加
- ('reserved', ctypes.c_uint * 2)]
复制代码 5.修改canlib.py,新增加一个option参数
- class VectorBus(BusABC):
- """The CAN Bus implemented for the Vector interface."""
- deprecated_args = dict(
- sjwAbr="sjw_abr",
- tseg1Abr="tseg1_abr",
- tseg2Abr="tseg2_abr",
- sjwDbr="sjw_dbr",
- tseg1Dbr="tseg1_dbr",
- tseg2Dbr="tseg2_dbr",
- )
- @deprecated_args_alias(**deprecated_args)
- def __init__(
- self,
- channel: Union[int, Sequence[int], str],
- can_filters: Optional[CanFilters] = None,
- poll_interval: float = 0.01,
- receive_own_messages: bool = False,
- bitrate: Optional[int] = None,
- rx_queue_size: int = 2 ** 14,
- app_name: Optional[str] = "CANalyzer",
- serial: Optional[int] = None,
- fd: bool = True,
- data_bitrate: Optional[int] = None,
- sjw_abr: int = 32,
- tseg1_abr: int = 127,
- tseg2_abr: int = 32,
- sjw_dbr: int = 8,
- tseg1_dbr: int = 31,
- tseg2_dbr: int = 8,
- option=0, # 手动增加
- **kwargs: Any,
- ) -> None:
复制代码 8.搜索 self.canFdConf = vxlapi.XLcanFdConf() ,新增以下内容
- if fd:
- self.canFdConf = vxlapi.XLcanFdConf()
- self.canFdConf.options = ctypes.c_uint(option) # 手动新增
复制代码 9.找到python-can的安装路径,在vector目录下修改canlib.py
参考:\venv\Lib\site-packages\can\interfaces\vector\canlib.py\ - sjw_abr: int = 32,
- tseg1_abr: int = 127,
- tseg2_abr: int = 32,
- sjw_dbr: int = 8,
- tseg1_dbr: int = 31,
- tseg2_dbr: int = 8,<br><br>
复制代码- bus = can.interfaces.vector.VectorBus(bustype='vector', app_name='CANalyzer', channel=2, bitrate=500 * 1000, data_bitrate=2000 * 1000, fd=True)
复制代码 在User Manual文档5.4.1 XLcanFdConf章节的函数解释中可以看到sample point和sjw_abr、tseg1_abr、tseg2_abr的关系
打开本地CANoe -> CANFD工程 -> Network Hardware :
此时python-can发送CANFD信号已经完成,接下来完成使用dds API接收dds信号
参考文档:
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |