From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String Readed in Hexadecimal convert to Decimal.

Solved!
Go to solution

Hi there! i am making a vi to check the lamp hours of my projector Sony. I send an Hexadecimal command that is: A901 1301 0000 139A . When the projector receives it respond with 1901 1302 0031 339A. 0031 is the data that i have to convert to decimal because it tells me how many hours we have used the lamp. How can i get that string readed separated to get only the third part of hexadecimal numbers converted to decimal? Thanks in advance!

0 Kudos
Message 1 of 15
(10,610 Views)

I have found here some examples, but i cannot make them work for my problem. Anyone? Thanks!

0 Kudos
Message 2 of 15
(10,582 Views)
Solution
Accepted by topic author roundish

Hey roundish!

 

As the data is in a String format, then the Hexadecimal String to Number VI should work fine in this instance.

 

To grab only a particular numeral from that String to use in the Hexadecimal String to Number VI, then I'd suggest using the String Subset VI; this returns a specified segment of a string. By modifying the offset input which determines what part of the String the data begins to be parsed from, and changing the length to control the amount of characters to be parsed, you'll be able to grab the character you want to convert.

 

Regards, 

 

 


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

Message 3 of 15
(10,580 Views)

Hi! Thank you so much Alex!!! It worked pretty well. Let me post for the forum my example code. Thanks!

0 Kudos
Message 4 of 15
(10,573 Views)

Ho again! i have another problem now, the string i am reading is in Hexadecimal format, so when i maked that vi it worked, but when i use it on the projector i always return the value 0.  I have checked the hexadecimal option on the display style so i receive the data but the conversion doesn't work. This is the code, thx in advance.

0 Kudos
Message 5 of 15
(10,535 Views)

What is the data you are getting from the VISA read look like?

 

Earlier you were converting Hex formatted strings to data.  But now you are actually sending Hex data to the VISA Write.  So I'd think you'd be getting similar data back. In which case converted from hex formatted strings would be wrong.

 

Are you getting data like "0" and "F" (2 characters), or a hex value such as 0F,  (one byte)?

0 Kudos
Message 6 of 15
(10,531 Views)
Hi! I am sending hex data to the projector, so the projector is giving to me hex data to. I need to convert it to decimal, but just the part i have selected. I am receiving 0 all the time.
0 Kudos
Message 7 of 15
(10,523 Views)

You need to use typecast to convert the string data to the appropriate datatype.

0 Kudos
Message 8 of 15
(10,520 Views)
So adding a typecast before the conversion will work?
0 Kudos
Message 9 of 15
(10,514 Views)

No No No.

 

Get rid of that hexadecimal string to number conversion.

 

Just take your string bytes and typecast them.

0 Kudos
Message 10 of 15
(10,507 Views)