Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

manipulating hex string/reformatting

I have to take a numeric value (ex. 1000), convert to a hex string with width of 8 digits, parse the string into a set of 4 2-digit hex numbers, reverse the order of the numbers, then put back into a hex string command to send out of a serial port.
 
I run into a road block on how to do this after I have parsed my hex number.  I cannot find a way to turn this back into a hex string after I have swapped my strings.
 
Ex:
 
1000 is converted to a hex value of 000F4240.  The hex value is split into 4 sets  (00 0F 42 40), then the order will be reversed (40 42 0F 00) and inserted into another hex string that makes up a command (01 12 15 02 00 02 01 01 40 42 0F 00 .... 3 more sets of transformed data....04).
 
The only way I see that I can take these hex values and concatenate them into a single hex string to send serially is to pass the ascii characters (ex. @ B SI NULL) into a string with a hex display.  However, I can't convert to the ascii characters.
 
Any better ways to do this or a way to do it at all??
0 Kudos
Message 1 of 9
(5,484 Views)
Hi dawnw,

I have looked into the example you described and I am coming up with values that are different from what you have mentioned provided. I have a feeling this is because I may be using different functions to accomplish this. Would it be possible to post your segment of code that does what you are describing. This will help me figure out what would need to be modified. Thanks!

Best regards,

Steven
0 Kudos
Message 2 of 9
(5,462 Views)
I have since figured it out through trial and error and looking at other posts.  If anyone is interested in what I did, I can post.  Just let me know.
0 Kudos
Message 3 of 9
(5,457 Views)
Hi dawnw!

I have exactly the same problem.. so I would be very grateful if you could post your solution.

Best regards,
Beata
0 Kudos
Message 4 of 9
(5,415 Views)
I am not quite sure what algorithm dawnw used, but I would suggest converting the number to a hexadecimal string, then manually transposing the characters that represent each byte. I've attached a simple example VI that performs this algorithm (written in LabVIEW 8.2). Please let me know if this accomplishes your goal! Thanks,

Mike D.
National Instruments
Applications Engineer
0 Kudos
Message 5 of 9
(5,394 Views)

Hello, dawnw,

 

I am battling with exactly the same problem here... could you post your solution, please?

I am trying to concatenate a string of hex values (00 02 04 A0 ...) with an ASCII string of hex characters (0C0D...)

It seems like a rather straightforward thing to do, but no matter what I did, one of the sttrings is converted wrong.

 

Thanks!

 

 

0 Kudos
Message 6 of 9
(4,777 Views)

Hello, could you post your code and tell us how the result is wrong? you can check out this thread as well, you just be displaying the wrong format?

 

http://forums.ni.com/ni/board/message?board.id=170&message.id=203490&requireLogin=False

 

Thanks,

National Instruments
0 Kudos
Message 7 of 9
(4,753 Views)

Hello,

 

I think it's not just a display issue... because the ASCII string is the output of "Number to Hex String" vi, so if I change it's display to hex, I see the hex values of the characters themselves, which is not what I want. On the other hand, the result of the concatenation has to go to a "Serial Write" block, so it has to be in hex display. 

 

Here's my vi, and an example: I need the hex equivalent of 2000, which is  000007D0, to be concatenated with a constant hex display string 0004 000D 15.

So it would look 0004 000D 1500 0007 D0

But it's not what I'm getting. 

 

Anyhow, I thought it was a very long shot to post to this thread (now I see I was wrong...), so I opened another one... and got a solution suggestion that works:

 

http://forums.ni.com/ni/board/message?board.id=170&message.id=436312#M436312

 

 

But I 'd surely like to know if there is a faster way...

Thank you for you time 🙂

 

Michal 

0 Kudos
Message 8 of 9
(4,747 Views)

Hi Michal,

 

This  is a classic problem of the difference between converting to Hexadecimal strings and flatteing data to a string.  

 

The first method will create an ASCII string with Hex letters as each character.  The second method will take any kind of data and without converting the actual bits, simply changing the data type to string.  Both are correct ways of doing things, but you cannot mix and match the two.  Try one of the two methods:

 

 Hexdisplay.png

 

Hopefully this helps

 

0 Kudos
Message 9 of 9
(4,725 Views)