09-10-2010 08:08 AM - edited 09-10-2010 08:11 AM
Hello,
I am working on a project that can receive and display data that is produced by a DLL.
The DLL performs mathematical calculations, which can take a while (minutes).
During its execution, the DLL should be able to inform LV that new data exist (say every five seconds).
These data (an array of numbers) should be appended to an array that grows gradually as execution of the DLL proceeds.
Some LV code will be used to start the calculations (making the initial call to the DLL) and to display the data that are received from the DLL.
Now my questions are:
How can LV be notified about the new data?
How can the data be transferred to LV?
Since I'm a real beginner on this topic, could someone please give me some hints or simple examples?
The DLL should be in C, because I already have a lot of code that performs the calculations in C.
Please do not hesitate to ask for more details.
After spending hours reading tutorials and discussion forums, I realize that this is not an easy topic, and I really would appreciate some help.
Thanks!
[I am using LabVIEW 2009 and VisualC++ 2008]
09-10-2010 08:33 AM
Generally, when LabVIEW calls a dll that LabVIEW thread stops until the dll returns. What you may want to do is write your dll with the intermediate functions callable from outside, so that you can pass the intermediate data out. You will also want to make the dll "thread safe" (there are white papers about this and dll's in general on this and the main NI site), which means it will run in any thread. The default, if it isn't thread safe, is the User Interface thread, meaning that while the program is in the dll your User Interface stops responding.
09-10-2010 09:28 AM - edited 09-10-2010 09:30 AM
I know it is possible to have several functions in one dll.
So with a thread-safe dll, can I call any of these functions at any time?
If so, would the following be a possible solution to the problem:
In the dll, i have two functions:
1) Function that receives initial values for computation from LV, and within a loop, performs the calculations.
2) Function that returns the intermediate values (either as return value or as a pointer) when it is called from LV during the execution of Function 1).
But how can i access the data in function 1) from function 2)?
The only way i can imagine is that i keep a global variable in the dll that stores the actual intermediate value(s). Or do i have some misconception here?
Thank you for helping!
09-16-2010 10:24 AM
Hello,
do you have the header file for the dll? So you could use the dll import wizard.
Do you have any documentation for the dll?
Link:
http://zone.ni.com/devzone/cda/tut/p/id/2818
Regards
Rüdiger
09-16-2010 11:10 AM - edited 09-16-2010 11:15 AM
Hello,
sorry! Forget what I mentioned.
Why the "calculation loop" have to be included in the dll? You could call the dll in a lv loop for each calculation.
If the dll should inform lv to read the calculated data you could use events.
http://zone.ni.com/devzone/cda/epd/p/id/1480
But I know your problem is to receive data from a running process inside the dll. I think what LV_Pro mentioned is right. You can solve the problem by creating a second process and realising a inter-thread communication inside the application (global variables). So the dll have to be thread safe (reentrant use).
Below you will finde examples for inter-application communication.
http://decibel.ni.com/content/docs/DOC-9136
http://zone.ni.com/devzone/cda/epd/p/id/6117
Regards
Rüdiger
09-17-2010 03:52 AM
Thank you, I will have a look at your suggestions.