Hello i made a labview program which sends 8 bytes of data, an i stored the data to a string array .
The String array looks like : {"FF" , "7 " , "A "} for example
I want to transform the string array to a byte array that would look like : {"0xFF", "0x07" , "0x0A"}
How can i do that?
I want to transform the string array to a byte array that would look like : {"0xFF", "0x07" , "0x0A"}
That is not a byte array.
Do you mean
{0xFF, 0x07, 0x0A};
By the way, you have used the words String and string in your post. They are not the same thing.
Yes, without quotes, I'm sorry, my mistake. I'm refering to String .This is how you declare a string type in arduino.
bogdanfarmore:
This is how you declare a string type in arduino.
Absolutely NOT That's how you declare a (troublesome) String. You can use normal C strings
Let me be more clear , I need a string array. Not just a string. In C would be a char array . I used the "String" keyword because this seemed the only solution for what i wanted, a string array.
I used the "String" keyword because this seemed the only solution for what i wanted, a string array.
A String and a string are NOT the same thing. Quit writing this crap like they are the same thing.
You have an array of Strings. There are three elements in the array. How many elements do you want in the byte array?
Since the first String is "FF", what value do you want in the byte array?
Why is the data in an array of Strings now? Is it just laziness or incompetence, or is there some VALID reason?
Sorry for missunderstandings . I made a labview program which sends data through serial port . I have 8 bytes , so 8 values . I used the String object to be able to store FF as a single element, not two .Then in arduino i want to take these 8 bytes and pass them to a function which only accept byte array as argument .
In the byte array i want the equivalent hex values (FF)
I made a labview program which sends data through serial port . I have 8 bytes , so 8 values .
Labview sends ASCII or binary data. It does NOT send String objects. You have a choice of how to send the data. If you need it in binary, send it in binary. It is a waste of effort to convert the binary value that labview has to a string in hex format and then have to convert that string back back to a binary value. It is even worse to wrap the string in a String instance.
You need to unwrap the string from the String instance, and call strtoul() on the string to get the byte value.
In the byte array i want the equivalent hex values (FF)
If the target is an array of bytes and the source is "FF" then I assume that you want {255} in the target.
Bear in mind that HEX is only a way of representing the value of a byte in a way that is easier for humans to read than binary. An 8 bit byte may be said to hold 0b11111111, 0xFF or 255 and it will still have the same value.
Thank you @PaulS . I modified my labview code to send the equivalent characters of the binary data.Now I'll look for some informations about using strtoul.
@UKHeliBob I'm aware of that. My labview program was sending the "FF" Ascii characters and i was interested by the value .
My labview program was sending the "FF" Ascii characters and i was interested by the value .
So you wanted "FF" converted to 255, but what do you mean by
I modified my labview code to send the equivalent characters of the binary data.
What is it sending now instead of "FF" ?
I had FF as characters before, not the binary value 255/0xb11111111.
It's sending a character whose binary value is FF now.
It's sending a
characterbyte whose binary value is FF now.
Sending ASCII is indeed a bit wasteful but it does give you room to actually detect the beginning and end of a transmission. Using hex ASCII representation would be an okay choice. You can use strtoul() or something to convert it back.
But what is LabView sending as a whole?
Did you read Robin2's updated serial input basics?