"""
Program test environment
Pyhone version:3.4.1
Firmware version:2.8.28
Dependent files(MacOSX):libGinkgo_Driver.dylib,libusb-0.1.4.dylib,libusb-1.0.0.dylib
Dependent files(Windows):Ginkgo_Driver.dll
Dependent files(Linux):libGinkgo_Driver.so,libusb-1.0.so
More product infomation:
http://www.viewtool.com/index.php/en/14-2016-07-26-07-18-35/57-2016-07-27-07-19-58
Data structure and API functionality definition detail please download:
Ginkgo USB-CAN Interface API Library Instruction
http://www.viewtool.com/demo/Ginkgo/Documents/Ginkgo_USB-CAN_Interface_API_Library_Instruction_v1.2.zip
"""
from ctypes import *
import platform
# Compatible with other CAN adapter datatype
class VCI_BOARD_INFO(Structure):
_fields_ = [
("hw_Version", c_ushort), # hardware version, in hex format, for example: 0x0100 present version is 1.00
("fw_Version", c_ushort), # firmware version in hex format
("dr_Version", c_ushort), # driver version, in hex format
("in_Version",c_ushort), # interface library version, in hex format
("irq_Num",c_ushort), # interrupt number used by board
("can_Num",c_ubyte), # CAN channel number
("str_Serial_Num",c_ubyte*20), # CAN board serial number
("str_hw_Type",c_ubyte*40), # string for hardware type,for example:"USBCAN V1.00\0"(note:include string null end'\0').
("Reserved",c_ushort*4)
];
# Compatible with other CAN adapter datatype
class VCI_BOARD_INFO_EX(Structure):
_fields_ = [
("ProductName", c_ubyte*32), # hardware name,for example: "Ginkgo-CAN-Adaptor\0"(note: include string null end'\0')
("FirmwareVersion", c_ubyte*4), # firmware version
("HardwareVersion", c_ubyte*4), # hardware version
("SerialNumber",c_ubyte*12) # adatper serial number
];
# Definition of CAN frame
class VCI_CAN_OBJ(Structure):
_fields_ = [("ID", c_uint), # Frame ID
("TimeStamp", c_uint), # timestamp of the frame arriving,started from initialization of CAN controller
("TimeFlag", c_byte), # if using timestamp. 1: use TimeStamp, 0:not use. TimeFlag and TimeStamp is available when the frame is recived frame
("SendType",c_byte), # send frame type. 0: normal send,1: single send,2: self send/receive,3: single self send/receive
("RemoteFlag",c_byte), # remote frame flag
("ExternFlag",c_byte), # extended frame flag
("DataLen",c_byte), # Data length(<=8),how many uint8_ts of data
("Data",c_ubyte*8), # text data
("Reserved",c_byte*3) # reserved
];
# definition of CAN controller status
class VCI_CAN_STATUS(Structure):
_fields_ = [("ErrInterrupt", c_byte), # interrupt record,will be cleared while reading
("regMode", c_byte), # CAN controller mode register
("regStatus", c_byte), # CAN controller status register
("regALCapture",c_byte), # CAN controller arbitrator lost register
("regECCapture",c_byte), # CAN controller error register
("regEWLimit",c_byte), # CAN controller error alarm limitation register
("regRECounter",c_byte), # CAN controller receive error register
("regTECounter",c_byte), # CAN controller send error register
("regESR",c_uint), # CAN controller status register
("regTSR",c_uint), # CAN controller status register
("BufferSize",c_uint), # CAN controller receive buffer size
("Reserved",c_uint), #
];
# definition of error data type
class VCI_ERR_INFO(Structure):
_fields_ = [("ErrCode",c_uint), # error code
("Passive_ErrData",c_ubyte*3), # error identification data when error has passive error
("ArLost_ErrData",c_ubyte) # error identification data when error has arbitration lost error
];
# definition of CAN initialization data type
class VCI_INIT_CONFIG(Structure):
_fields_ = [("AccCode",c_uint), # ACC code (for verification)
("AccMask",c_uint), # Mask code
("Reserved",c_uint), #
("Filter",c_byte), # filter type.0: double filter,1: single filter
("Timing0",c_byte), # Timer 0
("Timing1",c_byte), # Timer 1
("Mode",c_byte)
];
# Definition of CAN initialization data type
"""
CAN baudrate = 36MHz/(CAN_BRP)/(CAN_SJW+CAN_BS1+CAN_BS2)
baudrate(bps) CAN_BRP CAN_SJW CAN_BS1 CAN_BS2
1M 9 1 2 1
900K 5 1 5 2
800K 3 1 10 4
600K 12 1 3 1
666K 6 1 7 1
500K 12 1 4 1
400K 10 1 7 1
300K 15 1 6 1
250K 18 1 6 1
200K 10 1 15 2
150K 30 1 6 1
125K 36 1 6 1
100K 45 1 6 1
90K 50 1 6 1
80K 75 1 4 1
60K 75 1 6 1
50K 90 1 6 1
40K 100 1 7 1
30K 150 1 6 1
20K 225 1 6 1
more baudrate parameters and detail please download:
Ginkgo USB-CAN Interface STM32 baud rate calculation software:
http://www.viewtool.com/demo/download/Ginkgo2/Ginkgo_USB-CAN_Baudrate_Windows.rar
"""
class VCI_INIT_CONFIG_EX(Structure):
_fields_ = [("CAN_BRP", c_uint),# range: 1~1024,
("CAN_SJW", c_byte), # range: 1~4
("CAN_BS1", c_byte), # range: 1~16
("CAN_BS2",c_byte), # range: 1~8
("CAN_Mode",c_byte), # CAN working mode. 0: normal,1: loopback,2: silent,3: silent loopback
("CAN_ABOM",c_byte), # auto off line management. 0: prohibit,1: enable
("CAN_NART",c_byte), # text repeat send management. 0: enable text repeat sending,1: disable text repeat sending
("CAN_RFLM",c_byte), # FIFO lock management. 0: new text overwrite old, 1: ignore new text
("CAN_TXFP",c_byte), # send priority management, 0: by ID, 1: by order
("CAN_RELAY",c_byte), # relay feature enable. 0x00: close relay function,0x10: relay from CAN1 to CAN2,0x01: relay from CAN2 to CAN1, 0x11: bidirectionaly relay
("Reserved",c_uint) # reserved
];
# definition of CAN filter setting
class VCI_FILTER_CONFIG(Structure):
_fields_ = [("Enable", c_byte), # filter enable. 1: enable,0: disable
("FilterIndex", c_byte), # filter index. range: 0~13
("FilterMode", c_byte), # filter mode.0: mask bit,1: id list
("ExtFrame",c_byte), # filter frame flag. 1: the frame to be filtered is extended frame,0: the frame to be filtered is standard frame
("ID_Std_Ext",c_uint), # verification code ID
("ID_IDE",c_uint), # verification code IDE
("ID_RTR",c_uint), # verification code RTR
("MASK_Std_Ext",c_uint), # Mask code ID,only available when filter mode set to mask bit mode
("MASK_IDE",c_uint), # Mask code IDE,only available when filter mode set to mask bit mode
("MASK_RTR",c_uint), # Mask code RTR,only available when filter mode set to mask bit mode
("Reserved",c_uint), # reserved
];
# definition of CAN receive callback
if(platform.system()=="Windows"):
PVCI_RECEIVE_CALLBACK = WINFUNCTYPE(c_void_p,c_uint,c_uint,c_uint)
else:
PVCI_RECEIVE_CALLBACK = CFUNCTYPE(c_void_p,c_uint,c_uint,c_uint)
# CAN type definition
VCI_USBCAN1
没有合适的资源?快使用搜索试试~ 我知道了~
使用Python与CAN总线设备建立连接.zip
共16个文件
so:6个
dylib:3个
pyc:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 180 浏览量
2021-12-30
20:58:48
上传
评论
收藏 651KB ZIP 举报
温馨提示
使用Python与CAN总线设备建立连接.zip
资源推荐
资源详情
资源评论
收起资源包目录
使用Python与CAN总线设备建立连接.zip (16个子文件)
Python_USB_CAN_Test_working with 2 channels simultaneuously
lib
macos
libusb-0.1.4.dylib 27KB
libGinkgo_Driver.dylib 144KB
libusb-1.0.0.dylib 110KB
linux
64bit
libGinkgo_Driver.so 152KB
libusb-1.0.so 337KB
libusb.so 63KB
32bit
libGinkgo_Driver.so 158KB
libusb-1.0.so 275KB
libusb.so 52KB
windows
64bit
Ginkgo_Driver.dll 162KB
32bit
Ginkgo_Driver.dll 178KB
ControlCAN.py 15KB
CANTest.py 13KB
__pycache__
ControlCAN.cpython-36.pyc 10KB
ControlCAN.cpython-37.pyc 10KB
ControlCAN.cpython-35.pyc 10KB
共 16 条
- 1
资源评论
mYlEaVeiSmVp
- 粉丝: 1888
- 资源: 19万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- matlab的车牌识别系统源码毕业设计.zip
- 1990-2024年公司是否退市、上市公司退市名单、退市上市公司、退市公司(stata计算)
- matlab答题卡识别带界面GUI框架源码课程设计.zip
- 限流框架,使用固定时间滑动窗口+路径前缀匹配来完成对请求路径的限流 .zip
- 双指针 滑动窗口 二分查找 前缀和 位运算 模拟 分治 归并 链表 哈希表 字符串 栈 队列 优先级队列 BFS.zip
- MATLAB车牌计时计费系统源码课程设计.zip
- 全国31个省份2022-1990每万人拥有公共交通车辆人均城市道路绿地面积GDP常住人口无缺失
- 毕业设计基于matlab教室人数统计系统源码.zip
- 相对价格法计算市场分割指数或者一体化指数
- 基于滑动窗口的船舶避碰转向点数据挖掘模型.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功