// CAN data receive function protected void RecvDataFunc() { ZCAN_Receive_Data[] can_data = new ZCAN_Receive_Data[100]; ZCAN_ReceiveFD_Data[] canfd_data = new ZCAN_ReceiveFD_Data[100]; uint len; while (m_bStart) ...
// CAN data receive function protected void RecvDataFunc() { ZCAN_Receive_Data[] can_data = new ZCAN_Receive_Data[100]; ZCAN_ReceiveFD_Data[] canfd_data = new ZCAN_ReceiveFD_Data[100]; uint len; while (m_bStart) { lock (locker) { len = Method.ZCAN_GetReceiveNum(channel_handle_, TYPE_CAN); if (len > 0) { int size = Marshal.SizeOf(typeof(ZCAN_Receive_Data)); IntPtr ptr = Marshal.AllocHGlobal((int)len * size); len = Method.ZCAN_Receive(channel_handle_, ptr, len, 50); for (int i = 0; i < len; ++i) { can_data[i] = (ZCAN_Receive_Data)Marshal.PtrToStructure( (IntPtr)((UInt32)ptr + i * size), typeof(ZCAN_Receive_Data)); } OnRecvCANDataEvent(can_data, len); Marshal.FreeHGlobal(ptr); } len = Method.ZCAN_GetReceiveNum(channel_handle_, TYPE_CANFD); if (len > 0) { int size = Marshal.SizeOf(typeof(ZCAN_ReceiveFD_Data)); IntPtr ptr = Marshal.AllocHGlobal((int)len * size); len = Method.ZCAN_ReceiveFD(channel_handle_, ptr, len, 50); for (int i = 0; i < len; ++i) { canfd_data[i] = (ZCAN_ReceiveFD_Data)Marshal.PtrToStructure( (IntPtr)((UInt32)ptr + i * size), typeof(ZCAN_ReceiveFD_Data)); } OnRecvFDDataEvent(canfd_data, len); Marshal.FreeHGlobal(ptr); } } Thread.Sleep(10); } }