LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Hex String to Numeric conversion

Solved!
Go to solution

I have the following String returned by a MODBUS instrument :

Hex String.PNG

My embedded data is 0104 , 7530, 7530, 7530 which is shown inside green brackets.

 

I want to convert them into relevant numeric data of 260, 30000, 30000, 30000.

 

Have been trying to do that with a  VI as attached. Not getting there right. Any help would help !! 

( The attached VI is attempting to convert only the first data which is 0104)

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 26
(4,183 Views)

Here's one solution to your question.

 

hextonumber.png

0 Kudos
Message 2 of 26
(4,150 Views)

Hi Raghunathan,

 

if you would receive your string as HEX data (as I suspect) it would be so much easier:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 26
(4,115 Views)

I tried the solution that you suggested... but the results were not as expected. Maybe I am doing something wrong. Need to study the code when I am more relaxed...

 

the code in LV12 is attached. 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 4 of 26
(4,041 Views)

Hi GerdW,

 

Yes if it was in Hex it could have been simple. But the feed is from a TCP read. 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 5 of 26
(4,038 Views)

Raghunathan wrote:

Yes if it was in Hex it could have been simple. But the feed is from a TCP read. 


It doesn't matter where the data is coming from.  All that matters is the format of the data from the read.  That information is what people have been asking for.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 26
(4,031 Views)

The data format is string. A point I thought to emphazise by saying its from a TCP Read - which as per LV Help is a string.

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 7 of 26
(4,022 Views)

The string is just an array of  bytes.  What is the format of the data in this byte array that shows up as a string?  I recommend you get a normal message from your instrument and save that string data to a file and post the file.  Also tell us what you expect the output to be.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 26
(4,017 Views)

Finally the solution.

 

Maybe from an expert programmer point of view, not very smart or compact code but nevertheless does the job. The project can atleast proceed. 

( Possibly the Indexes can be taken as an array and a FOR loop can make the code small and compact )

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 9 of 26
(3,977 Views)

Hi Raghunathan,

 

yes, a VI which does the same things by copying code again and again is not very smart…

 

One more suggestion:

check.png

Hint: You should always get the habit of showing the string display mode, especially for your strings containing hex formatted numbers…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 26
(3,963 Views)