LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create a DLL in Project and call the DLL from LabVIEW

I am in a situation in which we are developing LabVIEW code along. We have to interface with other groups in our company and some outside companies. Although we have just received version 8.2, we are still at 8.0, until we can coordinate with other groups to upgrade. We still have one company that is using version 7 (I can not control this). Our software publishes data, using NI Data Socket, for use by other programs. We have many workstations which may access this data. We have various processes that publish data. To make it easier for other groups and companies to access this published data, without having to explain how our software functions, and for easier maintenance in the future, I developed a user interface function which would allow a user to send a list of measurements that they would like data on and the software would return a list of published data corresponding to the list of measurements that were requested. I created a VI to do this using LabVIEW 8.0. I use Project to create a DLL using that VI as source (prehaps I have not created the DLL properly with the limited options available). Listed below is the .h file generated by Project.
 
____________________________________________________
 
#include "extcode.h"
#pragma pack(push)
#pragma pack(1)
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
 long dimSize;
 LStrHandle String[1];
 } TD1;
typedef TD1 **TD1Hdl;
typedef struct {
 LVBoolean status;
 long code;
 LStrHandle source;
 } TD2;

void __stdcall PublishedDataUserInterface(TD1Hdl *MeasurementIDS,
 TD2 *errorInNoError, double PublishedData[], TD2 *errorOut, long len);
long __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
#ifdef __cplusplus
} // extern "C"
#endif
#pragma pack(pop)
__________________________________________
 
The LabVIEW VI PublishedDataUserInterface has two inputs. MeasurementIDS is an array of strings. errorInNoError is the standard LabVIEW error cluster.
The LabVIEW VI PublishedDataUserInterface has two outputs. PublishedData is an array of double precision. errorOut is the standard LabVIEW error cluster.
 
I am now writing a test VI to see if I can access the function within the DLL. I have been having problems and decided it might better to get some expert help.
 
I have tried different data types even using the Adapt to Type. But I still have problems. If anyone can tell me EXACTLY what Type, Data Format, etc. that I need to use in the Call Library Function to access this function in the DLL, I would be gratefull.
 
Thank you in advance for your help !!!
 
0 Kudos
Message 1 of 7
(3,311 Views)
I kinda solved this issue.
 
Using LabVIEW 8.0 Professional version, I was able to create a VI that executed the code in the DLL. I verified this by putting pop up messages into the DLL code to show me that it received what I sent in the way of input data. It also returned output data.
 
 
Now the first of the other two problems. The system I normally work on has LabVIEW 8.0 Basic version on it. When I attempt to open this same VI on the Basic version, LabVIEW generates a pop box stating:
 
LabVIEW.exe has encountered a problem and needs to close. We are sorry for the inconvience.
If you were in the middle of something, the information you were working on might be lost.
 
 
The second problem: When I ran this VI on the LabVIEW professional version. I received a returned error. The error deals with attempting to use the DataSocket Open function. The error code being returned is number 56. One of the possibilities is a timeout issue. I set the timeout value to 1 and 5 minutes and the DataSocket Open function waited 1 and 5 minutes each time before returning the error. So I do not think it is a timeout issue. Also, I made a copy this VI and instead of calling the function in the DLL, I called the VI that I used to create the DLL directly. Every thing worked fine in that configuration. If I were to guess, I would think that perhaps when I create the DLL that LabVIEW is not getting everything it needs for the DLL to function properly with DataSocket. Is there any DataSocket functions, libraries, DLL's, that I need to make sure are being placed into my DLL. If so, how do I do this.
 
Thank you for any help on these issues.
 
P.S. Does LabVIEW 8.2 fix any of these issues?
 
 
0 Kudos
Message 2 of 7
(3,300 Views)

Hi Bill,

Can you post the VI and dll ?

Tunde A., Application Engineer, National Instruments.

0 Kudos
Message 3 of 7
(3,269 Views)
I have taken my VI's and trimmed them down to 1 VI with the basic code we are attempting to use. Since I last posted, I have noticed a few other things.
 
1. When I created the project and selected my source file, Project populated the call parameters as shown in the .h file in my first post. I could not get the published data to be returned. However, when I changed the Project initially defined definition for the Published data to what it is defined within the enclosed project and .h files, the published data is returned.
 
2. While on the machine with LabVIEW Professional version, if I execute the "Test DLL.vi" I get the error. If I get out of LabVIEW and then execute the "Test NO DLL.vi", which calls the VI without going through the DLL, its works fine. I also noticed that if I close Labview and then execute "Test DLL.vi" again, it still fails. But, without closing LabVIEW, if I execute "Test NO DLL.vi", and then execute "Test DLL.vi" immediately afterwards, it executes without the error.
 
3. If I atempt to open "Test DLL.vi" on my LabVIEW Basic system, I get the LabVIEW crash that I mentioned in my previous post.
 
 
I hope this helps you track down the problem.  Thank you for your help !
0 Kudos
Message 4 of 7
(3,264 Views)

Hi Bill,

I am currently working on this issue and will get back.

Tunde A.

0 Kudos
Message 5 of 7
(3,238 Views)

I was unable to build the dll as the "Data Socket Quality.ctl and ARINC FMC Publish Measurement.ctl" custom controls were missing. I will suggest testing the dll with version 8.2. It has a new "import dll" wizard that automatically creates a VI that makes call to the dll. To use the dll import wizard, select Tools-> Import-> Shared Library (.dll) from the project explorer. Besides, is the final goal to call this dll from LabVIEW or another programming environment?

I will appreciate if you can post the custom controls.

Tunde.

0 Kudos
Message 6 of 7
(3,218 Views)

In response to your comments:

1. Yes, I did forget to include the customs controls. If you right click on the control and select "Disconnect from Type Def." it will keep the control and remove the link to the custom control.

2. The final goal ... ?  I can not go into the sepific details of what we are doing. We have developed software that other groups within our company and external to our company will need to interface to. Our software will publish data on difference systems within our network. The other groups will need to access that data. Since we have different types of data from different sources being published on different systems, I developed an interface tool that will allow the user to perfrom a simple call and the requested data to be returned without the user knowing where it came from, how it was being published, etc. At this point, we have one company using LabVIEW 8.0. We have another company that is still using LabVIEW 7.1 (argh!) and questioned why they should upgrade to the latest version. I was told that we may have groups writing their code in C++. I know, what a mess. I really do not know who the other groups are and what language(s) they might be using. Temporarily, I have created a LabVIEW 8.0 and LabVIEW 7.1 LLB with the interface to my program so that they can test their software. I would eventually like to have a DLL so that we can make changes when ever we need to and not be concerned with making many different interfaces for these people ( 8.0 LLB, 7.1 LLB, etc.). Perhaps that is not the best approach or possible.

3. I did install 8.2 on one of our computers. I tried the "import dll" feature. I had issues and decided it was not relievant to my problem. I decided to not spend any more time on it. However, I did include a zip file with the files in it in case you are interested.

 

I did determine that the problem is in the "DataSocket Open" function. It seems to behave differently when run in LabVIEW (7.1, 8.0, and 8.2) when I call the function directly and opposed to when I call it using the DLL. I have included 2 zip files relating to this.

In the 1st zip file, I popup windows if an error is detected and when I start DataSocket. I did this to try and determine where the errors are coming from. I ran the program with DataSocket already running and when it was not already running. I ran it directly and through the DLL. I found that it generated different error messages when it was being called from the DLL. I also added a loop and determined that the error is only generated on the 1st pass when a DataSocket is open using the DLL. After that is seems to work. Outside of the DLL it works fine.

In the 2nd zip file, I do not popup error windows. This makes it easier to see the 1st error message and then it working fine.

I did create a file to publish data to that I could verify that my function was reading the published data.

 

My educated guess is that some parameter(s) is/are not being initialized properly when running from the DLL as opposed to being run from LabVIEW, that the create DLL function is not formatting the call properly so that the data is being passed correctly, or that some/all of the input data is not being used until the next call. I work as a sub-contractor. For the right price, I would be willing to come on down and help NI debug their DataSocket code.

 

0 Kudos
Message 7 of 7
(3,198 Views)