LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Normal String Display to Hex String Display

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). 

Solution 1 (blockview)Solution 1 (viview)

 

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. 

Solution 2 (blockview).JPGSolution 2 (viview).JPG

 

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!

Message 1 of 16
(10,470 Views)
Do you want to convert and send to any device for communication or just you need to see the converted value?

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
Message 2 of 16
(10,464 Views)

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.

0 Kudos
Message 3 of 16
(10,460 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 16
(10,435 Views)

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.

Solution 3 (blockview).JPGSolution 3 (viview).JPG

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)

Diagram.png

0 Kudos
Message 5 of 16
(10,422 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 16
(10,416 Views)

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).

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 16
(10,406 Views)

@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.

Solution 3 (blockview).JPGSolution 3 (viview).JPG

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)

Diagram.png


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

Message 8 of 16
(10,398 Views)

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.

Diagram.png

0 Kudos
Message 9 of 16
(10,396 Views)

My apologies the 'h' was a mistake, you can ignore it.

0 Kudos
Message 10 of 16
(10,392 Views)