Quick quest
-
Just wondering as rxMessage is looking at the 3rd byte not the second am I right putting : switch (rxMessage[2]) { case 0x56: // "V" Version Number Request if (rxMessage.Length == 3) { rxCommmandType = commandType.VersionNumRequest; } else { throw new IndexOutOfRangeException("Inavlid data entered, " + "Incorect number of bytes for a display update"); } break;
-
Just wondering as rxMessage is looking at the 3rd byte not the second am I right putting : switch (rxMessage[2]) { case 0x56: // "V" Version Number Request if (rxMessage.Length == 3) { rxCommmandType = commandType.VersionNumRequest; } else { throw new IndexOutOfRangeException("Inavlid data entered, " + "Incorect number of bytes for a display update"); } break;
I don't quite know what you are trying to do but one thing that stands out is you are checking to see if the array length is big enough after you access the data. If you want to check if it is available to access then do it before the switch.
Life goes very fast. Tomorrow, today is already yesterday.
-
I don't quite know what you are trying to do but one thing that stands out is you are checking to see if the array length is big enough after you access the data. If you want to check if it is available to access then do it before the switch.
Life goes very fast. Tomorrow, today is already yesterday.
-
Just wondering as rxMessage is looking at the 3rd byte not the second am I right putting : switch (rxMessage[2]) { case 0x56: // "V" Version Number Request if (rxMessage.Length == 3) { rxCommmandType = commandType.VersionNumRequest; } else { throw new IndexOutOfRangeException("Inavlid data entered, " + "Incorect number of bytes for a display update"); } break;
-
switch (rxMessage[2]) <- change to rxMessage[1] since arrays starts at 0. rgds Tomas
If it' stuck, DO NOT pull harder!
byte 0 and one are filled i didnt add this code because it would have crowded the message <code> // COMMAND HEADER if (rxMessage[0] != (byte)'J') { throw new InvalidDataException("Error: Invalid Command Header found"); } // MCU TYPE if (rxMessage[1] != (byte)DEVICE_ID) { throw new InvalidDataException("Error: Invalid Device ID"); }
-
byte 0 and one are filled i didnt add this code because it would have crowded the message <code> // COMMAND HEADER if (rxMessage[0] != (byte)'J') { throw new InvalidDataException("Error: Invalid Command Header found"); } // MCU TYPE if (rxMessage[1] != (byte)DEVICE_ID) { throw new InvalidDataException("Error: Invalid Device ID"); }
-
Ok. i cant say i really understand your question, but rxMessage[2] is the 3'rd byte if that's what you're asking. MCU's are cool btw. i use AVR's alot :)
If it' stuck, DO NOT pull harder!
-
thats kwl thanx. The question was just to check that if i was in array[2] it would be containing three values. So array.length should equal three or it is invalid so sure its right
just because you are accessing index 2 of the array it does not mean the length is three. If you can access index 2 without an array then there are at least 3 values. what you should do is first check the length...
if(array.Length != 3)
//not correct version request messagethen do your switch... I assume that index 3 tells what type of request it is and should always be present?
Life goes very fast. Tomorrow, today is already yesterday.