LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Java and Labview communication

Hello,
I need to know how to pass data from java to labview and vice-versa?
0 Kudos
Message 1 of 10
(2,676 Views)
There are a variety of ways depending on your need. A few off the top of my head would be

If you are calling Java as a library:
1. Create a JNI library to expose your Java code as a C-style interface. You can then use the Call Library node

If you have a Java application you are talking to
1. Use TCP/IP or HTTP. Requires some amount of protocol building.
2. Flat files - using CSV, XML, etc.
Message 2 of 10
(2,667 Views)
I don't know java so I'm not sure if and how this is applicable.
You could use TCP by opening a connection to localhost (127.0.0.1) on a specific port and use the same port in the java program.
Alternatively, if java allows you to call DLLs, you can try making a LV DLL and call it from java.
Like I said, I'm not sure if and how this will work, but it might help as a start. There probably are examples on this site of communicating with other languages and you might be able to adapt them.
Hope this helps.

___________________
Try to take over the world!
Message 3 of 10
(2,666 Views)
I have a Java application. Do you know examples?
Thanks, Gilson.

Message Edited by gilsonap on 04-05-2005 06:13 AM

Message Edited by gilsonap on 04-05-2005 06:13 AM

0 Kudos
Message 4 of 10
(2,651 Views)
Going to the top of the page (the very top) and writing "java" in the search box yields quite a few results. Changing the search string to "java communication" or other similar derivatives will probably give more results. Here is one which seems to be relevant.

___________________
Try to take over the world!
0 Kudos
Message 5 of 10
(2,643 Views)
"I have a java application" - By this I assume that the Java program runs in its own process? Then the JNI approach won't work for you (although there are a couple of techniques by combining JNI with an RMI wrapper).

Could you give a little more information about the application and the kind of data you want to exchange? Is it a quick app that you can spawn from LV? Is it a server app that is always running?
0 Kudos
Message 6 of 10
(2,632 Views)
I need to pass data to and from Java/Labview. The data are arrays with numbers. A think the TCP/IP may work... Do you agree?
0 Kudos
Message 7 of 10
(2,621 Views)
I am just going to assume that we are dealing with a Java process. If that is the case, then yes - TCP/IP is fine for doing the transfer.

HOWEVER - It may or may not be easy depending on your system (which you still have not described).

For example, if the LabVIEW application is running on an open network then you may need to worry about security (authentication, authorization and encryption).

Another issue is the data protocol you choose to use. For example, it is very easy to convert the numbers to string ("1234" rather than the integer 1234) but it is much slower. Sending the raw integer over means you need to worry about byte order of the data (Java is always big-endian, even on Windows).

It really isn't that difficult - I just want to make sure you are prepared for the decisions you need to make.
Message 8 of 10
(2,607 Views)

Hello, did you get to know how to parse data from labview to java ... could you please help !

0 Kudos
Message 9 of 10
(1,292 Views)

And i forgot to mention that server and client are able to connect to the same port and on localhost but when i pass a constant string, in java i can't read it.

 

Here's my code 

public class Test
{

private static Socket socket;

public static void main(String[] args)
{
try
{

int port = 8006;
ServerSocket serverSocket = new ServerSocket(port);
System.out.println("Server Started and listening to the port 2018");

//Server is running always. This is done using this while(true) loop
while(true)
{
//Reading the message from the client
socket = serverSocket.accept();
System.out.println(socket);
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String data = br.readLine();
System.out.println("Message received from client is "+data);



}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
socket.close();
}
catch(Exception e){}
}
}

0 Kudos
Message 10 of 10
(1,285 Views)