LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid creating event cases for each individual button on a repetitive control

I am writing a program that uses a DQMH module to control motors, and there are 4 motors with identical controllers, each with a clone of the same module. There's a front panel in an overarching program with a cluster for each motor [see screenshot].

 

Nokaroa_0-1747921419642.png 

 

In the app's event loop, there's a data cluster that stores the DQMH module IDs. The only way I can really think of to handle all of these controls is to add to the event structure an individual case for each button, "Source 1 motor.Forward", "Source 1 motor.Reverse", Source 1 motor.Stop", etc x 4. That's 12 nearly identical cases being added to the event handler. Can anyone think of a cleaner way to do this? I want the clusters to all be individually visible. Otherwise, I would only have one of these control clusters and a selector for which motor.

 

Labview 2025, latest DQMH

0 Kudos
Message 1 of 6
(149 Views)

You can make the control a 2D (2x2) array of clusters, have a value change event for it, then see which one changed (by comparing new and old value from the event data node).

 

(It is difficult to give specific advice without seeing the code details)

0 Kudos
Message 2 of 6
(141 Views)

@Nokaroa wrote:

I am writing a program that uses a DQMH module to control motors, and there are 4 motors with identical controllers, each with a clone of the same module. There's a front panel in an overarching program with a cluster for each motor [see screenshot].

 

Nokaroa_0-1747921419642.png 

 

In the app's event loop, there's a data cluster that stores the DQMH module IDs. The only way I can really think of to handle all of these controls is to add to the event structure an individual case for each button, "Source 1 motor.Forward", "Source 1 motor.Reverse", Source 1 motor.Stop", etc x 4. That's 12 nearly identical cases being added to the event handler. Can anyone think of a cleaner way to do this? I want the clusters to all be individually visible. Otherwise, I would only have one of these control clusters and a selector for which motor.

 

Labview 2025, latest DQMH


Use the name of the button as a tag, like "STOP:: source 1 motor" then make a vi that extracts the name of the motor and the function from the button name. Place all the fp controls into a cluster, make one user event case for the cluster value change. Place the name/function extraction vi in the event case that then calls the appropriate code depending on the name and function of the button that was pressed. Now you have a single event case that handles any button push. 

______________________________________________________________
Have a pleasant day and be sure to learn Python for success and prosperity.
0 Kudos
Message 3 of 6
(115 Views)

Huh, interesting. I wouldn't think of parsing the string tag. I think I'll try this 

0 Kudos
Message 4 of 6
(108 Views)

Here's a quick example how to use a 2D array of clusters and find which one has changed. (To be used for further decisions! You can easily reduce the 2D indices to a single index if needed)

 

altenbach_0-1747929833108.png

 

altenbach_0-1747929970122.png

 

 

0 Kudos
Message 5 of 6
(96 Views)

 


@Jay14159265 wrote:


Use the name of the button as a tag, like "STOP:: source 1 motor" then make a vi that extracts the name of the motor and the function from the button name. Place all the fp controls into a cluster, make one user event case for the cluster value change. Place the name/function extraction vi in the event case that then calls the appropriate code depending on the name and function of the button that was pressed.


Since the controls are identical, you don't need to have all the controls in a cluster. Have the same event case handle the Value Change for all those motor controls. Then use the property reference Control Label to determine which control was pressed.

Message 6 of 6
(72 Views)