#region CAN接受和发送数据定义
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
public struct PVCI_CAN_OBJ
{
public uint ID;
public uint TimeStamp;
public byte TimeFlag;
public byte SendType;
public byte RemoteFlag;
public byte ExternFlag;
public byte DataLen;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] data;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] Reserved;
}
#endregion
#region 其他CAN函数数据定义
public struct PVCI_ERR_INFO
{
public uint ErrCode;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] Passive_ErrData;
public byte ArLost_ErrData;
}
public struct _VCI_BOARD_INFO
{
public ushort hw_Version;
public ushort fw_Version;
public ushort dr_Version;
public ushort in_Version;
public ushort irq_Num;
public byte can_Num;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
public byte[] str_Serial_Num;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)]
public byte[] str_hw_Type;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public ushort[] Reserved;
}
#endregion
#region DLL连接
//调用接受设备动态连接库
[DllImport("ControlCAN.dll", EntryPoint = "VCI_Receive", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern uint VCI_Receive(int DevType, int DevIndex, int CANIndex, [Out] PVCI_CAN_OBJ[] pReceive, uint Len, int WaitTime);
//调用报错动态连接库
[DllImport("ControlCAN.dll", EntryPoint = "VCI_ReadErrInfo", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int VCI_ReadErrInfo(int DevType, int DevIndex, int CANIndex, PVCI_ERR_INFO pErrInfo);
/*关闭设备连接库*/
[DllImport("ControlCAN.dll", EntryPoint = "VCI_CloseDevice", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern bool VCI_CloseDevice(int DevType, int DevIndex);
/*CAN启动CAN连接库*/
[DllImport("ControlCAN.dll", EntryPoint = "VCI_StartCAN", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int VCI_StartCAN(int DevType, int DevIndex, int CANIndex);
/*CAN发送连接库*/
[DllImport("ControlCAN.dll", EntryPoint = "VCI_Transmit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern uint VCI_Transmit(int DevType, int DevIndex, int CANIndex, PVCI_CAN_OBJ[] pSend, uint Len);
#endregion