LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How a variable in C++ gets updated from calling a labview dll running in a loop?

Hi,

 

I have created a dll which is called from a C++ program. The dll has been created from a vi which continuously runs in a loop (this is necessary because I need to control some hardware in real-time). When I call the function from C++ I can see the front panel of the vi working properly, i.e. all variables are updated in real time on the labview panel (which I will set as not visible once i get this problem sorted out).

 

However, I can't get the variables' values getting updated in my C++ program and I need these values to change in which way the hardware should behave ... is there any example somewhere in which something similar has been done? I have seen some examples where a dll is called from C++ with a vi function but not running in a loop. In these examples, the vi function passes the datum to the C++ software once is finished ...  

 

thanks very much for your help,

 

kind regards

 

Sergio

0 Kudos
Message 1 of 5
(2,830 Views)

Let's ask the question a different way. Let's say you did not have a LabVIEW DLL. Let's say you had a C++ DLL that had a function, and when you called that function it basically consisted of the following:

 

function int my_function()

{

   int my_variable;

   while (condition_is true)

   {

      do stuff that updates "my_variable";

   }

   return my_variable;

}

 

Then how would you get "my_variable" out to your calling program while the loop is running? See how the situation is no different with the LabVIEW DLL? You are talking about inter-process communication, which is not specific to LabVIEW. The answer to your question is that you must code in some form of inter-process communication. There are many ways to do this. In the simple example above, the function could be passed a pointer to a memory location where the function can update the value of the variable.

0 Kudos
Message 2 of 5
(2,823 Views)

It sounds like you have two threads (a vi thread and a C++ thread) and you want them to share data (with one exclusively reading and one exclusively writing). I imagine you could create another DLL called by both the vi and the C++ thread. Each loop, the vi calls 'write data' in the dll, and it writes a static data structure in the dll. The C++ thread then calls 'read data' to get the data out of the static data structure. This should work by default as long as the two threads owned by the same process. Just a possibility.

0 Kudos
Message 3 of 5
(2,818 Views)

Hi smercurio_fc!

 

Thanks very much for your answer!

 

I have already an inter-process communication, where there are two threads running in parallel. In one thread the C++ code is running while in the other the LabVIEW code is running. The labview function is passing the "output" variables as pointers too.

 

_1DScan(ReqForce,&StopAlign,0,&ReadForce,&Piezo_running,&RS232OK,&Running);

 

the function is called using the following:

 

void CFMControl::FMThreadProc()
{

    _1DScan(ReqForce,&StopAlign,0,&ReadForce,&Piezo_running,&RS232OK,&Running);


    return;
}

 

When I run the C++ code I can see both threads working by seeing data being updated in C++ front panel (data that belongs to C++) and in labview fron panel (data that belongs to labview). However, when I try to use any of the outputs coming from labview I can't get them updated....

0 Kudos
Message 4 of 5
(2,814 Views)

Hi majoris!

 

Thanks very much for your answer, it looks like this is a good option. I can imagine then passing data in the other way around by doing the same but with another dll called by both where the vi calls read data and the c++ writes into it... i'll try it... thanks again

0 Kudos
Message 5 of 5
(2,809 Views)