Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Quick quest

Quick quest

Scheduled Pinned Locked Moved C#
announcement
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gwithey
    wrote on last edited by
    #1

    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;

    M C 2 Replies Last reply
    0
    • G gwithey

      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;

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      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.

      G 1 Reply Last reply
      0
      • M musefan

        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.

        G Offline
        G Offline
        gwithey
        wrote on last edited by
        #3

        Ah im just using it to check that i have recieved the correct number of bytes. If there are more than three bytes in the recieved array then something is wrong throwing an exception. In other words checking nothing follows the Version number request

        1 Reply Last reply
        0
        • G gwithey

          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;

          C Offline
          C Offline
          c0ax_lx
          wrote on last edited by
          #4

          switch (rxMessage[2]) <- change to rxMessage[1] since arrays starts at 0. rgds Tomas

          If it' stuck, DO NOT pull harder!

          G 1 Reply Last reply
          0
          • C c0ax_lx

            switch (rxMessage[2]) <- change to rxMessage[1] since arrays starts at 0. rgds Tomas

            If it' stuck, DO NOT pull harder!

            G Offline
            G Offline
            gwithey
            wrote on last edited by
            #5

            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"); }

            C 1 Reply Last reply
            0
            • G gwithey

              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"); }

              C Offline
              C Offline
              c0ax_lx
              wrote on last edited by
              #6

              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!

              G 1 Reply Last reply
              0
              • C c0ax_lx

                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!

                G Offline
                G Offline
                gwithey
                wrote on last edited by
                #7

                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

                M 1 Reply Last reply
                0
                • G gwithey

                  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

                  M Offline
                  M Offline
                  musefan
                  wrote on last edited by
                  #8

                  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 message

                  then 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.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups