06-14-2011 02:21 PM
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
Solved! Go to Solution.
06-14-2011 02:31 PM
I would typecast the 8-byte string
I chose SGL since you said it was 4 bytes.
06-15-2011 07:34 AM - edited 06-15-2011 07:35 AM
@Darin.K wrote:
I would typecast the 8-byte string
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.
06-15-2011 12:53 PM
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
06-15-2011 01:13 PM
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.
06-15-2011 01:16 PM - edited 06-15-2011 01:21 PM
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
06-15-2011 01:25 PM
@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
06-15-2011 01:31 PM
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.
06-15-2011 01:31 PM
If you want to adjust the endianness (endianity) then you can switch to Unflatten from String:
06-15-2011 01:34 PM
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 !