Hello!
I have a question.
I want to transmit the decimal number 371234 as a 3-byte hexadecimal number through serial communication.
How should I send it?
Thank you for always.
hexadecimal number send serial communication
-
- Posts: 206
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 03, 2020 1:43 pm
- Has thanked: 5 times
- Been thanked: 7 times
-
- Matrix Staff
- Posts: 1472
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 204 times
- Been thanked: 349 times
Re: hexadecimal number send serial communication
If you are in control of both sides of the communication, just send it as a number and then convert it on the other side when you want to display it.
But if it needs to be send as a hex string, then use the "NumberToHex" calculation function. This will convert it to "0x0005aa22" and so you may need to trim some of the prefix characters depending on the format you require.
But if it needs to be send as a hex string, then use the "NumberToHex" calculation function. This will convert it to "0x0005aa22" and so you may need to trim some of the prefix characters depending on the format you require.
Re: hexadecimal number send serial communication
Thanks for your help.
It is output in the form of 0x123456 using Numbertohex, but it is a string. I want to send this as UART(RS232) - send number hexadecimal 0x123456
It is output in the form of 0x123456 using Numbertohex, but it is a string. I want to send this as UART(RS232) - send number hexadecimal 0x123456
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 503 times
- Been thanked: 686 times
Re: hexadecimal number send serial communication
Hello,
If you're sending it as raw binary data then you would do something like this, assuming you're sending the least significant byte first.
LongNumber = 371234
UART::SendChar (LongNumber)
LongNumber = LongNumber >> 8
UART::SendChar (LongNumber)
LongNumber = LongNumber >> 8
UART::SendChar (LongNumber)
This would send the number as three binary bytes.
Binary, Decimal and Hexadecimal are simply different ways of representing a value via a human readable string, in each case the value itself doesn't change.
If you're sending it as raw binary data then you would do something like this, assuming you're sending the least significant byte first.
LongNumber = 371234
UART::SendChar (LongNumber)
LongNumber = LongNumber >> 8
UART::SendChar (LongNumber)
LongNumber = LongNumber >> 8
UART::SendChar (LongNumber)
This would send the number as three binary bytes.
Binary, Decimal and Hexadecimal are simply different ways of representing a value via a human readable string, in each case the value itself doesn't change.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel