07-23-2019 11:46 AM
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.
07-23-2019 11:56 AM
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.
07-23-2019 12:05 PM
07-23-2019 12:11 PM
@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.
07-23-2019 12:13 PM
Oftentimes people will get confused because the data comes out as a "string", which is really just an array of bytes.
07-23-2019 12:14 PM
@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.
07-23-2019 12:20 PM