LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help converting two 16 bit hex words to signed integer

Solved!
Go to solution

I am currently attempting to use labVIEW 2010 to read temperature and mass flow information off of a modbus instrument. However the instrument returns all values in 2 16 bit hex words in "Intel Bytes" ordering. I am having trouble converting this information to a usable signed decimal. For example:

 

Word 1   Word 2             Signed Integer

527E      41C0                 +24.0402793884277340

 

 

I have attempted to merge the words and cast to decimal but to no avail. Any help or tips are appreciated as I am new to labVIEW and working with raw data in general.

My current code is attached.

0 Kudos
Message 1 of 14
(6,336 Views)
Solution
Accepted by topic author pcxt21

Is 24.040... what you're supposed to get? You're talking about an integer, but this is floating point.

Anyway, if this is what you want to get it's quite simple:

2U16-SGL.png

 

 

Message 2 of 14
(6,332 Views)

You don't even need to index the array, if the elements are in the correct order you can directly feed an array of 2 U16 into the typecast to SGL:

ArrU16-SGL.png

 

 

0 Kudos
Message 3 of 14
(6,330 Views)

I have attempted to implement your first solution (as it was the most logical based on what I was reading from my device), however as you can see it doesn't appear to be working correctly. Can you spot my error? For reference I have included a screen shot of my VI running along with the expected value in the program to the left. I have attempted to reverse the wiring order but to no avail.

0 Kudos
Message 4 of 14
(6,314 Views)

You're doing a type cast to DBL, which is 64 bits. You need to type cast to SGL (32 bits).

 

0 Kudos
Message 5 of 14
(6,310 Views)

Ah OK that would make sense! But I must ask, I can't seem to find the a constant for SGL anywhere in the menus. Sorry for the idiot question however this it my first week working with LabVIEW and I'm still getting used to how the menus are organized.

0 Kudos
Message 6 of 14
(6,307 Views)

right-click the diagram constant...representation...SGL.

Message 7 of 14
(6,298 Views)

Thanks! Now I can interpenetrate the information I need.

0 Kudos
Message 8 of 14
(6,287 Views)

On a side note, there is also an idea that would make code images less ambiguous in terms of numeric representations.

 

(Personally, I always insist of attaching code or code snippets instead of images to make things unique. A flat image can never fully show all important aspects of a program.) 

0 Kudos
Message 9 of 14
(6,285 Views)

@altenbach wrote:

On a side note, there is also an idea that would make code images less ambiguous in terms of numeric representations.

 

(Personally, I always insist of attaching code or code snippets instead of images to make things unique. A flat image can never fully show all important aspects of a program.) 


I fully agree, even though the data type is visible on the indicator.

I don't have a clue why the Code Snippet Tool does no longer allow me to create a snippet (LV 8.5.1). It used to work...

 

EDIT: ah, I just figured it out again... works only when something is selected. My bad.

 

0 Kudos
Message 10 of 14
(6,280 Views)