杀鸡焉用牛刀 发表于 2022-8-9 14:39:23

python-can模拟发送CAN FD总线信号

目的:中间件将CAN总线信号转成dds信号发出,为测试中间件的准确性,模拟发送CAN信号,并模拟dds接收器接收信号,将发送和接收的数据比较
 1.安装XL Driver Library,必须安装,里面包含各种网络接口,可上官网下载

XL Driver Library 20.30.14
https://img2022.cnblogs.com/blog/1900473/202206/1900473-20220623174621568-194257112.png通过XL-Driver-Library访问Vector网络接口
 https://img2022.cnblogs.com/blog/1900473/202206/1900473-20220623174722240-1436590233.png
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_wheelThe project can be installed in editable mode with:
pip install -e .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, str],
      can_filters: Optional = None,
      poll_interval: float = 0.01,
      receive_own_messages: bool = False,
      bitrate: Optional = None,
      rx_queue_size: int = 2 ** 14,
      app_name: Optional = "CANalyzer",
      serial: Optional = None,
      fd: bool = True,
      data_bitrate: Optional = 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 :
https://img2022.cnblogs.com/blog/1900473/202206/1900473-20220623185553965-1299384546.png
 
此时python-can发送CANFD信号已经完成,接下来完成使用dds API接收dds信号
参考文档:

[*]Short overview of facts (PDF)
[*]User Manual (PDF)
[*]python-can对Vector CAN FD(no-iso)的支持
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: python-can模拟发送CAN FD总线信号