03-13-2019 04:20 AM - edited 03-13-2019 04:23 AM
Hello Labview friends,
in my application it is necessary to stop the vi.'s running on the RT target when a button is pressed on the host PC. With the help of a network published shared variable coming from the host PC, I can pass the stop-command over TCP/IP down to the RT target. Now, on the target there are three VIs running:
Inside the Network.vi, which is for communication with the host, I pass the stop-command to an 3x1 Single-process shared variable containing the same boolean in each entry.
Then each of the three vi.'s reads one element of the abort array, in order to stop the corresponding loop.
Is there a more elegant way to stop multiple loops with one boolean value? I think that with a 1x1 single-process shared variable, one reader can claim the value for himself, leaving the other readers waiting or even missing the value (?). I want to avoid global or local variables. Are Notifiers a solution perhaps? I am aware that there is this knowledge article:
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019LmXSAU&l=de-DE
but here we have not only multiple loops, but different vi.'s also.
Best regards
Lysandros
03-14-2019 09:42 AM
Hi Lysandros,
You can actually read directly from the StopCommand shared variable in all of your VIs without worrying about the value getting lost. Shared variables function as tag communication and store the most recent value that is written to the variable in a register. Unlike network streams or queues, this data persists until a new value is written to the variable. As long as StopCommand remains TRUE (is not overwritten by the host PC VI) long enough for each RT target VI to read the variable, TRUE will be read from the variable in each VI.
Best,
Duncan W.
Applications Engineer
National Instruments
03-14-2019 10:40 AM
03-14-2019 10:54 AM
Thank you both Duncan and Bert.
I suppose that the issue is, that as soon as the StopCommand is sent down to the RT Target the VI on the Host PC is also programmed to stop. Because of this, maybe not each loop received the value change in time. This is why I used the array option. I will make sure, that the Host PC vi stays on for a few more milliseconds, so as to ensure that each loops is stoped.
I recently also tried to solve this whole issure with an Notifier, but it didn't work as expected.
03-14-2019 11:04 AM
There is no functional difference between using an array and using a boolean as far as the Network Variables go. All of the Read functions are reading the entire variable.
If your variables are hosted on your host PC, won't the RT Target throw an error when the variable gets destroyed? You could trigger Stop on a Read error from the variable as well as a boolean True.
03-14-2019 12:03 PM
I echo Bert's sentiment that the RT Target will throw an error if the variable no longer exists when the target is trying to read from it. The variable shouldn't be deallocated until both the host and target have closed their variable references or stopped execution.
Are you seeing incorrect functionality in your program that makes you think that not all of your VIs are receiving the stop command?
-Duncan
03-18-2019 03:02 AM
I think that I stopped the Host PC to early, that's why not each VI terminated (they have different loop rates)
Thanks, I will try it.