none
Byte Swapping "54h" command from Little Endian to Big endian using VB.NET RRS feed

  • Question

  • Hello everybody,

     

    I am trying to communicate with a Omega Instrument using serial port communication. Omega Instrument has Motorola Format and i am using VB.NET as programming language. I have to perform byte swapping and send command 54h to the Omega Instrument so that it will display RMT.

    Anybody has idea on how to do this on VB.net

    tHANKS

    vISHAL

    Thursday, October 20, 2011 7:18 PM

Answers

  • I know what big/little endian means in general, I only wasn't sure how to handle your example "54h". The endian is only relevant if you're sending Short, Integer or Long values. If you send a String, byte swapping does not make sense.

    Are you sure you don't have to send the byte with a hex value of 54? This would just be....:

         dim buffer(0) as byte

         buffer(0) = &H54

        com1.write(buffer, 0, 1)


    Armin
    • Marked as answer by Vishal Patel Thursday, October 20, 2011 8:24 PM
    • Unmarked as answer by Vishal Patel Thursday, October 20, 2011 8:24 PM
    • Marked as answer by Vishal Patel Thursday, October 20, 2011 8:24 PM
    Thursday, October 20, 2011 8:11 PM

All replies

  • If you have one byte, what do you want to swap?
    Armin
    Thursday, October 20, 2011 7:20 PM
  • Armin,

    I am not a professional programmer. But i understand that 54h is a command with three bytes : 53 52 104 in decimal value or 35 34 68 in Hex value.

    Now am using com1.write(byte, 0, length of byte) function to communicate with serial port. This means i have to swap the above three bytes so that Motorola Format instrument can understand it.

    How do i swap this three bytes ?

    Thanks

    Vishal

    Thursday, October 20, 2011 7:27 PM
  • Oh, I thought "h" is the suffix for hexadecimal (54 hex =84 dec).

    If you want to send the String "54h", I guess ASCII encoded, you can reverse the array:

          Dim enc = System.Text.Encoding.ASCII
    
          buffer = enc.GetBytes("54h")

    Array.Reverse(buffer) com1.Write(buffer, 0, buffer.Length)

    EDIT:
    I'm not sure if this is the kind of swapping required?!

    Armin


    Thursday, October 20, 2011 7:31 PM
  • I think it is IF it's encoded which I doubt.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me
    Thursday, October 20, 2011 8:05 PM
  • Armin,

    Thanks for your program.

    Your program makes perfect sense But, I tried this, it did not work, so i guess the byte swapping is something else.

    Byte Swapping is done between two different endian machines to communicate. In this case, my PC is little endian and my omega instrument is big endian, so i am going from little endian to big endian.

    I do not know why it is not working.

    Thank You

    Vishal

    Thursday, October 20, 2011 8:07 PM
  • Stick with it. OF course remember that "did not work" carries exactly one bit of information.

    You might start by show the code with your mode. Run your code through Word firsrt and then cut and paste it onto the board.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me
    Thursday, October 20, 2011 8:10 PM
  • I know what big/little endian means in general, I only wasn't sure how to handle your example "54h". The endian is only relevant if you're sending Short, Integer or Long values. If you send a String, byte swapping does not make sense.

    Are you sure you don't have to send the byte with a hex value of 54? This would just be....:

         dim buffer(0) as byte

         buffer(0) = &H54

        com1.write(buffer, 0, 1)


    Armin
    • Marked as answer by Vishal Patel Thursday, October 20, 2011 8:24 PM
    • Unmarked as answer by Vishal Patel Thursday, October 20, 2011 8:24 PM
    • Marked as answer by Vishal Patel Thursday, October 20, 2011 8:24 PM
    Thursday, October 20, 2011 8:11 PM
  • Armin,

    It worked. I had never tried this before, as i was always looking for byte swapping as mentioned in the manual for this instrument.

    Thank you for your help. cheers....

    -Vishal

    Thursday, October 20, 2011 8:26 PM