-
安装python-can
pip install python-can
-
找到python-can安装路径
- windows下一般不用虚拟环境安装则在python安装路径下Lib/site-packages
- linux下一般不用虚拟环境安装则在用户home目录./locals/lib/PythonVersion/Lib目录下
- 使用虚拟环境则在虚拟环境下Lib/site-packages
-
修改python-can路径下的can/interfaces/__init__.py文件, 在BACKENDS字典中添加一行:
"zlgcan": ("can.interfaces.zlgcan", "ZCanBus"),
-
把zlgcan文件夹拷贝到site-packages文件夹
-
把zlgcan.py拷贝到can/interfaces/文件夹
-
使用:
import can import time from zlgcan import ZCANDeviceType, ZCANCanTransType with can.Bus(bustype='zlgcan', device_type=ZCANDeviceType.ZCAN_USBCANFD_200U, resend=True, configs=[{'bitrate': 500000, 'initenal_resistance': 1}] # 1通道配置 ) as bus: while True: msg = can.Message( arbitration_id=0x01, is_extended_id=False, channel=0, data=[0x01, 0x02, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02, ], is_rx=False, ) bus.send(msg, trans_type=ZCANCanTransType.SELF_SR) time.sleep(0.05) print(bus.recv())
-
CAN测试列表:
- USBCAN-I-mini - ZCAN_USBCAN1, ZCAN_USBCAN2
- USBCANFD-100U-mini - ZCAN_USBCANFD_MINI
- USBCANFD-100U - ZCAN_USBCANFD_100U
- USBCANFD-200U - ZCAN_USBCANFD_200U
-
注意事项:
- ZCAN_USBCAN1及ZCAN_USBCAN2类型的设备无论是windows还是Linux, 波特率支持均在baudrate.conf.yaml中配置
- 此时计算timing0及timing1请下载CAN波特率计算软件
- 其他CANFD类型的CAN卡仅仅在Linux上使用时baudrate.conf.yaml中配置
- 此时计算相关值可以通过
ZCANPRO
软件
- 此时计算相关值可以通过
- 在Linux上使用ZCAN_USBCAN1衍生CAN卡时, 请设置derive为True, Windows上暂时未发现有问题
- ZCAN_USBCAN1及ZCAN_USBCAN2类型的设备无论是windows还是Linux, 波特率支持均在baudrate.conf.yaml中配置
-
官方工具及文档:
andyzhouh2017 / zlgcan-driver Goto Github PK
View Code? Open in Web Editor NEWThis project forked from zhuyu4839/zlgcan-driver
ZLGCAN driver
License: GNU Lesser General Public License v3.0