LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Complications when using LabVIEW user events as a callback solution

I'm having some issues when using an implementation for callbacks from a third party C++ DLL with LabVIEW.

To solve the problem of not having callback functionalities compatible with C++ in LabVIEW, I create an intermediate DLL which posts user events to my LabVIEW code inside my C++ callback function. This is based on an example I found somewhere on the website, using the PostLVUserEvent in the C++ code.

The issue is that this involves a DLL call in a seperate thread inside my LabVIEW VI. I want to stop this thread once I press the Stop button of my VI. However, I do not seem to find a way to accomplish this. I do not have any means to communicate with the DLL after the function is called, since it is in essence just an infinite loop. I think I need some control/indicator inside my VI which I modify when Stop is pressed. I tried to just pass a control as a pointer inside the DLL when calling it first, but this does not seem to solve anything. I do not find any way to have some modifiable variable inside my VI which I can monitor from my C++ DLL.

I hope it's a little clear, and maybe someone has an idea which I overlooked. Now I always have to stop LabVIEW the hard way, killing the process.
0 Kudos
Message 1 of 2
(2,761 Views)
Maybe I posted this question too quickly, I already found the solution Smiley Happy I use a global int inside my C++ code, which is initially equal to 0. I change it to 1 using a second function, and check it inside my main loop to see if the thread has to be stopped.

For those of you who are interested, the concept of the C++ code looks a bit like this :



int ready = 0;

LVUSEREVENT_API void SendEvent(LVUserEventRef *rwer)
{
    float data;

    ready = 0;

    while(!ready)
    {
        data = rand()/(float)RAND_MAX;
        Sleep(1);
        PostLVUserEvent(*rwer,(void *)&data);
    }

    return;
}

LVUSEREVENT_API void StopLoop()
{
    ready = 1;
}




0 Kudos
Message 2 of 2
(2,752 Views)