From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can we link Java Code with LabView

Can any body guide me that how can we link Java Code with LabView.
Message 1 of 15
(31,141 Views)
Anderomeda,
I have no experience how to do it, but propably the following KB will help you a little bit.

BR,
ThSa
0 Kudos
Message 2 of 15
(31,140 Views)
Having spent many years developing in Java, my main complaint is how little effort has been put in to integrate with the platforms it runs on. However, as ThSa pointed out, JNI is the recommended way to talk from Java to non-Java code in the same process. Let me give you the summary of ways that I know of.
 
1. LabVIEW calling Java routines "in process"
 
Two ways to do this. One is to build a DLL that hosts the JVM and uses the JNI interface to call Java methods. The second is to convert the .class or .jar files into .NET and use the LabVIEW support for .NET. For the second case, look for stuff like this - I've not used it, but it was pointed out to me before.
 
2. LabVIEW calling Java routines "out of process"
 
The best solution here is Web Services. Java now supports building a web service that can be hosted in many different web servers. LabVIEW 8.20 for Windows now has an automatic importer for Web Services...so that makes this pretty easy. You could also use things like JSP/Servlets and simple URL commands.
 
Outside of that, its back to the standard "open a TCP/IP socket and create your own protocol for communication".
 
3. Java calling LabVIEW "in process"
 
Back to JNI. Build your LV code into a DLL and use JNI to call it.
 
4. Java calling LabVIEW "out of process"
 
While LabVIEW can talk to web services, it cannot current be a web service directly (although you can always call LV from a web service server, you just need to use something like Java or ASP.NET). Thus you'd be best to go with either the ActiveX interface for LabVIEW (you'll need to JNI to call the ActiveX interface, or use a COM importer for Java).
 
Again, as in the other direction, you can use TCP/IP to communicate.
 
Let me know if any of this sounds like a direction you want to take.
Message 3 of 15
(31,127 Views)

Can you please develope the second solution (best, with web services) or give me a small example of implementation ? I need to tu use my implementation in Java (methods) in project in Labview.  Thank you

0 Kudos
Message 4 of 15
(26,265 Views)

The solution is to implement a communication TCP between your project labview and your code in java. It's very easy, in Labview we need:

- num Port, adress (127.0.0.1) for a TCP open connection.

-data to send for a TCP write (send a informations to java).

-data receive for a TCP Read (receive information from java)

-TCP close connection.

 

for the code java, there is an example here. Use the tcp Server.java , because the code in labview will remplace the code of the tcpClient.java

0 Kudos
Message 5 of 15
(26,090 Views)

I would like to know if I am able to convert a vi into a ejs (easy java simulations)...does someone know?

0 Kudos
Message 6 of 15
(22,146 Views)

@godinhoer wrote:

I would like to know if I am able to convert a vi into a ejs (easy java simulations)...does someone know?


No, you can't convert a VI into a form that can run in Java. You would need some type of communication channel (such as a TCP socket) between the LabVIEW application and your Java program.

0 Kudos
Message 7 of 15
(22,137 Views)

If I wanted to use option 1, what do you suggest?  Are there some very simple examples?

0 Kudos
Message 8 of 15
(11,908 Views)

You're responding to a thread that was originally started over 10 years ago and last posted to 2 years ago.  Highly doubtful you'll get any replies from the original posters.

 

Can you please back up a step and tell us what you need to do and why you think calling Java code from LabVIEW is the way to do it, instead of jumping right to asking how to call Java code?

Message 9 of 15
(11,901 Views)

@kyle97330

 

>> Can you please back up a step and tell us what you need to do and why you think calling Java code from LabVIEW is the way to do it, instead of jumping right to asking how to call Java code?

 

I know LabVIEW better than Java and I need a gui.  I also need to wire the gui to call some (really large, really hard to reproduce) code that is currently in Java, and then present the results.  I'm looking to make a clean, standalone executable. 

 

I want to know:

  • if it is possible
  • how hard it is
  • what sorts of challenges and steps are in the process

 

Does that clarify?
Should I just make a new standalone question?

0 Kudos
Message 10 of 15
(11,897 Views)