LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

repeatedly calling a dll that contains a loop

Solved!
Go to solution

I would like to call a dll function which contains a while loop. This loop copies data from a buffer while a control signal 'on' is true:

 

void Get(double* x, double* y, double* z, double* Y, double* P, double* R, int on)
{
    int index = Index -1;

    while(on == 1)
    {
        if(index >= buffersize)
        {
            index = 0;
        }
        *x = buffer[index].Position[0];
        *y = buffer[index].Position[1];
        *z = buffer[index].Position[2];
        *Y = buffer[index].Angles[0];
        *P = buffer[index].Angles[1];
        *R = buffer[index].Angles[2];
        index ++ ;
    }
}

 

I would like to call this dll function once 'on' becomes true, and for it to complete once it goes false. I also want to be able to switch 'on' on and off, so that it can copy data from the buffer whenever I want. I haven't been able to figure out a way of doing this, and whenever I step through the program it doesn't seem to "stick" when the Get function is called (i.e. the while loop inside Get is running), as I would expect it to.

 

Thanks for any support.

0 Kudos
Message 1 of 5
(3,313 Views)
Solution
Accepted by chilenomikejones

I assume "Index", "buffersize", etc, are static variables?

 

In any event, once you've called the function LabVIEW waits for the function to complete. You cannot dynamically pass a new value for "on" while the function is executing. Note that this is not a LabVIEW issue. The same would hold true in using that DLL from any other programming language. What you would need to do is to have the function use a static "on" and then provide a separate function to set this value. Note that you would also need to configure the CLFN to be "reentrant".

Message 2 of 5
(3,295 Views)

 


@smercurio_fc wrote:

I assume "Index", "buffersize", etc, are static variables?

 

In any event, once you've called the function LabVIEW waits for the function to complete. You cannot dynamically pass a new value for "on" while the function is executing. Note that this is not a LabVIEW issue. The same would hold true in using that DLL from any other programming language. What you would need to do is to have the function use a static "on" and then provide a separate function to set this value. Note that you would also need to configure the CLFN to be "reentrant".


static variables and reentrancy together are utterly evil. As long as you gurantee that only one function accesses it to write to it and you don't have some race condition in reading and writing it doesn't cause real troubles, but it is so easy to mess up here that I simply refuse to do such things myself. Also you should consider that the uglyness is hidden inside the DLL and in a few months from now you may edit the LabVIEW program and not remember that uglyness and since it is not in the LabVIEW diagram not have an easy way to notice nor debug it once a seemingly small change to your LabVIEW code starts to behave all bad.

 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 3 of 5
(3,274 Views)

Thank you for your replies. I think I will try to find some other way of doing this in order to avoid future complications.

0 Kudos
Message 4 of 5
(3,259 Views)

 


@rolfk wrote:

 

static variables and reentrancy together are utterly evil. As long as you gurantee that only one function accesses it to write to it and you don't have some race condition in reading and writing it doesn't cause real troubles, but it is so easy to mess up here that I simply refuse to do such things myself. Also you should consider that the uglyness is hidden inside the DLL and in a few months from now you may edit the LabVIEW program and not remember that uglyness and since it is not in the LabVIEW diagram not have an easy way to notice nor debug it once a seemingly small change to your LabVIEW code starts to behave all bad.

 

I never said it was a particularly good idea. However, the poster wanted to know how to do it, and I explained what would have been required, since you obviously can't change a function's parameters once it's called.

 

Also, I never subscribe to the "utterly evil" category for programming constructs. Smiley Wink

0 Kudos
Message 5 of 5
(3,243 Views)