ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending 16 bit Integer by TCP

I have a program written in JAVA that connect to the TCP server on my labview vi, everything is sending good but I am having a hard time converting the bytes back to an integer.  I beleive it is messing up when sending anyting about 255.  What the VI program does is takes an input signal between 0 - 10 and multiplies it by 1000 and then takes the 16 bit integer value of that and sends it over the TCP connection to my java program.  I had a length of the byte array sent over to but it is always giving me a length of 1 even though it should be 2 if a value of more then 255.  I have attached a copy image of my program, is there a better way to do in?
 
Thanks
 
Kevin
0 Kudos
Message 1 of 3
(3,526 Views)
First you convert the waveform data to an array of doubles.  That is OK.  Then you convert the doubles to 16-bit integers.  That will truncate the decimal, but since you multiplied by 1000, I assume you are considering that so that is OK too.  Then you make your  fatal error in wiring the I16 array to a Byte Array to String function.  See that little red dot on the left side if the Byte Array to String function?  That tells you there is a coercion going on that is chopping each I16 down to a U8.  Since you only have 1 integer in your 16-bit array, you end up with only 1 byte in the coerced byte array.

I recommend the Flatten to String function.  It has the option (in newer LabVIEW versions) to change the byte-order (LabVIEW is big endian, but Intel is little endian) and can prepend the array size or not.  Since you seem to want just a single number, you do not want the array size.

See attached example.

Dan Press
PrimeTest Automation
0 Kudos
Message 2 of 3
(3,509 Views)
You can also do a split number function on the I16 array to come up with two U8 byte arrays.  Interleave those arrays then convert the byte array to a string for sending into the TCP/IP.  You can do all the opposite functions on the other end, though you will need to do a typecast  to conver the resulting U16 to an I16.


Message Edited by Ravens Fan on 07-09-2008 10:23 PM
0 Kudos
Message 3 of 3
(3,470 Views)