protected void Task_ZlgClearReceiveBuffer() { ZCAN_Receive_Data[] can_data = new ZCAN_Receive_Data[10]; ZCAN_ReceiveFD_Data[] canfd_data = new ZCAN_ReceiveFD_Data[10]; uint len; Thread.Sleep(1000); len = Method.ZCAN_GetReceiveNum(VAR_ZlgUsbCanChannelHandle, 0); // TYPE_CAN Console.WriteLine("ZLG USBCAN archived CAN frames are: " + len.ToString()); ...
protected void Task_ZlgClearReceiveBuffer() { ZCAN_Receive_Data[] can_data = new ZCAN_Receive_Data[10]; ZCAN_ReceiveFD_Data[] canfd_data = new ZCAN_ReceiveFD_Data[10]; uint len; Thread.Sleep(1000); len = Method.ZCAN_GetReceiveNum(VAR_ZlgUsbCanChannelHandle, 0); // TYPE_CAN Console.WriteLine("ZLG USBCAN archived CAN frames are: " + len.ToString()); if (len > 0) { int size = Marshal.SizeOf(typeof(ZCAN_Receive_Data)); IntPtr ptr = Marshal.AllocHGlobal((int)len * size); len = Method.ZCAN_Receive(VAR_ZlgUsbCanChannelHandle, ptr, len, 50); //for (int i = 0; i < len; ++i) //{ // // Drop the message // can_data[0] = (ZCAN_Receive_Data)Marshal.PtrToStructure( // (IntPtr)((Int64)ptr + i * size), typeof(ZCAN_Receive_Data)); //} // OnRecvCANDataEvent(can_data, len); Marshal.FreeHGlobal(ptr); } len = Method.ZCAN_GetReceiveNum(VAR_ZlgUsbCanChannelHandle, 1); // TYPE_CANFD Console.WriteLine("ZLG USBCAN archived CAN-FD frames are: " + len.ToString()); if (len > 0) { int size = Marshal.SizeOf(typeof(ZCAN_ReceiveFD_Data)); IntPtr ptr = Marshal.AllocHGlobal((int)len * size); len = Method.ZCAN_ReceiveFD(VAR_ZlgUsbCanChannelHandle, ptr, len, 50); //for (int i = 0; i < len; ++i) //{ // // Drop the message // canfd_data[0] = (ZCAN_ReceiveFD_Data)Marshal.PtrToStructure( // (IntPtr)((Int64)ptr + i * size), typeof(ZCAN_ReceiveFD_Data)); //} // OnRecvCANDataEvent(can_data, len); Marshal.FreeHGlobal(ptr); } Thread.Sleep(10); }