コード例 #1
0
ファイル: NativeCAN.cs プロジェクト: ThadHouse/FRCCANReader
        public NativeCAN()
        {
            handle = FRC_CAN_Reader_Native_Create();

            readThread = new Thread(() =>
            {
                var eventHandle = FRC_CAN_Reader_Native_GetEventHandle(handle);
                while (true)
                {
                    int dataLen = 0;
                    if (WPI_WaitForObjectTimeout(eventHandle, 1, &dataLen) != 0)
                    {
                        dataLen           = 0;
                        CANData *messages = FRC_CAN_Reader_Native_ReadMessages(handle, &dataLen);
                        if (messages == null)
                        {
                            continue;
                        }
                        for (int i = 0; i < dataLen; i++)
                        {
                            CANData data    = messages[i];
                            ulong ulongData = Unsafe.ReadUnaligned <ulong>(data.data);
                            CANMessageReceived?.Invoke((uint)data.id, ulongData, data.length, (uint)data.timestamp);
                        }
                    }
                }
            });
            readThread.IsBackground = true;
            readThread.Name         = "CAN Managed Reader";
            readThread.Start();
        }
コード例 #2
0
ファイル: NativeCAN.cs プロジェクト: ThadHouse/FRCCANReader
 private static extern unsafe CANData *FRC_CAN_Reader_Native_FreeMessages(CANData *data, int dataLen);