//2.定义CAN信息帧的数据类型。
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct VCI_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, ArraySubType = UnmanagedType.I1)]
public byte[] Data;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3, ArraySubType = UnmanagedType.I1)]
public byte[] Reserved;
}
[DllImport("ControlCAN.dll", EntryPoint = "VCI_Receive", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern uint VCI_Receive(uint DeviceType, uint DeviceInd, uint CANInd, ref VCI_CAN_OBJ pReceive, uint Len, int WaitTime);
CANApi.VCI_CAN_OBJ[] frameInfos = new CANApi.VCI_CAN_OBJ[50];
len = (int)CANApi.VCI_Receive(3, 0, 0, ref frameInfos[0], 50, 200);
if (len <= 0)
{ CANApi.VCI_ReadErrInfo(3, 0, 0, ref errInfo);
}运行程序可以读取并返回一条数据
public static extern uint VCI_Receive(uint DeviceType, uint DeviceInd, uint CANInd, ref VCI_CAN_OBJ pReceive, uint Len, int WaitTime);是将这部分重新定义吗?[DllImport("ControlCAN.dll", EntryPoint = "VCI_Receive", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern uint VCI_Receive(uint DeviceType, uint DeviceInd, uint CANInd, out VCI_CAN_OBJ[] pReceive, uint Len, int WaitTime);
这样