LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Big Endian Value Extraction Problem

Hello,
 
For a change i don't have a setup issue but a VI problem. Smiley Indifferent
 
Here's the scenario:
I have a problem where I have an 8 Byte data where I would need to extract values based on a particular bit location and a lenght associated with it. I start of by converting the hEX string data to hEX NUMBER TO U8 and then convert that to an8 bit array. This process is repeated for all eight bytes.
 
Since, I now have the array.. for Little endian extraction is pretty straight forward. All I need to do this is extract using the array subset and retrieve the values.
 
However, for Big Endian it is a bit tedious. I am making a 2D array and reversing the array order than LE.
I seem to get right values in some examples but NOT getting the correct values if the signal extraction is greater than 16 bits.
Can someone help. I have attached a psuedo example of the code to give an idea of both methods.

Regards,
Ashm01
0 Kudos
Message 1 of 11
(4,666 Views)
I have seen this technique (and your related problems too often). What you can do is extract the bytes of interest, cast them to a U16 or U32 and then use the "Swap Bytes" and/or or "Swap Words" functions located in the Programming>Numeric>Data Manipulation palette.



What your probably interested in is byte endianess, not bit endianess. Read this to understand why your simple array reversal doesn't always work...
http://en.wikipedia.org/wiki/Endianess#Examples_of_storing_the_value_0x0A0B0C0D_in_memory

Message Edited by Phillip Brooks on 08-15-2007 07:08 AM

Message 2 of 11
(4,658 Views)

HI Phillip,

Thanks for your insight. However, someone must have a fix available if you have encountered this problem often.

I tried looking up this example(Byte order), unfortunately it does not work because and has a broken arrow. http://zone.ni.com/devzone/cda/epd/p/id/1178 Some one had already posted that this example doesn't work yet it still exists on the website Smiley Indifferent

Hence this was the reason I broken up the bits into an 8*8 array was to reassemble the 8 byte value and change the byte order but, it does not work too well when the values are larger than two bytes. Smiley Surprised

I figure, I will still need an 64 bit array to remove the array subset of the interested bits.

Say for example : Starting Bit 15, Lenght 16 or Starting Bit 47, lenght 24.

I tried looking for more real life examples on google but nothing of value.

Thanks,

Ashm01

0 Kudos
Message 3 of 11
(4,636 Views)
Well, I am not even trying to understand your code, but I think there is a much simpler way.
  1. Scan your string and covert to a binary string.
  2. This you can unflatten to a U32 array (or U16 array) Byte order is only defined within each number, so the resut will differ depending on the case if the segements are U16, U32, or U64. Depending on the selection it will reverse sets of 2, 4, or 8 bytes.
  3. Covert to boolean array and reshape.

Do you really need arbitrary sets of bits, possibly spanning the number boudaries or do you just need aligned U16 or U32 segments? In this case you would not need any green on your diagram. What do you actually need?

In the upper part of the attached code, I made a quick draft. You should modify it according to your exact requirements.

0 Kudos
Message 4 of 11
(4,614 Views)
You should also know that LabVIEW is by default big endian on any platform. If you don't swap bytes, you'll get big endian interpretation.
0 Kudos
Message 5 of 11
(4,608 Views)
Hello, I have a problem that might be related to this topic. I'm using the Modbus Library (Ethernet Master Query VI).
The following real variable was program into a PLC location 123.456 (32 bit, byte memory locations with in the PLC).
When I read these values in, they are stored in an array of U16 elements ( For example; Modbus address 16384 and 16385)  
With the following results 17142 in the first location and 59769 in the next location, it does not make sense.
 
I need to convert the U16 values to the original type and value (123.456) how can this be done?
 
Thanks for any input!
 
0 Kudos
Message 6 of 11
(4,399 Views)
You should start a new thread and reference an older thread in general.

The 4 bytes are a single precision number.  If you combine the numbers into a 32-bit value, then typecast it to a SGL, then you will get 123.456.




Message Edited by Matthew Kelton on 02-20-2008 07:43 PM
0 Kudos
Message 7 of 11
(4,387 Views)
Hi I'm kind of new to all this, I tried what you suggested but I end up with 1.12348E+9 could this be the value in a different format?
I don't understand it seems like labview is manipulating the 123.456 real value before it get put into the U16 registers. any suggestions?
0 Kudos
Message 8 of 11
(4,367 Views)

Try again, you seem to have something not wired right. Make sure all the representations are correct. The two inputs must be U16 and the type diagram constant must be SGL.

Attach your code if you cannot get it to work and we'll see what's wrong. 🙂

 



Message Edited by altenbach on 02-21-2008 07:59 AM
0 Kudos
Message 9 of 11
(4,349 Views)


JAMR wrote:
I don't understand it seems like labview is manipulating the 123.456 real value before it get put into the U16 registers. any suggestions?

If you want to go from a SGL to two U16, you would just reverse the steps. Here's one possibility. (You could also cast to a U32 scalar followed by "split number")
 



Message Edited by altenbach on 02-21-2008 08:07 AM
0 Kudos
Message 10 of 11
(4,347 Views)