Click here to Skip to main content
15,847,902 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i had below Hex value from serial Rx pin.

006900730020006D0065007300730061006700650020007700610073002000730065006E007400200074006F00200079006F0075002000620079002000310030002D0053007400720069006B00650020004E006500740077006F0072006B0020004D006F006E00690074006F007200200066006F007200200074006800650020


How store it in to String variable as ASCII type?

What I have tried:

i tried this way. but not success

C++
loop(){
 String d,full_time ;
  char c ;
  while ( Serial1.available() ) {
    c = Serial1.read();
    d += c;
  }
 
  full_time = (String) strtol( &d[1], NULL, 16);
}
Posted
Updated 19-Feb-16 11:31am
v2
Comments
Patrice T 19-Feb-16 14:19pm    
This piece of code have nothing to do with hex to ASCII conversion.
Sergey Alexandrovich Kryukov 19-Feb-16 14:46pm    
The question, strictly speaking, makes no sense. You are not talking about numbers (a number cannot be hexadecimal or decimal), you are talking about string -> string function, but it can make sense only if you know how to interpret the string. You have the sample, but the sample is not a spec. What is supposed to be interpret as a character? Say, first two characters can be 0x00 and 0x69, or they could be 0x60 and 0x73 (4 characters per number). The problem is very simple, but you are doing it wrong. You should read characters representing one output character by groups, say, of 2 or 4.
—SA
Sergey Alexandrovich Kryukov 19-Feb-16 14:51pm    
What is this language? What is String? You have to tag it. Function loop() without return type, even void? += operation for char? But ctrtol line in C/C++? What is it?
—SA
CPallini 19-Feb-16 16:36pm    
See here:
https://www.arduino.cc/en/Reference/HomePage
Sergey Alexandrovich Kryukov 19-Feb-16 17:53pm    
Thank you, but this page does not tell me what is the language in the samples; it's assumed that the reader knows it. I know that Arduino can be programmed in different languages; and this one looks like C (and at least I can see where is "String") :-)

Still, "loop() {/* ... */}" does not seem to be right syntax which can compile. In a sample, it's just "void loop() {/* ... */}"; and this is what I indicated in my comment:
"Function loop() without return type, even void?"
And still: "d += c;" ?!!!

—SA

Please see my comments to the question.

You are doing it wrong. You cannot do d += c;, you have to have a string, or, better, fixed-size array (giving a room for 2 or 4 characters) and fill it with input characters in an inner cycle. On each iteration of inner cycle, parse the string defined by this array (you may need to add closing zero) into a byte value of ASCII code point.

Some uncertainty comes from the fact that it's not known what is your language and what libraries you are using or can use — please see my second comment. :-)
But I hope you can grasp the idea.

—SA
 
Share this answer
 
Comments
CPallini 19-Feb-16 15:55pm    
5.
Sergey Alexandrovich Kryukov 19-Feb-16 16:03pm    
Thank you, Carlo.
—SA
Your arduino board is receiveing somthing like:
"is message was sent to you by 10-Strike Network Monitor for the "

probably encode as UTF-16. Since it is just a piece of the message it is difficult to understand the byte order (big or little endian).
Empirically, you may build your string using just the 2nd,4th,6th.. characters, i.e.
loop(){
 String message;
  char c ;
  int count = 0;
  while ( Serial1.available() ) {
    c = Serial1.read();
    if (count % 2) message += c;
    count++;
  } 
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Feb-16 18:28pm    
Sure, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900