LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

run once when click on button

The event structure is definitely the way to go. Here are a few more tips:

  • Notice that the button should be set to "mechanical action: latch when released/pressed". If something should occur only once when pressed you don't want any "switch" action. The way latch action works, it will be true until the new value is read once by the code.
  • You definitely want a push button of some sort. A toggle switch as in your original code is not intuitive for latch action.
  • For the same reason, you should place the boolean terminal inside the event case that is triggered by it. If you e.g. place it outside the loop, it will never switch back because it never gets read by the code again.
  • You don't need a timeout case.
  • In your original code, you have two different string indicators, one in each case. This makes little sense. Once each case has executed once, they will never change and both always display the same two texts. You probably want a single text indicator after the case structure and feed it one of two text constant.
  • Maybe it is sufficient to place all the instrument configuration ouside the loop and configure it once at the start of the program. This way you only need to read the voltage and current when you press the button and can skip the initialization and configuration later. Of course this depends on your hardware and requirements. 
0 Kudos
Message 11 of 15
(2,395 Views)


 


@Mathias_P wrote:

I want to have a LV-programme running continously and perform a measurement every time someone clicks a button. Then it should be idle and wait for the next mouse click to perform the same thing.


Always do remember that, when you want something to get executed only once on the click of a button, then you should use a push-button with a Latch mechanical action. Moreover, this button should directly be connected to the case structure that executes the code because its inherent nature is that it ll retreat to False state only after its state is read in the code.

See the Help for more details on the various mechanical actions of boolean controls. Boolean indicators & Radio button controls wont ve user-configurable mechanical actions.

- Partha ( CLD until Oct 2027 🙂 )
Message 12 of 15
(2,376 Views)

Maybe this works better. It is switched when pressed.

Andries

0 Kudos
Message 13 of 15
(2,369 Views)

Andries,

I don't see the "logic" of all that complicated boolean gymnastics just to make a "switch until released" boolean to act like a latch action boolean. This does not make any sense! If you simply hook the boolean button directly to the case structure and change the mechanical action to "latch when pressed" you get exactly the same result, but with much less code.

I would also suggest to place a small wait statement inside the loop.

I also don't understand why the [i] indicator "False" is inside the case structure. Since [i] always increments, it is misleading to not update it in some iterations and show a stale value instead. It probably belongs outside the case structure.

0 Kudos
Message 14 of 15
(2,363 Views)
If you just switch until released the 'true part' of the case structure run until released (the true counter shows the amount of runs of the 'true part'). You are right about the latch when pressed. I just overlooked that option.
 
With 'i indicator False' I wanted to show how many times the 'false part' is executed. I understand that it does not really do this. sorry.
 
0 Kudos
Message 15 of 15
(2,353 Views)