查阅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.Busbustype='canalystii', channel=0, baud=500000)
msg = can.Messagearbitration_id=0xc0ffee,
data=[0, 25, 0, 1, 3, 1, 4, 1],
is_extended_id=True)
try:
bus.sendmsg)
print"Message sent on {}".formatbus.channel_info))
except can.CanError:
print"Message NOT sent")
if __name__ == '__main__':
send_one)