Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SerialPort sp = (SerialPort)sender;
- while (sp.BytesToRead != 0)
- {
- byte startByte = (byte)sp.ReadByte();
- if (startByte == 0xEE)
- {
- Console.WriteLine("Start of Message");
- byte srcAdr = (byte)sp.ReadByte();
- if (srcAdr < (int)32) // There is only 32 nodes available on CAN
- {
- byte length = (byte)sp.ReadByte();
- if (length < (int)14) // Length will never exceed 14 bytes
- {
- byte[] message = new byte[length - 3];
- sp.Read(message, 0, length - 3);
- for (int i = 0; i < message.Length; i++)
- {
- Console.Write(message[i].ToString("X2") + " - ");
- }
- Console.WriteLine();
- }
- else
- {
- Console.WriteLine("Error: Length : " + length);
- }
- }
- else
- {
- Console.WriteLine("Error: Source address : " + srcAdr);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement