Go Down

Topic: HEX Split (Read 1 time) previous topic - next topic

PaulS

Quote
Idon't know how to make buf of my received char or dec or hex to asign it to Variable, this is my major problem.

Then, perhaps you should go back to where I suggested that you use sprintf() and start googling.

UKHeliBob

Have you written any code to do the data transmission using IR ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Xenon69

PaulS - Seems the sprintf() function is that what i want, but i can't find no one good example! :(


UKHeliBob  - Yes at this moment i just experimenting, and i have transmitting code. Where is conected 4 buttons and i can send 4 diferent codes with it.

But my general what i need is to seperate receiver incoming data.


For example if in transmitter i change first char, second char and third char (example - 486) then transmit it to receiver

then on receiver i need to seperate it and asign to variable.

received code = 486

asigning to variable


Variable1 = (First character = 4)
Variable2 = (Second character = 8)
Variable3 = (Third character = 6)

Looks very simple but no one can help me, yet!



Chaul

#18
Mar 10, 2013, 08:02 pm Last Edit: Mar 10, 2013, 09:18 pm by Chaul Reason: 1
I don't quite get this. I would assume that you are already sending the data as 8-bit characters. That's how your library most likely presents it anyways. I don't get where the number to string conversion comes in. Would be curious to see the code that you have for receiving and sending data.

If you now want to interpret the transmitted data from the hexadecimal representation into characters, then each "character" in that format represent 2 four-bit symbols, since it takes 4 bits to represent 16 values and hexadecimal happens to have 16 symbols. That's the easiest way of interpreting the hexadecimal representation to bits and back. You can take the high and low 4-bits to interpret what you have without the need for string to number and back to string conversions.

Then again, you could just as well be sending ASCII characters and interpret it as such unless you insist on saving that one half of a byte. So, ASCII character 1 could mark led 1, and so on, just to make it easy.

Edit: Oh, and you do realize that there is a difference between 'A' and 0xA? The first one is a character having a number value 65 in the ASCII character table and the latter is the hexadecimal (16-base) representation of the decimal (10-base) number 10.

UKHeliBob

I don't understand why you are combining the codes in the first place if you have written the transmitting code.  If you want to send, receive and act on several type of command such as steering, speed, lights on/ff then why not send simple individual commands to do it rather than combining several together which is more work at both ends.

By all means send a stream of commands one after the other but use a separator of some kind to make them easy to identify at the receiving end.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up