Jump to content

Sending Integer/Double


Recommended Posts

QUOTE (jjylf @ Jun 24 2008, 04:30 AM)

Is it possible to send data of type Integer or double over TCP/IP in LV?

The TCP Write can only send string, or?

TCP Write uses a string for its datatype, but remember that a string is really just an array of bytes. So anything you want to send will have to be packed into a byte array for transmission (it's like serial in that respect).

A straightforward way to pack the data is by using the Flatten To String and Unflatten From String functions in your palettes. You could also just format the numeric data into a human-readable string and decode it at the other end.

Link to comment

QUOTE (Antoine @ Jun 24 2008, 08:46 AM)

This is definitely not the way to do it - you're potentially losing precision while adding overhead and extra bytes of data. There are much easier ways to convert numeric data into a string for transmission purposes. Take Justin's suggestion - use flatten to string and unflatten to string. Or, if you don't need to do any verification of the data type on the receiving end, just use Type Cast, found in the Numeric pallette under Data Manipulation.

Link to comment

QUOTE (ned @ Jun 24 2008, 03:02 PM)

This is definitely not the way to do it - you're potentially losing precision while adding overhead and extra bytes of data. There are much easier ways to convert numeric data into a string for transmission purposes. Take Justin's suggestion - use flatten to string and unflatten to string. Or, if you don't need to do any verification of the data type on the receiving end, just use Type Cast, found in the Numeric pallette under Data Manipulation.

I`m sending the data to a Java program. Is there any java library methods to unflatten the string?

Link to comment

QUOTE (jjylf @ Jun 24 2008, 08:11 AM)

I`m sending the data to a Java program. Is there any java library methods to unflatten the string?
Yes and no.

JAVA uses object serialization -- implement the "Serialize" interface on your class to have it be able to flatten and unflatten. The primitive types of JAVA have serialize naturally implemented for you as part of the language specification. The problem will be that LabVIEW's flat string format and JAVA's are almost certainly not the same. There's no IEEE standard for flat representations of numeric data.

Workaround #1:

If you use Antoine's solution (the one that Ned recommended that you NOT use), this is something that LV can read/write and JAVA can read/write. Use this:

   ObjectOutput out;   out.writeInt(5);

to create the string, and use the inverse InputObject to read the string in Java.

Workaround #2:

LV's format for flat data is documented in the "interfacing to external code" documents that ship with LV. Java's format is similarly documented (I know O'Reily's has it and I'm sure that in one of the various online doc sites you'll be able to find it). Write code in one language or the other that can read/write the other language's format.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.