From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Saturday, Nov 23rd 7:00 PM CST - Sunday, Nov 24th 7:45 AM CST, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
04-18-2019 10:05 AM - edited 04-18-2019 10:06 AM
Hello dear forum,
I am currently struggling with a piece of code that is supposed to change the format of a hex string into a float of the type Mid-Big Endian.
The input is from a sensor and is displayed in Labview via a string indicator with hex display option enabled. The input consists of 4 bytes.
See my attached image.
I have been searching the forums and trying to manipulate the data in many different ways but i cannot get it to display the correct value.
I know that the hex string e.g. 3CBF 1442 should translate into -0.7347 float format.
I have tried to re-construct the string to show "BF3C 4214" as the formats predicts but I cannot get any output close to the desired one.
Am I missing something obvious? Any help would be greatly appreciated and I would gladly eloborate of something is unclear.
Solved! Go to Solution.
04-18-2019 10:20 AM
@simonhb wrote:
Hello dear forum,
I am currently struggling with a piece of code that is supposed to change the format of a hex string into a float of the type Mid-Big Endian.
The input is from a sensor and is displayed in Labview via a string indicator with hex display option enabled. The input consists of 4 bytes.
See my attached image.
I have been searching the forums and trying to manipulate the data in many different ways but i cannot get it to display the correct value.
I know that the hex string e.g. 3CBF 1442 should translate into -0.7347 float format.
I have tried to re-construct the string to show "BF3C 4214" as the formats predicts but I cannot get any output close to the desired one.
Am I missing something obvious? Any help would be greatly appreciated and I would gladly eloborate of something is unclear.
First, I think you reversed the byte order in the first group of bytes. If I reverse them to BF3C 1442, I can convert it to "-0.734684". The file is a snippet saved in LV 2015.
I'm not sure you should try to download the image shown here, because I think that the forum will rob it of the "magic" necessary to convert it into LV code.
04-18-2019 01:14 PM - edited 04-18-2019 01:14 PM
You are doing some weird mixed-endian conversion where you only swap the strings for 1,2 and 3,4. This is most likely wrong. You should reverse the entire string if you think the byte order is wrong.
Bill is right, the string (in hex display) should be BF3C 1442 and interpreted as big endian. LabVIEW can translate that into a SGL in one step with the default settings. Here are two possibilities:
04-18-2019 01:46 PM - edited 04-18-2019 01:46 PM
I only thought the string was incorrect because OP second example was what you would expect.
04-21-2019 05:37 AM
Thank you altenbach and billko,
It works perfectly. The problem just was that I was overthinking it after some long days at uni.
I used your method and got the right result (see attached snippet)
04-21-2019 08:15 AM
@simonhb wrote:
Thank you altenbach and billko,
It works perfectly. The problem just was that I was overthinking it after some long days at uni.
I used your method and got the right result (see attached snippet)
Here is another way to do it. Don't know if it's any better or faster. But it is a little cleaner looking.
04-21-2019 10:56 AM - edited 04-21-2019 10:59 AM
@jamiva wrote:
@simonhb wrote:
Thank you altenbach and billko,
It works perfectly. The problem just was that I was overthinking it after some long days at uni.
I used your method and got the right result (see attached snippet)
Here is another way to do it. Don't know if it's any better or faster. But it is a little cleaner looking.
It's pretty "Rube-ish" and not as flexible as the unflatten from string in that you cannot specify the endianness of the resulting number. If you are going to use the typecast function, may as well use it only once and get it over with.
Edit:
Oh, I see you were trying to solve the original problem. It was agreed that the original problem had the first word accidentally byte-swapped. Your solution is fine if that is taken into account.
04-21-2019 11:32 AM
@simonhb wrote:I used your method and got the right result (see attached snippet)
First of all, that's a plain image, not a snippet. (In LabVIEW, the term "snippet" has a very specific meaning and is an image that includes diagram code).
Second, your image mostly resembles your original code, nothing what Bill or Me suggested. Are you sure you attached the right image?
04-22-2019 09:41 AM - edited 04-22-2019 09:43 AM
That's better and works more in general.
I uploaded the wrong picture of my code. I do not concatenate the strings like before but make the conversion directly like your snippet shows billko.
Thank you for your help.
02-11-2023 08:44 AM
I used the attached snippet to get the desired output. Hope it helps everyone.