Answered by:
Byte Swapping "54h" command from Little Endian to Big endian using VB.NET

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
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
All replies
-
-
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
-
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
- Edited by Armin Zingler Thursday, October 20, 2011 7:33 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- Edited by Renee Culver Thursday, October 20, 2011 8:07 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 YouVishal
-
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- Edited by Renee Culver Thursday, October 20, 2011 8:14 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
-