LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

RT target: multiple reads of one single-process shared variable possible?

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:

 

  • Control (contains timed loop)
  • Network (contains while loop)
  • Log (contains while loop)

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.

Unbenannt2.PNG

 

 

Then each of the three vi.'s reads one element of the abort array, in order to stop the corresponding loop.

Unbenannt.PNG

 

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



0 Kudos
Message 1 of 7
(2,302 Views)

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

0 Kudos
Message 2 of 7
(2,272 Views)
Your current method actually doesn't prevent what you're worried about, which means it's not something to worry about :) Your worry was that each read would "take" the entire variable so nothing else could see it, so you're using an array. The problem here is that you are reading the WHOLE array from each network variable each time you use it. The Index Array function doesn't tell the code to just take one element from the array- the whole array is read, then Index throws away all of the other elements. If you replace your existing code with a single Boolean it will work exactly the same.
0 Kudos
Message 3 of 7
(2,267 Views)

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.



0 Kudos
Message 4 of 7
(2,262 Views)

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.

0 Kudos
Message 5 of 7
(2,260 Views)

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

0 Kudos
Message 6 of 7
(2,253 Views)

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.



0 Kudos
Message 7 of 7
(2,214 Views)