LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how a string in hexadecimal display convert to number

Hi,
I have a string read off Modbus through comport. It must in Hexadecimal display style (string property) in order to get meaningfull reads.
Now I want to convert this string to a decimal number for human read.
I used "Hexadecimal String to Number" conversion, it doesn't work. (only works if the string has "nomal display" in its property setting).
Anybody has ideas/solutions for this problem?
Thanks in advance.
0 Kudos
Message 1 of 10
(9,517 Views)
Strings controls don't have a hexidecimal display style. Integer numerics do. Are you sure you're using a string? Could you post an example?
0 Kudos
Message 2 of 10
(9,510 Views)
String controls do indeed have a Hex display mode.

To original poster: I suspect it's because you're misunderstanding the Hex display mode. The way you display a string doesn't change its underlying value. The display mode is for human consumption. If you put a string control on the front panel, and type in 'abc', in "normal" mode it would display 'abc'. In "Hex" display it would show '616263'. That's because '61' is the ASCII code for 'a', '62' is the ASCII code for 'b', and '63' is the ASCII code for 'c'.

If you have were to have a string control in Hex display mode, and you entered '3F56' you're saying that you're entering a string of two characters. The first character is the character that corresponds to ASCII code 3F, which is '?', and the second character is the character that corresponds to ASCII code 56, which is 'V'.

Message Edited by smercurio_fc on 11-28-2006 04:58 PM

0 Kudos
Message 3 of 10
(9,504 Views)
If you want to convert your string to a number first you must convert it to an array of 8 numbers bit.  Then you can combine the elements of your array to make 16 or 32 bit numbers.
 
Good Luck
Eric 
0 Kudos
Message 4 of 10
(9,494 Views)
Oh, of course. I'm an idiot. I was thinking that, since there's no "Format and Precision" tab, you can't set the display options on a string like that.

0 Kudos
Message 5 of 10
(9,492 Views)

Thanks to everybody who responded this thread.

OK, here is my situation: I want to monitor a device through a serial port.  This device is using Modbus RTU as communication protocol.

In the LV8.2 code, I use "VISA Read" (Functions panel\Instrument I/O\Serial\Read) to read income data.(through VISA Read's read buffer).  This read buffer is in string type.

I have to set the string indicator (destination of  the read buffer) in hexadecimal display style, because the data off the comport is in hexadecimal format (Modbus protocol).  If I set the string indicator in normal display, all the income data shown in the indicator just garbage.  

Now I want go one step further to cast the income data in hexadecimal format to decimal format for easy read, and got the conversion problem I posted before.

Is it possible to convert the data naturally in hexadecimal format to decimal display?

Thanks again.

0 Kudos
Message 6 of 10
(9,464 Views)
You can use String to Byte Array to convert a string to an array of unsigned bytes. Each character of the string becomes one element in the array.

0 Kudos
Message 7 of 10
(9,456 Views)
You did not seem to understand my post. It does not matter what display format you use for the string indicator that displays what you get from the VISA Read. The data is the data. It does not change based on what display format you use. LabVIEW is simply interpreting the data based on the display mode you've selected. When you have it set on 'normal' display it displays "garbage" because it's displaying the ASCII characters that correspond to the hex values you're getting. It hasn't changed the data.

How you convert it depends on the meaning of the data. How many bytes are you getting? Is each byte a value, or are you getting 4 bytes that correspond to an I32? Is each character the string equivalent of the value, or the actual value? In other words, if you get "1F3A", does the "1" represent that the actual value of 1, or does it represent the written number 1? The String to Byte Array for this text would give you {49, 70, 56, 65}, since it's interpreting each character as an ASCII character, and the values of the elements in the array correspond to the ASCII codes for "1", "F", "3", and "8", respectively. Is this what you want? If, on the other hand each character indicates an actual value, you would want an array with elements of {1, 15, 3, 10}. Is this what you want? Does the string "1F3A" correspond to a 32-bit number? If so, the Hexadecimal String to Number is what you want to get a value of 8074 decimal. Is this what you want?

Please indicate exactly what you're getting, and what it means.
Message 8 of 10
(9,451 Views)
smercurio_fc nailed it on the head.  You have to know what your data means before you can convert it.
 
 
0 Kudos
Message 9 of 10
(9,429 Views)
Ok, I will try to convert the string directly from the read buffer of "VISA Read".
Thanks for everybody.
0 Kudos
Message 10 of 10
(9,411 Views)