1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
# coding: utf-8
"""
Ctypes wrapper module for IXXAT Virtual CAN Interface V3 on win32 systems
Copyright (C) 2016 Giuseppe Corbelli <giuseppe.corbelli@weightpack.com>
"""
import ctypes
class LUID(ctypes.Structure):
_fields_ = [
("LowPart", ctypes.c_uint32),
("HighPart", ctypes.c_int32),
]
PLUID = ctypes.POINTER(LUID)
class VCIID(ctypes.Union):
_fields_ = [
("AsLuid", LUID),
("AsInt64", ctypes.c_int64),
]
PVCIID = ctypes.POINTER(VCIID)
class GUID(ctypes.Structure):
_fields_ = [
("Data1", ctypes.c_uint32),
("Data2", ctypes.c_uint16),
("Data3", ctypes.c_uint16),
("Data4", ctypes.c_char * 8),
]
class VCIDEVICEINFO(ctypes.Structure):
class UniqueHardwareId(ctypes.Union):
_fields_ = [
("AsChar", ctypes.c_char * 16),
("AsGuid", GUID),
]
_fields_ = [
("VciObjectId", VCIID),
("DeviceClass", GUID),
("DriverMajorVersion", ctypes.c_uint8),
("DriverMinorVersion", ctypes.c_uint8),
("DriverBuildVersion", ctypes.c_uint16),
("HardwareBranchVersion", ctypes.c_uint8),
("HardwareMajorVersion", ctypes.c_uint8),
("HardwareMinorVersion", ctypes.c_uint8),
("HardwareBuildVersion", ctypes.c_uint8),
("UniqueHardwareId", UniqueHardwareId),
("Description", ctypes.c_char * 128),
("Manufacturer", ctypes.c_char * 126),
("DriverReleaseVersion", ctypes.c_uint16),
]
def __str__(self):
return "Mfg: {}, Dev: {} HW: {}.{}.{}.{} Drv: {}.{}.{}.{}".format(
self.Manufacturer,
self.Description,
self.HardwareBranchVersion,
self.HardwareMajorVersion,
self.HardwareMinorVersion,
self.HardwareBuildVersion,
self.DriverReleaseVersion,
self.DriverMajorVersion,
self.DriverMinorVersion,
self.DriverBuildVersion
)
PVCIDEVICEINFO = ctypes.POINTER(VCIDEVICEINFO)
class CANLINESTATUS(ctypes.Structure):
_fields_ = [
("bOpMode", ctypes.c_uint8),
("bBtReg0", ctypes.c_uint8),
("bBtReg1", ctypes.c_uint8),
("bBusLoad", ctypes.c_uint8),
("dwStatus", ctypes.c_uint32)
]
PCANLINESTATUS = ctypes.POINTER(CANLINESTATUS)
class CANCHANSTATUS(ctypes.Structure):
_fields_ = [
("sLineStatus", CANLINESTATUS),
("fActivated", ctypes.c_uint32),
("fRxOverrun", ctypes.c_uint32),
("bRxFifoLoad", ctypes.c_uint8),
("bTxFifoLoad", ctypes.c_uint8)
]
PCANCHANSTATUS = ctypes.POINTER(CANCHANSTATUS)
class CANCAPABILITIES(ctypes.Structure):
_fields_ = [
("wCtrlType", ctypes.c_uint16),
("wBusCoupling", ctypes.c_uint16),
("dwFeatures", ctypes.c_uint32),
("dwClockFreq", ctypes.c_uint32),
("dwTscDivisor", ctypes.c_uint32),
("dwCmsDivisor", ctypes.c_uint32),
("dwCmsMaxTicks", ctypes.c_uint32),
("dwDtxDivisor", ctypes.c_uint32),
("dwDtxMaxTicks", ctypes.c_uint32)
]
PCANCAPABILITIES = ctypes.POINTER(CANCAPABILITIES)
class CANMSGINFO(ctypes.Union):
class Bytes(ctypes.Structure):
_fields_ = [
("bType", ctypes.c_uint8),
("bAddFlags", ctypes.c_uint8),
("bFlags", ctypes.c_uint8),
("bAccept", ctypes.c_uint8),
]
class Bits(ctypes.Structure):
_fields_ = [
("type", ctypes.c_uint32, 8),
("ssm", ctypes.c_uint32, 1),
("hi", ctypes.c_uint32, 2),
("res", ctypes.c_uint32, 5),
("dlc", ctypes.c_uint32, 4),
("ovr", ctypes.c_uint32, 1),
("srr", ctypes.c_uint32, 1),
("rtr", ctypes.c_uint32, 1),
("ext", ctypes.c_uint32, 1),
("afc", ctypes.c_uint32, 8)
]
_fields_ = [
("Bytes", Bytes),
("Bits", Bits)
]
PCANMSGINFO = ctypes.POINTER(CANMSGINFO)
class CANMSG(ctypes.Structure):
_fields_ = [
("dwTime", ctypes.c_uint32),
("dwMsgId", ctypes.c_uint32),
("uMsgInfo", CANMSGINFO),
("abData", ctypes.c_uint8 * 8)
]
PCANMSG = ctypes.POINTER(CANMSG)
class CANCYCLICTXMSG(ctypes.Structure):
_fields_ = [
("wCycleTime", ctypes.c_uint16),
("bIncrMode", ctypes.c_uint8),
("bByteIndex", ctypes.c_uint8),
("dwMsgId", ctypes.c_uint32),
("uMsgInfo", CANMSGINFO),
("abData", ctypes.c_uint8 * 8)
]
PCANCYCLICTXMSG = ctypes.POINTER(CANCYCLICTXMSG)
|