Jump to content

Testing LabVIEW-created DLL in c++


Recommended Posts

Hello:

I created a LabVIEW DLL in v8.2 that performs principal component analysis. I have successfully tested this within LabVIEW. Now I need to see if it will work in the C++ environment. I am asking for guinea pigs if anyone would volunteer to try this and tell me what is needed to get it working in that environment. In return, you get to keep this algorithm. I supply some sample time series of images within the .zip. Any help is greatly appreciated.

"This DLL calculates Principal Components (PCA) Images and stores them as .bmp images to disk. It is fairly rapid. Specify:

1) the folder location of the I vs. t .bmp images (char string)

2) the starting frame # I vs. t .bmp image to use in the analysis (I32)

3) the ending frame # I vs. t .bmp image to use in the analysis (I32)

4) the number of principal component images to calculate (I32)

I save the PCA images in the same folder as the original I vs. t bitmaps are stored. I name them *_PCA.bmp with * being equal to 1 to n where n is the number of PCA images you have chosen to calculate."

Sincerely,

DonDownload File:post-115-1165505846.zip

Link to comment
Hello:

I created a LabVIEW DLL in v8.2 that performs principal component analysis. I have successfully tested this within LabVIEW. Now I need to see if it will work in the C++ environment. I am asking for guinea pigs if anyone would volunteer to try this and tell me what is needed to get it working in that environment. In return, you get to keep this algorithm. I supply some sample time series of images within the .zip. Any help is greatly appreciated.

...

Hi Don,

I can help you to test by writing a C console program. Don't I need LV8.2 runtime engine to call LabVIEW created DLL? I haven't used LV8, if you have a quick link to where to download the LV8.2 runtime engine, that will help. I will test it over weekend if this is not too urgent for you.

Regards,

Irene He

Link to comment
Hi Don,

I can help you to test by writing a C console program. Don't I need LV8.2 runtime engine to call LabVIEW created DLL? I haven't used LV8, if you have a quick link to where to download the LV8.2 runtime engine, that will help. I will test it over weekend if this is not too urgent for you.

Regards,

Irene He

Hello Irene:

Thanks so much for your reply. In the project environment in LabVIEW 8.2, one can build an installer for a built application and the installer makes sure to include the run-time engine. For DLL building, the only thing that is offered is a build specification, i.e. there is no opportunity to build an installer as such for the DLL. Therefore, I am under the impression (and I may be wrong), that the only thing I need to supply are the .h files and necessary support files that are created during the DLL build process. Therefore, the only thing you should need are the support files I have in the .zip file. Can someone correct me if I am wrong on this?

There is a LabVIEW application note that discusses integration - http://zone.ni.com/devzone/cda/tut/p/id/3517. But it seems somewhat out of date. It does mention the LabVIEW run-time engine, but again this becomes somewhat confusing because there is no opportunity to build an "installer" for the DLL.

Sincerely,

Don

Link to comment
Don,

I think your wrong. You can build an installer for the dll? or not?

well the 8.2 runtime is here:

LV 8.2 runtime

I think the smaller one is sufficient for dlls (lvruntimeeng.exe)

Ton

I think you are right. I don't know why I thought differently. I have built installers for v8.2 applications and knew they were responsible for installing the LabVIEW RTE - I have to look and see what all is involved for building an installer for DLLs. Perhaps it is close to the same procedure. I don't know why I thought one did not need the LabVIEW RTE for DLL use in different environment. I had in my head that the DLL files contained all of what was needed. Irene: If you want me to try to build the installer for this, I can. But it might be that the RTE is all you need. Maybe Rolf or someone from NI can clear this up?????...

Thanks for your input.

Don

Link to comment
I think you are right. I don't know why I thought differently. I have built installers for v8.2 applications and knew they were responsible for installing the LabVIEW RTE - I have to look and see what all is involved for building an installer for DLLs. Perhaps it is close to the same procedure. I don't know why I thought one did not need the LabVIEW RTE for DLL use in different environment. I had in my head that the DLL files contained all of what was needed. Irene: If you want me to try to build the installer for this, I can. But it might be that the RTE is all you need. Maybe Rolf or someone from NI can clear this up?????...

Thanks for your input.

Don

Hi Don,

I have downloaded the LV8.2 RTE. (thanks Ton). Will try out and let you know if I need more files.

Regards,

Irene

Link to comment

Hi Don,

I have tested the PCA.dll. Attached is the simple console C program. Here are few points for the testing:

1.Yes, you do need to distribute the LV8.2 runtime engine to C programmer.

2.In the example I have hardcoded the image path to "C:\\Downloads\\Labview Downloads\\Ivst - with sample" if you want to run the "TestingPCA.exe" in release folder.

3.It produces many PCA images, not just one if I set "the number of principal component images to calculate" to say 5, it gives me 5 PCA images.

4. It seems there is LabVIEW vi searching dialog window poping up when runing the calculation. I thought that was because I moved the "lvanlys.dll" file to different location, but when I put under the same directory as TestingPCA.exe and PCA.dll files, it still poping up. So maybe some other dependancy files not in the same directoy as when you created the PCA.dll?

I hope this will help.

Best Regards,

Irene

Download File:post-42-1165855048.zip

Link to comment

Hi Irene:

Many thanks for testing this. Given the issue of the dialog below, it seems a good idea to follow this up by building the DLL installer to see if the LabVIEW VI searching dialog goes away. The problem is the installer is about 70 mbyte because it includes the RT engine which precludes uploading it here. I can put it on an ftp site for you to download if interested for one more round of this. Let me know. If you have run out of time, that is OK, and I appreciate this effort below.

Sincerely,

Don

ps. I created the folder heirarchy you suggested so I could test "TestingPCA.exe." I do not see the images anywhere. I used filelocatorpro to search all of c: just in case they were placed somewhere else. The console window popped up but went away so quickly, I could not for sure tell whether it recorded an error. I think it said it finished successfully. Any thoughts here?

Hi Don,

I have tested the PCA.dll. Attached is the simple console C program. Here are few points for the testing:

1.Yes, you do need to distribute the LV8.2 runtime engine to C programmer.

2.In the example I have hardcoded the image path to "C:\\Downloads\\Labview Downloads\\Ivst - with sample" if you want to run the "TestingPCA.exe" in release folder.

3.It produces many PCA images, not just one if I set "the number of principal component images to calculate" to say 5, it gives me 5 PCA images.

4. It seems there is LabVIEW vi searching dialog window poping up when runing the calculation. I thought that was because I moved the "lvanlys.dll" file to different location, but when I put under the same directory as TestingPCA.exe and PCA.dll files, it still poping up. So maybe some other dependancy files not in the same directoy as when you created the PCA.dll?

I hope this will help.

Best Regards,

Irene

Link to comment
Hi Irene:

Many thanks for testing this. Given the issue of the dialog below, it seems a good idea to follow this up by building the DLL installer to see if the LabVIEW VI searching dialog goes away. The problem is the installer is about 70 mbyte because it includes the RT engine which precludes uploading it here. I can put it on an ftp site for you to download if interested for one more round of this. Let me know. If you have run out of time, that is OK, and I appreciate this effort below.

Sincerely,

Don

No problem, I have some time. Let me know the ftp site when you are ready. But just doubting if including the RT engine will change things than install it separately. But you never know. I can give a try.

Regards,

Irene

Link to comment

ps. Irene: I retested your C executable after putting the original images in the correct directory in your heirarchy - it worked fine. Sorry about not doing that originall. I got 4 images, not 5, so I expect you hardcoded 4.....Don

Hi Irene:

I sent you a private message regarding ftp.

Sincerely,

Don

No problem, I have some time. Let me know the ftp site when you are ready. But just doubting if including the RT engine will change things than install it separately. But you never know. I can give a try.

Regards,

Irene

Link to comment
Hi Irene:

I sent you a private message regarding ftp.

Sincerely,

Don

Hi Don,

I got your message and I have tested it. The lvanlys.dll has to be in the Data folder, then no popup window anymore (I think LV installer puts it there automatically), but I must have moved it to different location the first time for some reason, that was my mistake :) . Other than that, your DLL works great.

Regards,

Irene

Link to comment

GREAT!

Now when I hand this installer off to the c++ programmer who knows nothing about LabVIEW DLLS, what documentation do I need to provide him with other than what I originally mentioned to you (the inputs, outputs [in this case = none], and formats of such). In other words, after the installation, what do I have to tell him to do to get this working in c++? Is there anything special that he needs to do or you did?

Thanks much!

Don

Hi Don,

I got your message and I have tested it. The lvanlys.dll has to be in the Data folder, then no popup window anymore (I think LV installer puts it there automatically), but I must have moved it to different location the first time for some reason, that was my mistake :) . Other than that, your DLL works great.

Regards,

Irene

Link to comment

ps. Irene: I retested your C executable after putting the original images in the correct directory in your heirarchy - it worked fine. Sorry about not doing that originall. I got 4 images, not 5, so I expect you hardcoded 4.....

Yes, your right, it outputs 4 images, but I did specify 5 images, starting from image 11 to image 15, see below parameter declaration.

int numPCA=5;

int startFrame=11;

int endFrame=15;

GREAT!

Now when I hand this installer off to the c++ programmer who knows nothing about LabVIEW DLLS, what documentation do I need to provide him with other than what I originally mentioned to you (the inputs, outputs [in this case = none], and formats of such). In other words, after the installation, what do I have to tell him to do to get this working in c++? Is there anything special that he needs to do or you did?

Thanks much!

Don

You can just give him the full installation (including the LV8.2 runtime engine) and the function calling document (you can also put that in the PCA.h file, commenting out with //). That should be enough. You can certainly also give him my very simple example project in C if you want.

Regards,

Irene

Link to comment

Hi Irene:

Not exactly clear what you mean by 'function calling document' - do you mean the documentation on the inputs and their types as I described in one of my first messages above?

Sincerely,

Don

Yes, your right, it outputs 4 images, but I did specify 5 images, starting from image 11 to image 15, see below parameter declaration.

int numPCA=5;

int startFrame=11;

int endFrame=15;

You can just give him the full installation (including the LV8.2 runtime engine) and the function calling document (you can also put that in the PCA.h file, commenting out with //). That should be enough. You can certainly also give him my very simple example project in C if you want.

Regards,

Irene

Link to comment
Hi Irene:

Not exactly clear what you mean by 'function calling document' - do you mean the documentation on the inputs and their types as I described in one of my first messages above?

Sincerely,

Don

Hi Don,

That is exactly what I meant, sorry for the confusing term. It's the function description (like vi, what does this function do and the input and output parameter's type and descriptions).

Regards,

Irene

Link to comment

Hi Irene:

Thanks again. One more point regarding your results when running. The reason you got only 4 images even though you specified 5 is because the maximum number PCA images you can get is the result of the subtraction of (# of ending frame from original images - # of starting frame from original images). Since you specified 15 and 11, respectively, 4 is the maximum. The way you want to use PCA is to use pretty much all of the captured frames (I gave you 100 I think, so you'd start with 0 and end with 99; and really I had 225 to give but I just wanted to give you a subset so would take less memory). Then if you specified that you wanted 5 PCA images, you would not be limited by the start and end frame numbers in this case. You might want to try just so you see what a true set of PCA images can look like.

Once again, I appreciate your help.

Sincerely,

Don

Hi Don,

That is exactly what I meant, sorry for the confusing term. It's the function description (like vi, what does this function do and the input and output parameter's type and descriptions).

Regards,

Irene

Link to comment
  • 2 weeks later...

Yes, sorry for the late reply. Its operation has been validated against other language versions of PCA. I have a neater version of this code in state machine format that has separate steps in separate cases - but I think this version reading from left to right should be easy to decipher....Don

One other thing I would like to figure out is how one would create the LabVIEW DLL if the inputs and outputs were arrays rather than stored images. The handling of arrays, allocations of memory, and determining interpretation of outputs that I believe have to be passed as pointers rather than by value has confused me to this point with respect to DLL creation. I would be interested if someone has some thoughts on this.

Sincerely,

Don

Don

Would it be possible for you to share the VI that is performing the actually PCA?

BR

Anders

Sincerely,

Don

Download File:post-115-1167314982.llb

Link to comment
Yes, sorry for the late reply. Its operation has been validated against other language versions of PCA. I have a neater version of this code in state machine format that has separate steps in separate cases - but I think this version reading from left to right should be easy to decipher....Don

One other thing I would like to figure out is how one would create the LabVIEW DLL if the inputs and outputs were arrays rather than stored images. The handling of arrays, allocations of memory, and determining interpretation of outputs that I believe have to be passed as pointers rather than by value has confused me to this point with respect to DLL creation. I would be interested if someone has some thoughts on this.

Sincerely,

Don

Hi Don,

I know the way to pass in LabVIEW allocated array for C program to process, but never done the reversed way to pass in a C allocated array for LabVIEW to process, but I think there is a trick that you can use a C allocated input array (usually pass in as array pointer, the pointer can be treated like U32, so the pass in parameter maybe an integer, not an array directly) for LabVIEW to use, just I never need it, so I didn't bother to remember how, but I think Rolf has mentioned in info-labview some time, I didn't read very carefully :-(. But on the other hand, maybe there is a setting when you create LabVIEW DLL, that let you specify the input array as pointer, have you check this? Maybe then everything will be taken care of automatically.

The output array is easier, I think, because you can allocate the output array in LabVIEW, then output the array pointer to C program, C program can make use of this pointer.

I am not sure if I talked my mind clearly or not, anyway, something is better than nothing:-)

Irene

Link to comment
Yes, sorry for the late reply. Its operation has been validated against other language versions of PCA. I have a neater version of this code in state machine format that has separate steps in separate cases - but I think this version reading from left to right should be easy to decipher....Don

Thanks for the llb Don! A half year ago I made PCA on histograms of black and white images in order to analyse different process conditions (using matlab). It was quite efficent for the purpose.

BR

Anders

Link to comment

I thought about contacting Rolf directly when I first started this project. It does seem like he is a master when it comes to understanding the creation and use of DLLs in LabVIEW. I was hoping he might be reading this. I started a forum thread on NI discussion forum regarding this very topic (direct use of input and output arrays when creating LabVIEW DLL) awhile back but I have not gotten sufficient resolution to this issue. Passing by value cannot be done for arrays, and in my preliminary testing early on, I was not able to resolve how to interpret the output pointer to array and the like. I'm tied up now but need to revisit this again as time permits. A simple example regarding use of arrays rather than stored disk images pertinent to our PCA DLL creation effort would be appreciated if anyone would like to contribute.

Sincerely,

Don

Hi Don,

I know the way to pass in LabVIEW allocated array for C program to process, but never done the reversed way to pass in a C allocated array for LabVIEW to process, but I think there is a trick that you can use a C allocated input array (usually pass in as array pointer, the pointer can be treated like U32, so the pass in parameter maybe an integer, not an array directly) for LabVIEW to use, just I never need it, so I didn't bother to remember how, but I think Rolf has mentioned in info-labview some time, I didn't read very carefully :-(. But on the other hand, maybe there is a setting when you create LabVIEW DLL, that let you specify the input array as pointer, have you check this? Maybe then everything will be taken care of automatically.

The output array is easier, I think, because you can allocate the output array in LabVIEW, then output the array pointer to C program, C program can make use of this pointer.

I am not sure if I talked my mind clearly or not, anyway, something is better than nothing:-)

Irene

Link to comment
I thought about contacting Rolf directly when I first started this project. It does seem like he is a master when it comes to understanding the creation and use of DLLs in LabVIEW. I was hoping he might be reading this. I started a forum thread on NI discussion forum regarding this very topic (direct use of input and output arrays when creating LabVIEW DLL) awhile back but I have not gotten sufficient resolution to this issue. Passing by value cannot be done for arrays, and in my preliminary testing early on, I was not able to resolve how to interpret the output pointer to array and the like. I'm tied up now but need to revisit this again as time permits. A simple example regarding use of arrays rather than stored disk images pertinent to our PCA DLL creation effort would be appreciated if anyone would like to contribute.

Sincerely,

Don

Hi Don, maybe you can try to ask the question in info-labview. Rolf seems to be more active in info-labview. Or maybe you can send him a PM.

Irene

Link to comment
Hi Don,

I got your message and I have tested it. The lvanlys.dll has to be in the Data folder, then no popup window anymore (I think LV installer puts it there automatically), but I must have moved it to different location the first time for some reason, that was my mistake :) . Other than that, your DLL works great.

Regards,

Irene

In order to have the lvanlys.dll file in the same directory as the main dll you can change the directory location for the "Support file directory" to be the same as the "Destination directory". Not sure exactly how this would be done in the Project Explorer in LabVIEW 8 however.

I do this all the time since I don't like the support dlls to end up in a different directory than my executable and customize the location of other support files afterwards in the "Custom Destinations" dialog.

I thought about contacting Rolf directly when I first started this project. It does seem like he is a master when it comes to understanding the creation and use of DLLs in LabVIEW. I was hoping he might be reading this. I started a forum thread on NI discussion forum regarding this very topic (direct use of input and output arrays when creating LabVIEW DLL) awhile back but I have not gotten sufficient resolution to this issue. Passing by value cannot be done for arrays, and in my preliminary testing early on, I was not able to resolve how to interpret the output pointer to array and the like. I'm tied up now but need to revisit this again as time permits. A simple example regarding use of arrays rather than stored disk images pertinent to our PCA DLL creation effort would be appreciated if anyone would like to contribute.

Sorry for chiming in so late here but I have been swamped with project work lately and have not participated in any LabVIEW forums very much for quite some time (well no forums at all really).

And no I'm not really a master in creating LabVIEW DLLs but quite proficient in creating DLLs in Visual C and less proficient with other C compilers and then using them from LabVIEW in sometimes rather sophisticated ways ;-)

It seems you want a possibilty to pass an array from some caller to a LabVIEW dll and possibly return it back. Unless you want to burden the user of your DLL with LabVIEW specific memory manager calls (and have him link his application with labview.lib which won't work for non Visual C users normally) you will need to pass C style pointers as function parameters.

Sorry for only being able to show you here an example using the LabVIEW 7.1 application builder but I haven't used the LabVIEW 8 project explorer for DLL projects at all yet.

First you have your VI that contains an input array and output array of some type. Now you can either make a separate pointer parameter for each of those arrays or combine them in one. The second approach will have some performance advantages since less memory buffers need to be allocated.

Add your VI to your DLL project and configure the function prototype. Add a parameter for the array and set it to Input/Output type. Connect the VI input to your input array control and the VI output to your output array control and set it to pass the array ass Array Data Pointer. You can use the same length parameter for the Input and Output Length in which case LabVIEW will make the length parameter to be passed by reference. On calling the length parameter should contain the number of elements passed in the data pointer and on return the length parameter will indicate the number of elements LabVIEW copied back into the pointer. Et voila!

This will cause LabVIEW to generate glue code to allocate a LabVIEW handle, copy the data from the array data pointer into the handle, then call the VI. On returning from the VI LabVIEW will copy back the array data into the pointer and update the length parameter accordingly. You can't avoid copying the array data twice unless you require the user to directly provide LabVIEW handles but that is going to be a very big restriction for using your DLL and it still should be a lot faster than reading and writing the data from and to disk.

Attached is a small example for an Input/Output array DLL project for LabVIEW 7.1

Rolf Kalbermatter

Download File:post-349-1168555016.zip

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.