55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace BmsMonitor.App.Can;
|
|
|
|
internal static class ControlCanNative
|
|
{
|
|
internal const uint VciUsbCan2 = 4;
|
|
internal const uint StatusOk = 1;
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
internal struct VciInitConfig
|
|
{
|
|
public uint AccCode;
|
|
public uint AccMask;
|
|
public uint Reserved;
|
|
public byte Filter;
|
|
public byte Timing0;
|
|
public byte Timing1;
|
|
public byte Mode;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
internal struct VciCanObj
|
|
{
|
|
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;
|
|
}
|
|
|
|
[DllImport("ControlCAN.dll", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern uint VCI_OpenDevice(uint deviceType, uint deviceIndex, uint reserved);
|
|
|
|
[DllImport("ControlCAN.dll", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern uint VCI_CloseDevice(uint deviceType, uint deviceIndex);
|
|
|
|
[DllImport("ControlCAN.dll", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern uint VCI_InitCAN(uint deviceType, uint deviceIndex, uint canIndex, ref VciInitConfig config);
|
|
|
|
[DllImport("ControlCAN.dll", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern uint VCI_StartCAN(uint deviceType, uint deviceIndex, uint canIndex);
|
|
|
|
[DllImport("ControlCAN.dll", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern uint VCI_ResetCAN(uint deviceType, uint deviceIndex, uint canIndex);
|
|
|
|
[DllImport("ControlCAN.dll", CallingConvention = CallingConvention.StdCall)]
|
|
internal static extern uint VCI_Receive(uint deviceType, uint deviceIndex, uint canIndex,
|
|
[Out] VciCanObj[] receive, uint length, int waitTime);
|
|
}
|