hexadecimal number send serial communication

For general Flowcode discussion that does not belong in the other sections.
Post Reply
seokgi
Posts: 165
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 1:43 pm
Has thanked: 5 times
Been thanked: 6 times

hexadecimal number send serial communication

Post by seokgi »

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.

Steve-Matrix
Matrix Staff
Posts: 1234
Joined: Sat Dec 05, 2020 10:32 am
Has thanked: 167 times
Been thanked: 277 times

Re: hexadecimal number send serial communication

Post by Steve-Matrix »

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.

seokgi
Posts: 165
Joined: Thu Dec 03, 2020 1:43 pm
Has thanked: 5 times
Been thanked: 6 times

Re: hexadecimal number send serial communication

Post by seokgi »

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

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: hexadecimal number send serial communication

Post by BenR »

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.

seokgi
Posts: 165
Joined: Thu Dec 03, 2020 1:43 pm
Has thanked: 5 times
Been thanked: 6 times

Re: hexadecimal number send serial communication

Post by seokgi »

Thanks for your help, I solved it well.

Post Reply