12-04-2019 02:52 PM
Hello,
I want to take a character string and convert it to a hexadecimal byte array. So I can use the hex byte array for a EEPROM input. Does anyone have any ideas? Please let me know.
thanks
Joe
Solved! Go to Solution.
12-04-2019 02:57 PM
Can you give an example of the string and what you expect it to look like after?
12-04-2019 02:59 PM
There's a built-in function for converting a string to a byte array, but can you clarify what you mean by a "hexadecimal byte array"? Do you just mean an array of U8s (a.k.a. bytes), in which case "hexadecimal" doesn't apply, or do you mean another string consisting of pairs of characters representing each byte in hexadecimal?
12-04-2019 03:03 PM
It's always a Good Idea to attach some code where you try to solve your own problem. This helps us by (a) telling us which version of LabVIEW you use (but only if you attach an actual VI, not a picture of one), (b) letting us see what you tried, (c) suggest ways for you to "fix it yourself" (and hence "Learn LabVIEW", if you don't know it already), and (d) if there is a real Error, helps us to "trap it in action".
It also provides a hint of how long you've used LabVIEW and how "gentle" we should be.
You didn't provide any code, so I'm going to guess you know almost nothing about LabVIEW. You probably don't know how to open the Palettes on the Block Diagram and look for functions that might be suggestive (like one called "String to Byte Array"). You might not know how Strings are represented in LabVIEW.
Here's a suggestion. Open LabVIEW. Create an empty VI. Open its Block Diagram. Look at the String functions. Look for "String to Byte Array". Wire a String to its input, and wire an indicator to its output. Run it. Observe the Results. Now use this to do something "useful".
Bob Schor
12-04-2019 03:09 PM
sure... say it is a module number for example AF1234... i want to convert this into a hex byte array to save to an EEPROM.. then read it back from the EEPROM and convert it back to the string.. thanks for your help
12-04-2019 03:13 PM
Again, please clarify what you mean by a "hex byte array". An array of bytes isn't inherently hexadecimal, that's just one format among many for representing the values in the bytes.
12-04-2019 03:14 PM
I tried it this way but I dont think this is right
12-04-2019 03:44 PM
sorry for the confusion... I included the SPI write VI and where I want to replace the data bytes written from a string command.. thanks again for your help
12-04-2019 04:07 PM
Aha! Now we have some indication of what you are trying to do, namely get LabVIEW to communicate via SPI to some other device. If you had attached all of your code (the easiest way to have done that would be to compress the Folder that contained the entire LabVIEW Project and attach the resulting .ZIP file), we would have been better informed and those of us (which does not include myself) who have familiarity with I²C and SPI protocols could provide some real help.
I'd still suggest you attach the entire Project ...
Bob Schor
12-04-2019 04:26 PM
@joeross wrote:
I tried it this way but I dont think this is right
That looks correct to me. Something that might help you is to turn on the Radix on the numeric array (right-click, Visible Items->Radix). You can then click on the little "d" that shows up and choose "Hex". Now you will see the values in a Hexadecimal format instead of Decimal. You can do something similar on the string controls/indicators except is it "Display Style" instead of Radix.