LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Parallel VI Execution in LabVIEW-built DLLs

Hi,

 

I have some code that needs to run continuously in order to control and acquire data from several devices.  I also need to be able to simply grab the latest block of data that was acquired.  The catch: I need to do both from Java, using JNA to call functions in a DLL built by LabVIEW.

 

My quick-and-dirty hack to see if this was possible was simply this:

  • Create one VI, "Continuous.vi", which has an infinite While loop that executes every second, writing a random number to a global variable.
  • Another VI, "GetData.vi", which takes the contents of the global variable and outputs it.

Now I've built my DLL, and both functions are available.  In Java, I create an instance of the DLL via JNA, then I create two threads.  One of them calls Continuous(), and does not expect the call to return.  Once Continuous is running the other thread calls GetData().  But it hangs when calling GetData, and it doesn't return.  Clearly, GetData() is waiting for Continuous() to finish before it will run.

 

A simple unsychronised global variable is a bit of a hacky way to do this, but it was the easiest thing that sprang to mind.  Is there some other (better) method I should be using that will allow these functions to run in parallel with each other?  Or have I found a weakness with LabVIEW-built DLLs that I will have to find another way of working around?

 

Thanks,

 

Ian

0 Kudos
Message 1 of 4
(2,917 Views)

Try returning an argument from the DLL to your Java script.  This should prove it out.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 2 of 4
(2,913 Views)

MoReese: My issue was with passing the data from one VI to the other, not returning the data to Java at the end.

 

For anyone stumbling across this thread in future:  I did it with a TCP connection in the end.

 

My Continuous.vi acquired data and placed it in a queue, and ran a TCP server.  GetData.vi ran frequently, making a TCP connection to the server, retrieving the available data, and returning it to Java.

 

Before going the TCP route I experimented with DataSockets, but I couldn't find a way to get them to work from within a compiled DLL - I don't think the DataSocket Server was launching when it was required, like it does when running DataSocket apps within LabVIEW itself.

Message 3 of 4
(2,852 Views)

First are you shure you started a seperate thread in Java to launch the Continous() function? You do say that your Java code doesn't expect continous to return, so you may have meant this, but it is not clear.

 

Second you should have done this differentely by creating a start() VI that loads the contrinous() VI and runs it through the VI Server run method. This turns the VI basically into a deamon type of thing. Then there should be of course a stop() VI which sets a boolean of some kind to terminate the deamon. And last but not least the get() VI that reads the value(s).

 

Your final solution to use TCP/IP instead is of course at least as elegant.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 4
(2,841 Views)