コード例 #1
0
 private static void ReceiveLoop()
 {
     using (CanRaw can = new CanRaw())
     {
         CanFrame frame;
         while (true)
         {
             if (can.TryReadFrame(out frame))
             {
                 receivedFrames.Enqueue(frame);
             }
         }
     }
 }
コード例 #2
0
        private static void ReceiveAllExample()
        {
            Console.WriteLine("Listening for any id");

            using (CanRaw can = new CanRaw())
            {
                byte[] buffer = new byte[8];

                while (true)
                {
                    if (can.TryReadFrame(buffer, out int frameLength, out CanId id))
                    {
                        Span <byte> data      = new Span <byte>(buffer, 0, frameLength);
                        string      type      = id.ExtendedFrameFormat ? "EFF" : "SFF";
                        string      dataAsHex = string.Join(string.Empty, data.ToArray().Select((x) => x.ToString("X2")));
                        Console.WriteLine($"Id: 0x{id.Value:X2} [{type}]: {dataAsHex}");
                    }
コード例 #3
0
        public static bool TryReadFrame(this CanRaw can, out CanFrame frame)
        {
            var buffer  = new byte[8];
            var success = can.TryReadFrame(buffer, out int frameLength, out CanId id);

            frame = new CanFrame()
            {
                Data          = new Span <byte>(buffer, 0, frameLength).ToArray(),
                Address       = id.Value,
                ErrorFrame    = id.Error,
                FrameFormat   = id.ExtendedFrameFormat ? FrameFormat.Extended : FrameFormat.Standard,
                RemoteRequest = id.RemoteTransmissionRequest,
                DLC           = (byte)frameLength
            };

            return(success);
        }