|
|
View previous topic :: View next topic |
Author |
Message |
rhaguiuda
Joined: 05 Sep 2007 Posts: 46 Location: Londrina - Brazil
|
How to get a long sequence of hexa bytes? |
Posted: Tue Dec 30, 2008 10:50 am |
|
|
Hi..
In my application I receive a sequence of bytes (hexa) like this one via USART (RS232): 7E 00 00 01 00 00 0A
I need that my application capture these bytes and save them in a array.
I tryied to use getc, but didn't work.
Can someone post a code that makes this job?
Thanks a lot! |
|
|
Ttelmah Guest
|
|
Posted: Tue Dec 30, 2008 11:03 am |
|
|
Your problem, is probably understanding the data types involved.
If the data is arriving in hex, then there are _two_ characters for each byte. If they are raw binary data (not hex), then each charcater is binary, and would need to be converted to hex to output.
A single 'byte', can just hold one character. Each character (assuming 8bit transmission), can hold values from 0, to 255. Each single charaacter, can be _represented_ as two hex digits (or as 8 binary bits, or as three decimal digits, etc. etc.), but these are only _representations_ of the value.
Now, if you are receiving hex characters (common from a lot of instumentation), then you would need to combine _pairs_ of bytes, to actually work out the received value. Look at the 'gethex' function, in input.c. However if you are receiving raw data, and want then to output this as hex, you would need to convert the value into hex text, to display. Lok at the %x output format in printf.
So, your code almost certainly is working, you just need to realise, that what you are receiving, is not the text that you expected, or if it is text, this needs to be converted into numbers for use.
Best Wishes |
|
|
rhaguiuda
Joined: 05 Sep 2007 Posts: 46 Location: Londrina - Brazil
|
|
Posted: Tue Dec 30, 2008 11:15 am |
|
|
Ttelmah, thanks for helping me.
I'm receiving hexa data. Just like the example I'v wroted: 7E 7E 00 00 01 00 00 0A...
I'll take a look at 'gethex' function. I'll let you know if it works.
Thanks |
|
|
rhaguiuda
Joined: 05 Sep 2007 Posts: 46 Location: Londrina - Brazil
|
|
Posted: Tue Dec 30, 2008 11:22 am |
|
|
Ttelmah
One thing that I don't understand is how the USART really works.
If it receives a long sequence of chars (like the one i wrote before) it will interrupt in the reception of first char? Or it will create a interrupt for everychar it receives?
Anyway, I have to use the function getc once? or create a loop that verifies if there's a char to be read?
How would this code be?
Thanks |
|
|
Ttelmah Guest
|
|
Posted: Tue Dec 30, 2008 11:31 am |
|
|
It'll interrupt for each character.
Look at ex_sisr.c, for how to handle this.
Then the question comes. "What do you actually want to 'do' with the values"?. If you want to put these into an array as numeric values, then you need to use a function like gethex (already mentioned), to get the pairs, and convert these to numbers. If the strings are separated by spaces as shown, this simplifies things, since you can use this to ensure the byte pairs are synchronised.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|