NI TestStand

取消
显示结果 
搜索替代 
您的意思是: 

Converting from 32bit Hex to Decimal Floating-Point

I need to use an already written VI that returns two U16 words (Output_1, Output_2). How do I combine these words and convert to a 32bit decimal floating-point number in a post expression for use in a numeric comparison? Is there a way to do something similar to the labview type-cast function in TestStand? I think the expression should start with something like this Step.result.Numeric = Locals.Output_1*65535 + Locals.Output_2.

I'm using TestStand 3.5

Thanks,
Jason
0 项奖励
1 条消息(共 8 条)
10,115 次查看

Jason,

 

You can try this:

 

Locals.OutputValue = (Locals.One << 16) | Locals.Two

 

I did this with the following values and let TestStand do the conversion, since all values in TestStand are stored as doubles regardless of viewing format:

 

My watch expressions showed the following:

Locals.OutputValue = 2271560481.000000 // formatted as Real
Locals.One << 16 = 0x87650000 // formatted as "0x#.8X"
Locals.Two = 0x00004321 // formatted as "0x#.8X"
Locals.OutputValue = 0x87654321 // formatted as "0x#.8X"
(Locals.One << 16) | Locals.Two = 0x87654321 // formatted as "0x#.8X"

 

I think you are on the right track, and TestStand will convert what you want.

 

-Jack

 

2 条消息(共 8 条)
10,106 次查看

Hi

 

Try this example

 

 

Greetings

juergen

 

Seems I was to slow. Excatly the same as Captain Jack !

Message Edited by j_dodek on 11-21-2008 01:32 AM
--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
下载全部
0 项奖励
3 条消息(共 8 条)
10,099 次查看
I'm able to combine the words correctly but can't get the correct conversion. If the low word is 0x6667 and the high word is 0x416E the correct conversion from 32-bit hexadecimal to decimal floating-point according to IEEE-754 is 14.9000....... I keep getting 1097754215 which is a hex to decimal conversion.
0 项奖励
4 条消息(共 8 条)
10,088 次查看

Hi,

 

that means your hole dword is repesenting a 32bit float ?

addtional http://de.wikipedia.org/wiki/IEEE_754

 

in C/C++

i would call this function;

float toFloat(WORD wLow, WORD nHigh)

{   union{

   WORD[2] warray;

   float fVal;

   } myUnion;

 myUnion.warray[0] = wLow;

 myUnion.warray[0] = nHigh;

 return myUnion.fVal;

}

 

juergen

Message Edited by j_dodek on 11-21-2008 09:48 AM
--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 项奖励
5 条消息(共 8 条)
10,072 次查看

I see, you don't want to treat the 16bit integers as integers, you want to reinterpret them as the binary bits of a 32-bit floating point number. Not sure if there is a way to do this in a LabVIEW VI (perhaps someone who knows LabVIEW better than me can help if needed), but you can do this in a C/C++ DLL as follows:

 

float ConvertBitsToFloat( unsigned short highbits, unsigned short lowbits)

{

     float retval;

     DWORD * floatbits = (DWORD *) &retval;

     *floatbits =  ((DWORD) highbits << 16) | (DWORD)lowbits;

 

    return retval;

}

 

Hope this helps,

-Doug

0 项奖励
6 条消息(共 8 条)
10,065 次查看
I know I can do this conversion in Labview using the type cast funtion, but I don't want to change the already written VI. Is there a way to do the above C/C++ commands in a post expression in TestStand?
0 项奖励
7 条消息(共 8 条)
10,061 次查看

You cannot do a reinterpret cast in the TestStand expression language. You could parse the exponent and the mantissa out of the 32-bits and use floating point arithmetic and functions to recreate an equivalent value, but it would be tricky, especially if you want to support corner cases like INF, IND, and NAN.

 

If you think you know how to do the conversion in LabVIEW already, I'd recommend just writing a utility VI in labview which does this and call that from TestStand. There's no need to modify existing VI, you just need to write a new one to do the conversion.

 

Hope this helps,

-Doug

0 项奖励
8 条消息(共 8 条)
10,053 次查看