背景:由于工作原因,最近想写一个CAN工具:1,界面简单容易操作;2,适合实车操作,有实车信号按钮;3.可自动化测试;4.CANoe Is Too Expensive!
环境:python3.7 +tkinter+多线程
一、调用dll库文件 调用的创芯科技DLL也可以用周立功DLL库;
# -*- encoding=utf-8 -*-
from ctypes import *
import time
dll = windll.LoadLibrary('./ControlCAN.dll') # 调用dll文件
nDeviceType = 4 # 设备类型USBCAN-2E-U
nDeviceInd = 0 # 索引号0,代表设备个数
nReserved = 0 # 无意义参数
# nCANInd = 1 # can通道号
# 定义一个python的'结构体',使用ctypes继承Structure,内容是初始化需要的参数,依据产品手册
class VciInitConfig(Structure):
_fields_ = [("AccCode", c_ulong), # 验收码,后面是数据类型
("AccMask", c_ulong), # 屏蔽码
("Reserved", c_ulong), # 保留
("Filter", c_ubyte), # 滤波使能。0=不使能,1=使能使能时,/
# 请参照SJA1000验收滤波器设置验收码和屏蔽码。
("Timing0", c_ubyte),