调用python-can库使用周立功CAN接口卡发送数据

9 篇文章 6 订阅

查阅python-can文档,知晓其支持部分周立功CAN接口卡,故写例程验证数据的发送。另外,使用的python版本为3.4,在安装python-can时提示找不到windows-curses对应版本的安装包,故在python-can的setup.py中,取消了windows-curses的安装依赖。
代码如下(ControlCAN.dll需放置在相同路径下):

from __future__ import print_function
import platform
import can

def send_one():
    bus = can.interface.Bus(bustype='canalystii', channel=0, baud=500000)

    msg = can.Message(arbitration_id=0xc0ffee,
                      data=[0, 25, 0, 1, 3, 1, 4, 1],
                      is_extended_id=True)

    try:
        bus.send(msg)
        print("Message sent on {}".format(bus.channel_info))
    except can.CanError:
        print("Message NOT sent")

if __name__ == '__main__':
    send_one()
Python立功是指通过调用zlgcan.dll来实现CAN卡的通讯收发报文的二次开发。在Python中,可以使用ctypes模块调用C++动态的接口函数(zlgcan.dll)来实现这一功能。根据电脑的操作系统和Python版本的不同,需要选择相应版本的zlgcan.dll。例如,如果是64位的操作系统安装了64位的Python,就需要使用最新的64位zlgcan.dll。这样做可以避免在运行时出现错误。\[1\] 为了优化代码,可以使用消费者和开发者模型来分离数据获取和绘图的过程,避免在同一个线程中进行。这样可以提高程序的稳定性和效率。\[2\] 如果需要下载示例代码,可以访问https://manual.zlg.cn/web/#/152?page_id=5332,点击Python合集进行下载。解压后,选择对应的型号示例打开,其中需要用到的文件包括zlcan.dll等。\[3\] #### 引用[.reference_title] - *1* *3* [Python基于立功盒子的二次开发的准备工作](https://blog.csdn.net/wsq119/article/details/129817000)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Python基于立功盒子接收特定报文信号并实时绘制折线图(二)](https://blog.csdn.net/wsq119/article/details/129821421)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值