public void Post(CanFrame frame) { using (CanRaw can = new CanRaw()) { can.WriteFrame(frame); } }
public static void WriteFrame(this CanRaw can, CanFrame frame) { var canId = new CanId(); canId.RemoteTransmissionRequest = frame.RemoteRequest; if (frame.FrameFormat == FrameFormat.Extended) { canId.ExtendedFrameFormat = true; canId.Extended = frame.Address; } else { canId.ExtendedFrameFormat = false; canId.Standard = frame.Address; } byte[] data = new byte[frame.DLC]; Array.Copy(frame.Data, data, frame.DLC); can.WriteFrame(data, canId); }
private static void SendExample() { Console.WriteLine($"Sending to id = 0x{Id.Value:X2}"); using (CanRaw can = new CanRaw()) { byte[][] buffers = new byte[][] { new byte[8] { 1, 2, 3, 40, 50, 60, 70, 80 }, new byte[7] { 1, 2, 3, 40, 50, 60, 70 }, new byte[0] { }, new byte[1] { 254 }, }; if (!Id.IsValid) { // This is more form of the self-test rather than actual part of the sample throw new Exception("Id is invalid"); } while (true) { foreach (byte[] buffer in buffers) { can.WriteFrame(buffer, Id); string dataAsHex = string.Join(string.Empty, buffer.Select((x) => x.ToString("X2"))); Console.WriteLine($"Sending: {dataAsHex}"); Thread.Sleep(1000); } } } }