LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

typecast byte

Solved!
Go to solution

Hi,

I'm using a self written c# programm to aquire data from a sensor. I'm serializing the sensor data into a byte Array and send them to a specific ip/port via udp.

 

example of sensor data:

 

uint16 ValueX => 2 Bytes

int16 ValueY => 2 Bytes

double ValueZ => 4 Bytes

 

=> 8 Bytes => convert to bytearray[] => while loop start => udp send => while loop end ...

 

in Labview:

 

udp receive ... > geting a string array => converting from string to unsinged bytearray  ... NOW i want my datatypes back 😞 .. anyone got an idea ?

 

is their a efficient solution?

 

with regards

SuperK

0 Kudos
Message 1 of 11
(4,729 Views)

I would typecast the 8-byte string

 

SimpleTypeCast.png

 

I chose SGL since you said it was 4 bytes.

0 Kudos
Message 2 of 11
(4,726 Views)
Solution
Accepted by topic author superK85

 


@Darin.K wrote:

I would typecast the 8-byte string

 

SimpleTypeCast.png

 

I chose SGL since you said it was 4 bytes.


You probably need to watch out for Endianess too. LabVIEW Bytestream format is by default Big Endian, while most Windows applications use the i386 default Little Endian. The Typecast function has always and still uses Big Endian. For the Unflatten function you can select what Endianess to use since about LabVIEW 8.2.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 11
(4,696 Views)

Hi,

 

no I dont think that i have an endian Problem because the Dataframe that im sending in bytes ist the same that I'm receiving.

I've got another Problem... as you can see in the screenshots I'm sending the Number "1" as an UINT32  to the VI.

 

Instead of a 1 i got the value 16777216.

When I'm doing the TypeCast with the same byte[] dataframe in c#  I'm getting my 1 when I'm sending the 1.

 

How can that be?

I know that  the INT Value "1" has the Hex Value "0x01"  and that 16777216 has the Hex Value "0x01000000"

 

The UDP Receiver in my VI transports the Datastream as a String not as a (Byte-)Array as usual I know from c#

 

with regards

SuperK

Download All
0 Kudos
Message 4 of 11
(4,669 Views)

It sure looks like an endian problem to me.  If you have the x01 showing up as the first byte vs. the last byte of a U32.

0 Kudos
Message 5 of 11
(4,661 Views)

But why the Header Info AB CD comes correctly ? Because it's just one byte each?

 

Well then, where is the option to change the endian value? or should i array reverse each value?

 

thank you

0 Kudos
Message 6 of 11
(4,655 Views)

@superK85 wrote:

But why the Header Info AB CD comes correctly ? Because it's just one byte each?  Yes

 

Well then, where is the option to change the endian value? or should i array reverse each value?  Look in Numeric >>  Data Manipulation.  Swap bytes and/or Swap words.

  

thank you


 

0 Kudos
Message 7 of 11
(4,642 Views)

Or instead of using the Typecast you can also try the Unflatten function. This one does have a selector where you can select the Endianess of the conversion, at least if you have a somewhat recent LabVIEW version.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 11
(4,636 Views)

If you want to adjust the endianness (endianity) then you can switch to Unflatten from String:

 

SimpleUnflatten.png

 

0 Kudos
Message 9 of 11
(4,634 Views)

thenk you i found a more elegant solution then the typecast and everything....

the marvelous  "data serialize" vi  😄

 

thank you so much for your help guys!

 

i hope this thread helps !

0 Kudos
Message 10 of 11
(4,632 Views)