LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert U16 to half-precision real

Hi All,

    I'm receiving values from a bluetooth device in the form of raw U16 values. I need to convert them to a 4byte float but am having problems figuring out how to manipulate the bits in the word. As example:

 

Raw data 14234, 14235

Real     0.866563618183

 

the raw data is created in the original python program by  "self.x_raw = struct.unpack_from('>4096H', buf, offset)"

 

the resulting "float" from the original python program : " self.X = struct.unpack_from('>2048f', buf, offset)"

 

I haven't seen the actual "raw" data stream yet, the python program shields me from that.

 

basically these two lines create two files, the raw with 4096 values, the real with 2048. This imples to me that there is a two to one relationship between the two, I'm trying to determine, basically, how the python struct.unpack_from commands with the H (indicates a "short integer") and f formats (indicates a 4 byte real, i.e an I32) would be duplicated with LabVIEW. Sorry guys, this is probably not so hard, but I'm, as usual when I ask on here, a bit sleep deprived and under the gun project timewise.

 

Thanks!

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 1 of 6
(4,157 Views)

4 bytes?  That is actually a Single Precision (SGL).  The real question is the endianess.  Is the first word the MSW or LSW?  You can play around with these using Join Number to create a U32 and then type cast to a SGL.


GCentral
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 2 of 6
(4,148 Views)

according to the python literature the  > in the statement indicates Bigendian.

 

Really didn't quote this project well, got blindsided a bit, thinking of working at that Scottish restaurant McDougal's, McDonaugh's, something like that, too tired to remember right now.

 

P

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 3 of 6
(4,139 Views)

Another comment here.  What you put down for Raw Data, is that the actual data or the addresses you read from?  The fact that they are sequencial makes me think those are addresses.


GCentral
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 4 of 6
(4,128 Views)

I'm pretty sure that it is the "raw" data, as formatted by the python command. THose two happen to be sequential, others aren't, the last two are zero, with the cooresponding entry in the "real" file being zero as well. I meant to say "SGL" as it is a 4 byte real. Tried a few combinations of splitting U16 reps of those two numbers, joining them and casting to SGL, so far without success. Working on issue of memory manager crashes now. Argh!

 

 

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 5 of 6
(4,118 Views)

Try these.

"If you weren't supposed to push it, it wouldn't be a button."
Download All
0 Kudos
Message 6 of 6
(4,077 Views)