LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I'm new to DLL's. I want to create a DLL using Labview which outputs an array. I built a VI that outputs an array...how do I turn it into a DLL


@Willie7 wrote:

If I am annoying you due to my limited knowledge in this space forgive me.


Not annoyed but it is weekend and this takes some serious time to answer properly. I can’t just invent this out of thin air in an eye blink.

 

Also this topic is very complex, in fact to complex for anyone who has not some serious C programming knowledge. So even if I cook you a pre configured solution with a lengthy explanation, you likely will stand in front of the same blocking wall as soon as you have to do a somewhat different solution. 

So let me look at it this evening (I’m in UTC+2.00) and see what I can come up with without having to write an entire book.

Rolf Kalbermatter
My Blog
0 Kudos
Message 11 of 17
(131 Views)

Rolf: I've taken up a lot of your time already and I apologize.

 

My rapid response to you was not to have you work over the weekend but a sign of respect to you for taking time over the weekend to respond to my query.  

 

Your time and expertise helps a lot of people and I do not want to interfere with you helping other people or your personal time.

 

I hopefully can get further assistance from my colleagues who are more familiar with C/C++ than I am. They are familiar with C/C++/PYTHON/etc but not familiar with Labview. 

 

Now that you have provided some information about the interface and what is required, we can get the interface correct and move on to the evaluation of our algorithms. 

 

One last question:  How do I provide a 'KUTO' or two to you ?

 

THANK YOU VERY MUCH FOR YOUR HELP.  IT is greatly appreciated.

 

Willie7

 

 

0 Kudos
Message 12 of 17
(120 Views)

I can't open your VI as it is in LabVIEW 2024 and I don't have that installed on my home machine. So I'm not quite sure what parameters are inputs and what are outputs.

 

One remark to start with: The len, len2 and len3 parameters are the length value for the three first arrays. Yes this is the LabVIEW default configuration when you select to create a DLL export from a VI but there is no need that you have to follow that first suggestion. It would be a lot more useful to rearrange those parameters and I personally would even rename them to some more concise but still useful names. All UPPERCASE variable identifiers in C are very ugly, there is a convention that all uppercase identifiers are for constants.

 

So your function prototype could then instead look more like this:

 

int32_t __cdecl Test_1(double SineWave[], int32_t lenSineWave, 
double IFIRInputArr[], int32_t lenInputArr, double IFIROutputArr[], int32_t lenOutputArr, 
Cluster *IFIRCoefficients);

 

I changed the int32_t error parameter into the return value of the function, choose shorter and not all uppercase variable names and placed the length parameters behind the according array param. This can all be done in the configuration dialog for each exported function by renaming the variables and rearranging them by moving them up and down.

 

As I'm not entirely sure which parameter is input and output and how you configured the actual export for the VI, I have to guess here a bit. So lets assume that the names are kind of indicative and the SineWave and InputArr are in fact inputs and the OutputArray is an output. And the arrays in the IFIRCoefficients are also inputs.

 

#include "Test1.h"

#define ARRAY_SIZE 2048
#define MODEL_SIZE 100
#define SUPPRESSOR_SIZE 50

int32_t MyFunction()
{
    int32_t status = MEMORY_ERROR;
    // Declare cluster parameter and initialize it all to 0
    Cluster cluster = {0];
    // Allocate arraya on the stack
    double sineWave[ARRAY_SIZE];
    double inputArr[ARRAY_SIZE];
    double outputArr[ARRAY_SIZE];
    double *temp;
    // Fill in the sine wave and input array
    .....
    // Set parameters in the cluster
    cluster.filterType = Enum_LowPass;
    cluster.interpolation = ??;
    cluster.ModelFilter = AllocateDoubleArray(MODEL_SIZE);
    if (!cluster.ModelFilter)
        goto exit;
    // Fill in ModelFilter array
    for (int i = 0, temp = (*cluster.ModelFilter)->passband; i < MODEL_SIZE; i++, temp++)
    {
        *temp = ......;
    }
    (*cluster.ModelFilter)->dimSize = MODEL_SIZE;

    cluster.ImageSuppressor = AllocateDoubleArray(SUPPRESSOR_SIZE);
    if (!cluster.ImageSuppressor)
        goto exit;
    // Fill in ImageSuppressor array
    for (int i = 0, temp = (*cluster.ImageSuppressor)->passband; i < SUPPRESSOR_SIZE; i++, temp++)
    {
        *temp = ......;
    }
    (*cluster.ImageSuppressor)->dimSize = SUPPRESSOR_SIZE;

    status = Test1(sineWave, ARRAY_SIZE, inputArr, ARRAY_SIZE, outputArr, ARRAY_SIZE, &cluster);
    if (!status)
    {
        // data should be now in the outputArr
    }
exit:
    if (cluster.ImageSuppressor)
        DeAllocateDoubleArray(&cluster.ImageSuppressor);
    if (cluster.ModelFilter)
        DeAllocateDoubleArray(&cluster.ModelFilter);
    return status;
}

 

This is very preliminary and with various assumptions but it shows you the principle. If your arrays are a lot bigger than 1000 elements you absolutely should avoid to allocate them on the stack like above but instead use explicit malloc() calls to allocate them on the heap (and of course free() them properly as soon as they are not needed anymore.

 

Generally it would be more easy to call from C (and Python) if you would pull out those two arrays from the cluster and pass as separate function parameters. This will require additional length parameters for these arrays too, but if you define them as array data pointer you can allocate them easily in the C program on the stack or through malloc() just as the first three arrays. And the nice thing about this is that you can also call such a function from Python without having to do super gymnastics with ctypes. You still need ctypes but simple array pointers are easy to make with ctypes.

Rolf Kalbermatter
My Blog
0 Kudos
Message 13 of 17
(115 Views)

You have given me a lot of good information, thank you !

 

For clarity, I can upload my VI for you to look at, if you wish to......just let me know what version of Labview you have at your location and I'll load the VI with that version so you can look at it, or if I've taken up too much of your time already, I'll go with what you've provided which is very helpful.

 

In either case, thank you !

 

Willie7

0 Kudos
Message 14 of 17
(105 Views)

To finish our discussion with a minimum of your time, the outputs of the VI are 1D,  double precision numeric arrays. 

 

They are LONG. 

 

Typical array length will be 250 samples/second for lengths as long as 20 minutes. or 250*60*20 or 300,000 samples per array. Perhaps as long as 400,000 samples possible total length.

 

  Ultimately there will be multiple 'channels' of data, each 1D, double precision  I will also include as a  U32 numeric the length of the arrays , input and output values.  

 

The Labview VI will preprocess the raw data with unique IFIR filters, Wavelets, and other algorithms to denoise the data.

 

IF you wish to see the Labview VI, I have labview 2011/2012 and 2024 on my home computer.  IF one of these would be compatible with your home version of labview and IF you'd like to see the VI, just let me know, otherwise thank you very much for your help and the education.

 

I reduced the VI complexity to just focus on the DLL to C/C++ interface needed to read the data in C/C++ and store it in the non labview environment, Windows O.S. and then possibly Android O.S. 

 

Again, please accept my sincere THANK YOU for ALL of your help and the corresponding education.

 

Willie7

 

0 Kudos
Message 15 of 17
(100 Views)

IF you wish to look at the VI, the following are the versions I have of Labview to match your version at your home....

 

LABVIEW 2019  64 BIT

 

LABVIEW 2021 64 BIT

 

LABVIEW 2022 Q3 64 BIT

 

LABVIEW 2024 Q1 64 BIT

 

Sorry for the previous error, I'm dyslexic

 

0 Kudos
Message 16 of 17
(97 Views)

It doesn’t matter which versions you have really. You always can do a “File->Save for Previous” and specify a version as far back as 8.0. If you do that for the project it will save all the VIs and build configurations in it too. Put the resulting files in a ZIP file and you got everything needed. My latest version I have here is 2020.

 

But I’m about to go to bed 🛌

Rolf Kalbermatter
My Blog
0 Kudos
Message 17 of 17
(90 Views)