Python-can库的使用(6)——can.logger使用

‍♂️我是纯良思安,爱技术、爱分享,更爱生活‍♂️

喜欢的朋友可以关注一下,下次更新不迷路


文章目录

简介

参数

使用方法


简介

通过Python-can可以无需license直接调用Vector的VNbox实现与CAN-BUS的交互。

Python-can库提供的脚本can.logger主要用于记录CAN log,将消息打印到标准输出或给定文件。

参数

在命令行窗口中使用python -m can.logger -h可以获取调用信息

$ python -m can.logger -h
ldf is not supported
xls is not supported
xlsx is not supported
yaml is not supported
usage: logger.py [-h] [-c CHANNEL]
                 [-i {canalystii,cantact,etas,gs_usb,iscan,ixxat,kvaser,neousys,neovi,nican,nixnet,pcan,robotell,seeedstudio,serial,slcan,socketcan,socketcand,systec,udp_multicast,usb2can,vector,virtual}]
                 [-b BITRATE] [--fd] [--data_bitrate DATA_BITRATE]
                 [-f LOG_FILE] [-a] [-s FILE_SIZE] [-v]
                 [--filter {:,~} [{:,~} ...]]
                 [--active | --passive]
                 ...

Log CAN traffic, printing messages to stdout or to a given file.

positional arguments:
  extra_args            The remaining arguments will be used for the interface
                        and logger/player initialisation. For example, `-i
                        vector -c 1 --app-name=MyCanApp` is the equivalent to
                        opening the bus with `Bus('vector', channel=1,
                        app_name='MyCanApp')

options:
  -h, --help            show this help message and exit
  -c CHANNEL, --channel CHANNEL
                        Most backend interfaces require some sort of channel.
                        For example with the serial interface the channel
                        might be a rfcomm device: "/dev/rfcomm0". With the
                        socketcan interface valid channel examples include:
                        "can0", "vcan0".
  -i {canalystii,cantact,etas,gs_usb,iscan,ixxat,kvaser,neousys,neovi,nican,nixnet,pcan,robotell,seeedstudio,serial,slcan,socketcan,socketcand,systec,udp_multicast,usb2can,vector,virtual}, --interface {canalystii,cantact,etas,gs_usb,iscan,ixxat,kvaser,neousys,neovi,nican,nixnet,pcan,robotell,seeedstudio,serial,slcan,socketcan,socketcand,systec,udp_multicast,usb2can,vector,virtual}
                        Specify the backend CAN interface to use. If left
                        blank, fall back to reading from configuration files.
  -b BITRATE, --bitrate BITRATE
                        Bitrate to use for the CAN bus.
  --fd                  Activate CAN-FD support
  --data_bitrate DATA_BITRATE
                        Bitrate to use for the data phase in case of CAN-FD.
  -f LOG_FILE, --file_name LOG_FILE
                        Path and base log filename, for supported types see
                        can.Logger.
  -a, --append          Append to the log file if it already exists.
  -s FILE_SIZE, --file_size FILE_SIZE
                        Maximum file size in bytes. Rotate log file when size
                        threshold is reached. (The resulting file sizes will
                        be consistent, but are not guaranteed to be exactly
                        what is specified here due to the rollover conditions
                        being logger implementation specific.)
  -v                    How much information do you want to see at the command
                        line? You can add several of these e.g., -vv is DEBUG
  --filter {:,~} [{:,~} ...]
                        R|Space separated CAN filters for the given CAN
                        interface: : (matches when
                         & mask == can_id & mask)
                        ~ (matches when  &
                        mask != can_id & mask) Fx to show only frames with ID
                        0x100 to 0x103 and 0x200 to 0x20F: python -m
                        can.viewer -f 100:7FC 200:7F0 Note that the ID and
                        mask are always interpreted as hex values
  --active              Start the bus as active, this is applied by default.
  --passive             Start the bus as passive.

使用方法

以Vector的VNbox盒子为例,具体使用方法步骤如下:

  1. 连接CANoe盒子(如VN1630A\VN1640A等所有Vector产品均可)至被测件
  2. 安装Python-can库,参考Python-can库的使用(1)——简介与安装
  3. 配置Vector Hardware Configuration中app_name到指定需要录log的通道,参考 Python-can库的使用(2)——配置
  4. 输入下方指令,之后会打印连接到哪个app的哪一路CAN以及开始录制的时间
python -m can.logger -i vector --app-name=Python_can -c 0 -b 500000 -fd --data_bitrate 2000000 -f bus_log.asc

通过Ctrl+C暂停录制,文件会自动保存到当前工作目录:
Python-can库的使用(6)——can.logger使用_第1张图片

  • 关于录制的文件格式,可以是上述.asc格式,直接用于在CANoe中离线分析
  • 也可以是txt格式,只需将指令中文件后缀改为bus_log.txt即可,常用于Python脚本直接处理:

Python-can库的使用(6)——can.logger使用_第2张图片

Python-can库的使用(6)——can.logger使用_第3张图片


如果文章对您有帮助,您可以“点赞、收藏、关注”,这也是我创作动力的源泉
感谢支持

你可能感兴趣的:(Python-can,python)