07-13-2016 11:08 AM
Hey like the subject says I'm trying to convert a normal string to a hex string to send through a serial connection and having very little luck. First I tried one solution that involved breaking it up and converting to a number then to a string. This worked with the example that was given but would add random 0's with the string I used (the extra string view in the for loop was there for testing purposes while I was trying to figure out what was going on).
The second solution I found used the scan from string block in a for loop and, once again, worked with the example but returned a "Scan failed. The input string does not contain data in the expected format." error when I ran it with the type of string I intended to use.
Any help would be greatly appreciated. I can also explain why I need a vi to do this and how the input string will change if that could help. Thanks!
07-13-2016 11:13 AM
07-13-2016 11:16 AM
All I need is a vi that takes in a nomal string and returns that string in hex view. all of the serial communication is already handled by the vi's that would use this one.
07-13-2016 11:47 AM
Please expalin more about what you actually need the VI to return.
My brain hurst trying to get past an string control wired to a string indicator with the latter set to display as hex (which would satify your stated needs).
Try...
String wired to "String to Byte Array" wired to "Number to Hexidecimal string" wired to sinlge input "Concantenate String" wired to an indicator?
Ben
07-13-2016 12:05 PM - edited 07-13-2016 12:11 PM
Here is what I created based on your instructions. This returns the inputed string translated into hex, which is simular to what happens when you just change the display type to hex.
What I need the VI to return is the input string formatted to display in hex properly. When I just send the string over serial it converts it to hex, as it should, when what I really need is the string itself to be sent, because it represents the hex that needs to be sent. (see crappy ms paint diagram below)
07-13-2016 12:11 PM
So.... just sending the string unmolested is somehow wrong?
Strings are simply byte arrays formatted for display as strings.
Sorry but I am at a loss as to how to help you.
Please help us understand what you need so we can help you.
Ben
07-13-2016 12:18 PM - edited 07-13-2016 12:18 PM
Use a for loop on the array of strings coming from the "format as hex" and append a "space" everytime the loop index +1 is divisable by 4 (see quotient remainder function).
07-13-2016 12:22 PM
@maland2 wrote:Here is what I created based on your instructions. This returns the inputed string translated into hex, which is simular to what happens when you just change the display type to hex.
What I need the VI to return is the input string formatted to display in hex properly. When I just send the string over serial it converts it to hex, as it should, when what I really need is the string itself to be sent, because it represents the hex that needs to be sent. (see crappy ms paint diagram below)
This image does not make sense. You can not have a small "h" ever show up in a string set for hex display. Only the characters 0-9 and A-F
07-13-2016 12:25 PM
Sorry i'm new to labview and trying my best to explain what I need. See the diagram i added above and check out this thread here: http://forums.ni.com/t5/LabVIEW/convers-ascii-string-to-hex-string/td-p/569834
Here's the whole story. (Note: using the word compiled as in put together not like compile code) I have to compile a command to send it over serial to a device. The command is 26 bytes long and is compiled as a string of ascii characters that is in hex. When I say in hex I mean the string literally is hex, not that it is numbers displaying as hex. The problem is when I try to send that string along over serial, the first thing it does is convert the ASCII characters into hex numbers and then sends it, which is useless because the string was the hex characers to begin with. That conversion that it does is the equivalent of changing the display type from string normal to string hex. What I need is some process that takes the ascii string and makes it so that when that string is displayed as hex it displayes exactly as it looks in the original string. The diagram below tries to demonstrate what I mean.
07-13-2016 12:27 PM
My apologies the 'h' was a mistake, you can ignore it.