LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger multiple events with dynamically registered value signaling

Solved!
Go to solution

I have different controls for some pumps.

I want to stop all of them with an Emergency Stop button.

 

I use Event Structures to handle all the user's commands.

 

In the previous version of my code, I was registering all the events statically in the same vi. But in order to make the program compact and modular, in the attached version of the code I use the references of the controls and I pass them to a subvi. In the subvi I register the events of these references and I link the "event registration refnum" to the Dynamic Events terminal of the Events Structure.

 

Everything works, except for the Emergency Stop.

I cannot use a reference of the Emergency Stop button to trigger the event, because the Emergency Stop opens other vi files for further confirmation of the user.

When the Emergency Stop is confirmed by the user, I use the Value Signaling property to trigger the Stop Event of all the Event structures of the sub-VIs that control the pumps.

Previously I had only one Value Signaling to trigger multiple events, but I saw that I create race condition and the first Event Structure that handles the event, it deletes it from the queue and the other Event Structures cannot get the event.

So, I use as many boolean's Value Signaling as many pumps I have.

But it still does not trigger all the events.

 

Another detail is that I don't use the "Unregister for events function" in all the sub-VIs that have the Event Structures. I didn't see any difference with this function or without it..

 

Apparently, I am missing a clue of a general principle of LabVIEW.

 

I attach the whole project for demonstation.

The main.vi starts the program.

0 Kudos
Message 1 of 7
(5,315 Views)

Sadly, this code is anything but "compact and modular".  Nothing fits on a single screen (I estimate I would need 5 across by 10 tall monitors to see your Main VI block diagram), there are multiple unclustered wires and controls all over the place, and it is accordingly too tiring to try to follow the logic.

 

Here are some suggestions.

  • Create a Cluster with all of the controls and indicators for a single pump.  Be sure to create (and use) a TypeDef for this Cluster.
  • Avoid creating controls that appear to be the same (like FA1, FA1, and FA1 on the Front Panel).
  • Consider the possibility of combining a dozen Pump Controls (Clusters) into a single Pump Array -- one Array Wire is much cleaner than 12 Cluster wires, and is much cleaner than 60-100 individual Control wires.
  • Start small.  Figure out how to control just 1 Pump with an Emergency Stop button.  Then add a second.  When you have "more than one" worked out, you can expand to hundreds of pumps pretty easily.
  • I'm unclear why and how you are using Events.  Suppose you have a Pump Cluster Control (like I mentioned above).  If you have a Value Change Event on the Cluster, you can pass the entire Cluster to a sub-VI that "runs" that pump.  It can, in turn, compare the Controls with a set of values that it saved from its previous call (that represents the controls "as they used to be"), figure out what changed, and take the appropriate Action.
  • If you simplify your code, it will probably become "obvious" how you can pass knowledge of the E-Stop request to all of the Pump Routines.  You'd want to take a look at the processing within a single Pump routine to decide where to safely insert the E-Stop action (you need the Pump routine to be "responsive", i.e. not blocked for long periods of time unable to respond to an E-Stop).

Try simplifying, and come back (if necessary) with something that fits on at most 4 screens (you should be able to get it down to a single screen -- don't be afraid to use Clusters and Arrays for bundling wires, and sub-VIs to encapsulate code).

 

Bob Schor

Message 2 of 7
(5,251 Views)

Thank you very much for your suggestions.

My time is limited though, so for the time being I attach again the project with the same architecture but simplified to one pump.

I use the Event Inspector Window to see the events that are created (attached screenshot in zip file).

I see that the problem is not only for the Emergency Stop, but for all the buttons. When I press the buttons fast and continuously, I see that some events are "flushed", so they are not handled.

If the vi has a lot more controls, this happens more often, so the buttons need to be pressed twice or more.

Why this happens ?

How can I ensure that every single event that is generated, is handled by the Event Structure ?

0 Kudos
Message 3 of 7
(5,191 Views)

Emergency Stop means "Everything Shuts Down, Now, No Questions Asked!"'.

 

Do you know about the Mechanical Actions of Boolean Controls?  Almost all Stop Buttons (and most Start Buttons) should have the Latch When Released action.  They should (and, indeed, if they were latched, could) never be part of a Value Property Node (nor a Local Variable).  Try to avoid Value Property Nodes.  Instead, rely on setting default values properly (you can consider using the Reinitialize All to Default Method on the Main VI).

 

I don't understand all of your loops.  What, in particular, is the Timied Loop doing?  

 

I recommend that you write a brief (1-2 pages) description what you are trying to do.  Don't worry about how to do it, just concentrate on what.  Also, I'll note that you obviously never opened the code you attached, as i doubt you would have omitted some of the TypeDefs.

 

Bob Schor

 

 

0 Kudos
Message 4 of 7
(5,173 Views)

The logic that I want to implement is the control of the pump through the Start, Stop, Plus & Minus buttons, in an event structure.

The events of these buttons are handled by different event cases which set the value (setpoint) of the Analogue Output .

In order to have a ramp for the pump's control, the module's Analogue Output channel is not changed by the Start, Stop, Plus or Minus buttons but from the Timeout of the Event Strucure. The Timeout case is able to identify how much time has passed and it changes the value of the Analogue Output slightly, until it reaches the setpoint.

 

The Mechanical Actions of the Boolean Controls are set to "Switch" and not to "Latch" because I want to show in the interface that they are pressed till the process is finished. So I want to control the value property.

 

The Timed Loop is the main loop of the main.vi that has all the controls. If I don't store the controls in a while loop, I cannot change their value more than once.

 

My question is why in the Event Inspector Window I see that some events are flushed?

Let's focus on the events that are generated by the Plus & Minus buttons.

The events are handled by the Event Structure that is in the subvi PumpAO-control.vi

I pass the references of the controls to the subvi, I connect them to the "Register for Events Function" and the output of this function is connected to the "Dynamically Registered Events" terminal of the Events Structure.

 

If I delete the "Unregister for Events Function" on the right side of the subvi's Event Structure, then the events are neved flushed, but the click of a button can generate the same event in multiple queues.

 

The code version 2 that I attached is the simplified version, in which I deleted everything and I left only the controls of one pump. It has only one TypeDef, the one that has the references of the pump's controls.

 

Regards,

Nikos

 

 

 

 

0 Kudos
Message 5 of 7
(5,098 Views)

In my previous attachment, I forgot to delete some unused clusters indeed.

I attach again the sample code.

I attach also another screenshot of the Event Inspector Window that shows an event in multiple queues, when the "Unregister For Events" Function is not used on the right terminal of the "Dynamic Events".

0 Kudos
Message 6 of 7
(5,053 Views)
Solution
Accepted by topic author nikosfs

The problem of this thread is re-posted more clearly and it is solved here:

https://forums.ni.com/t5/LabVIEW/Static-vs-Dynamic-Events-Some-dynamic-events-are-flushed/m-p/318239...

0 Kudos
Message 7 of 7
(4,967 Views)