Byte format sending in Serial Port Class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajorge
    New Member
    • Oct 2008
    • 4

    Byte format sending in Serial Port Class

    Good Morning!

    I'm trying to send a few bytes through my serial port into a remote system, but i'm having a problem... Suposing that i'm trying to send the array of bytes:

    68, 00, 00, 68, 00, 00, 00, 00, 80, 00, 01, 81, 00, 16

    How to define this array?

    Like this?

    dim btArray as byte() = { &H68,&H00, &H00, &H68, &H00, &H00, &H00, &H00, &H80, &H00, &H01, &H81, &H00, &H16 }

    I've made a test and i saw that &HA = 10 ..., so this is not the way i want this to work. What's the way to get the correct convertion?

    Best regards.
  • joedeene
    Contributor
    • Jul 2008
    • 579

    #2
    I think you can just insert those numbers in the curly brackets and they are your bytes, in c# it would be like this:

    Code:
    byte[] mybytes = new byte[] { 68, 00, 00, 68, 00, 00, 00, 00, 80, 00, 01, 81, 00, 16 };
    I think you can do something like that? Try that and let me know if it doesn't work.

    joedeene

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      The &H in VB means the followin number is in hex, you appear to want decimals, so just go as joedeene suggested and enter them as:
      { 68, 00, 00, 68, 00, 00, 00, 00, 80, 00, 01, 81, 00, 16 }

      Comment

      • ajorge
        New Member
        • Oct 2008
        • 4

        #4
        Hi Joe!

        I've tryed to do what you've told. But there's a problem! Suppose that we put a byte AF inside this array... After compiling the code, is giving an error and don't let me to do what i want.

        The main objective is to guarantee that this sequence reaches the remote system:

        {01101000, 00000000, 00000000, 01101000, 00000000, 00000000, 00000000, 00000000, 10000000, 00000000, 00000001, 10000001, 00000000, 00010110}

        Originally posted by joedeene
        I think you can just insert those numbers in the curly brackets and they are your bytes, in c# it would be like this:

        Code:
        byte[] mybytes = new byte[] { 68, 00, 00, 68, 00, 00, 00, 00, 80, 00, 01, 81, 00, 16 };
        I think you can do something like that? Try that and let me know if it doesn't work.

        joedeene

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Well "AF" would be a HEX value so you would want to use the &h for those values.

          10 is 10
          0x10 is 16

          Comment

          Working...