From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

buttons does not work properly

Hi,

 

I have made a simple user interface with several buttons, arrays, numeric input fields etc...

I wanted to make one if the buttons a start button, meaning only after being pressed the rest of the code can be executed.

For that matter i connected a button to a conditional structure and inserted the rest of the code into a while loop (separate from the if structure). then i connected the output of the button to the top condition of the while loop.

The code does what i want, except for the fact that when i change the button's state during run it does not respond, so if i start with the button on the code goes into the while loop, if i click on it while running it shuts the function half way through (as i want at the moment), but if i click on it again it indicates that it is on, however it does not execute the code again.

same goes if i start with the button off - if i turn it on while running it will not respond.

Any idea what could be the reason? is it the code? is something crooked in the way LV works on my computer?

 

Thanks in advance.

 

p.s.

1) I use conditional with the button cause i want to open a session in the future when the button is pressed

2) i have no access to my code until sunday, and i hope for help before i arrive to work, so i will send a picture of the code as soon as i can.

0 Kudos
Message 1 of 14
(2,123 Views)

The reason is that you coded it incorrectly.  Just do it right, and it will work fine.  I didn't try to reconstruct your code from your description; and neither will anyone else.  Post your VI if you want anyone to help fix it.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 14
(2,107 Views)

@Aqua- wrote:

I wanted to make one if the buttons a start button, meaning only after being pressed the rest of the code can be executed.


Yes, we cannot troubleshoot verbal descriptions. The correct way is to use a state machine architecture where the initial idle condition is just one of the possible states.

 


@Aqua- wrote:

 

2) i have no access to my code until sunday, and i hope for help before i arrive to work, so i will send a picture of the code as soon as i can.


We actually strongly prefer if you could attach the actual VI (or a simplified version). Pictures are hard to debug and often too ambiguous.

0 Kudos
Message 3 of 14
(2,068 Views)

Yes, we cannot troubleshoot verbal descriptions.

We actually strongly prefer if you could attach the actual VI (or a simplified version). Pictures are hard to debug and often too ambiguous.


Yeah i understand really... I will send here the VI as soon as i can, thanks

0 Kudos
Message 4 of 14
(2,040 Views)

hi. so i am attaching my VI. I have improved my code, yet it still all depends on whether the "initialize" button is pressed before i start the program. if it is then the relative move works, if it is not pressed then no matter what i do the relative mode doesnt work

0 Kudos
Message 5 of 14
(2,015 Views)

Hi Aqua,

 


@Aqua- wrote:

it still all depends on whether the "initialize" button is pressed before i start the program. if it is then the relative move works, if it is not pressed then no matter what i do the relative mode doesnt work


This is one the "other problems" in your VI as mentioned in your other thread!

 

What will happen to the big WHILE loop when "initialize" is not TRUE when you run your VI?

The VI does exactly what YOU have programmed to do!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 14
(2,004 Views)

@GerdW wrote:

Hi Aqua,

 


@Aqua- wrote:

it still all depends on whether the "initialize" button is pressed before i start the program. if it is then the relative move works, if it is not pressed then no matter what i do the relative mode doesnt work


This is one the "other problems" in your VI as mentioned in your other thread!

 

What will happen to the big WHILE loop when "initialize" is not TRUE when you run your VI?

The VI does exactly what YOU have programmed to do!


i get your point here, and when i follow the flow of my code with a breakpoint it is indeed in an infinite loop, however i dont get it.

The LV documentation states that the continue if true clause executes as long as 'True' is being sent to the loop.

Now:

1) if i start the program with a 'True' everything works well. if during run i change the button to 'False' the loop exits, but if i try to press it again to 'True' it will not work.

2) if i start the program with 'False' the program wont go into the loop, and then if i press the button again it still won't go inside.

 

What i conclude is that outside the  loop, even on continuous run the change of the button outside the loop does not work and im not sure why

0 Kudos
Message 7 of 14
(1,964 Views)

Hi Aqua,

 

you still don't understand the basic THINK DATAFLOW principle of LabVIEW…

 

This is the core problem in the VI:

 


@Aqua- wrote:

The LV documentation states that the continue if true clause executes as long as 'True' is being sent to the loop.

Now:

1) if i start the program with a 'True' everything works well. if during run i change the button to 'False' the loop exits, but if i try to press it again to 'True' it will not work.

2) if i start the program with 'False' the program wont go into the loop, and then if i press the button again it still won't go inside.

 

What i conclude is that outside the  loop, even on continuous run the change of the button outside the loop does not work and im not sure why


Your conclusion is wrong…

When the button is TRUE before the loop is started then the loop will run forever.

When the button is FALSE before the loop is started then the loop will iterate just once (it's a while loop!).

All this is dictated by THINK DATAFLOW!

 

Your case 1) cannot happen: the value of the button is only read once before the loop. No matter how often you switch the button it will NOT affect the iterations of the loop anymore!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 14
(1,960 Views)

To add what GerdW stated, you should...

 

  • Right click on where the Boolean input is in the While Loop and select "Replace with Shift Register"
  • Wire across (most likely) the stop button's output to the left side of where the other shift register would be on the left side of the while loop
  • Change the conditional terminal in the while loop from "Continue if True" to "Stop if True"

 

Beyond that, it looks like you have is a Simple State Machine. Look into that once you have this working the way you want.

0 Kudos
Message 9 of 14
(1,947 Views)

I also wired across the Initialize and Home button because you didn't need those Boolean constants. The button is the Boolean constant. Remember, DATAFLOW.

0 Kudos
Message 10 of 14
(1,941 Views)