LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

single precision conversion

Hi, I am receiving a stream of bytes on serial port. I want to combine 4 bytes and convert it into single precision IEEE754 format. I have tried example on https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000kKoNSAU&l=en-IN but doesn't seem to work.

any help is appreciated.

 

0 Kudos
Message 1 of 7
(2,309 Views)

It looks like you have a space in your input. The representation should be normal not hex.   The byte order could be wrong too, possibly. 

Message 2 of 7
(2,296 Views)

@MichaelS78

My input stream is in Hex. How do i convert this to normal string?

 

0 Kudos
Message 3 of 7
(2,281 Views)

@jpparmar wrote:

Hi, I am receiving a stream of bytes on serial port. I want to combine 4 bytes and convert it into single precision IEEE754 format. I have tried example on https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000kKoNSAU&l=en-IN but doesn't seem to work.

any help is appreciated.

 


First of all, right-click on that string constant and select "Visible Items" --> "Display Style" so that everyone here - and eventually even yoursel - won't be confused by what those characters actually are.  (In this case, I'm pretty sure you are displaying them as hex, but you already confused one person.)

 

All you need to do here is use the "Unflatten from String" VI, with a single precision FP as your type.  You'll have to configure a few things, so if you have problems, let us know.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 7
(2,273 Views)

Oftentimes people will get confused because the data comes out as a "string", which is really just an array of bytes.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 5 of 7
(2,269 Views)

@jpparmar wrote:

My input stream is in Hex. How do i convert this to normal string?


Once again, I am convinced there is a misunderstanding of what the data is here.  When I read "Hex String", I think of a binary/raw data.  The way you treated the string was what I call an ASCII Hex, which is a string that you can read in a normal text editor and all of the characters are 0-9 and A-F.

 

But in the end, I think you just need to use the Unflatten From String to convert your 4 byte string into a SGL.  I prefer using the Unflatten From String since there is an input to select the Endianness (byte order).

 

And a final note:  If you are going to show a string control/indicator/constant in a mode that is not "Normal", then choose the Visible Items->Display Style.  It will fix a lot of confusion.


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
Message 6 of 7
(2,266 Views)

Hi jp,

 

just typecast:

check.png

(UnflattenFromString is preferred, but in this case TypeCast is ok too.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 7
(2,255 Views)