10-13-2011 10:36 AM
I have 2 vis which communicate via datasocket. The behaviour of the second vi depends on whether the first vi is running or not, and both vis can be started and stopped independently of each other. I need vi 2 to be able to detect whether vi 1 is running or not. Simple, I thought, I'll have a boolean in vi 1 called Running which is set to True when the vi is running and False when it shuts down. I'll publish that vi to datasocket and have a matching boolean in vi 2 which subscribes to it.
It doesn't work, because as soon as vi 1 stops, Running disconnects and the matching boolean in vi 2 misses the fact that it got set to False before it disconnected, and just gets stuck in the True state.
So it seems to me there should be a "Is object connected?" vi or function somewhere, but I can't find it.
Is there another way to detect whether a vi is running or not? Preferably without using shared globals as I find that quite ugly, in fact I've switched to using datasocket from using shared globals because the latter just seemed like really ugly programming.
Note: I will have several variants of vi 1 with different names, so I can't just try to open a reference to the vi. That's why I wanted to use a datasocket object; all the versions of vi 1 can have a boolean called Running.
10-13-2011 11:30 AM
I found a solution. The subscribing boolean in vi 2 is now in its own little loop that executes every 50ms in parallel to the main program loop.
In vi 1 there is a delay of 500ms between the publishing boolean being set to false and the vi stopping.
That way the subscriber boolean has plenty of opportunity to read the False state of the publisher.