From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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 not getting triggered from 2nd time onwards in an Event structure inside a while loop

Hi All,
I hope any of you can resolve my problem.
 
Application Description: 
In my application, I am using 4 sequences (0 to 3).  I'm performing some of the hardware related calibration tests during the first 3 sequences. During this procedure, euipment door should be closed and it will be locked  automatically. Once the test  finishes, it'll unlock the door but still the door will be closed (not locked). Upto here no problem. Problem is occuring in 4th sequence(sequence 3)
 
I am having 3 buttons on UI ( Print Report, Close, and Main Menu). After the hardware test is done, user opens and then closes the door of an equipment. Once the door is opened and then closed, control should go to the first sequence (sequence 0) and should again start the test. To sense the door open and door close, subVI is available.
 
In case if user doesn't open the door and still it is closed, it should wait for the button events continuously until the door is opened. Once the door is opened, same thing should be continued (continuous button polling). Now if the door is closed, sequence 0 should repeat.
 
Problem Description:
Buttons are not getting triggered properly. First time if I click CLOSE, it is getting triggered. But from the second time onwards its not getting triggered from UI and not accepting the input. Similarly for other buttons.
 
Connecting  Timeout delay with different values (-1, 10 etc.) also not  worked out .
 
I'm using  the same button event structure TWO times inside a case structure, i.e. in
both  FALSE and TRUE cases.  In TRUE case, there is a while loop around the event structure.
In FALSE case NO while loop around it.
TRUE case ---> Door opened first
 
FALSE case --->Door closed.
This case structure is within main While loop ( to make the control goes to Sequence 0).
 
Can u please suggest me the changes needed to resolve this? I'll be grateful to you. Below I'm attaching a file. If any subVI is not loading properly, it is not a problem. Assume that it is a Door sense VI. which gives bundled cluster o/p.
 
SubVI o/P
 
Sicere thanks in advance,
Krishna.
 
 
0 Kudos
Message 1 of 9
(3,464 Views)
Your problem is having two separate event structures. It doesn't matter than they are in case statements. Both will always capture events. Right click on the event structure and select help. In the help window, click the caveats and recomendations for using events to get a more complete explanation. You should be able to use a single event structure with case statements inside the event instead of the other way around.
Message 2 of 9
(3,458 Views)

Hi,

Thank you for this information. Now also I am using the event structure both in TRUE and FALSE cases of the case structure. But this time  I've deselected the check box at the bottom of the event structures in both the cases for all the events (i.e. locking the front panel). Now my prototype application seems to be working fine. I've to test the actual application which is similar to this on the real equipment after two days. Once if that is also done fine, I'll let you know about it.

I hope that you'll help me in future by suggesting me like this about the LabVIEW doubts. I'm beginner to the LabVIEW and self learning most of the things.

Once again sincere thanks and regards,

Krishna.

 

0 Kudos
Message 3 of 9
(3,443 Views)

Hi,

Thank you for this information. Now also I am using the event structure both in TRUE and FALSE cases of the case structure. But this time  I've deselected the check box at the bottom of the event structures in both the cases for all the events (i.e. locking the front panel). Now my prototype application seems to be working fine. I've to test the actual application which is similar to this on the real equipment after two days. Once if that is also done fine, I'll let you know about it.

I hope that you'll help me in future by suggesting me like this about the LabVIEW doubts. I'm beginner to the LabVIEW and self learning most of the things.

Once again sincere thanks and regards,

Krishna.

0 Kudos
Message 4 of 9
(3,441 Views)

Your code is is very tangled and uneccessarily complex. You should redesign it completely. Stacked loops are often not a good idea and multiple event structures in seperate parallel cases is very bad. Your little event checkbox is only a bandaid solution, temporarlily masking serious flaws in your code. This is NOT the way to solve it.

Your outer loop has currently no purpose whatsoever. Can you explain why it is there?

For example, look at the first small loop on the left. If for example the subVI always generates an error, the loop will never finish and your VI will be locked up forever. None of the other code will ever have a chance to run and you'll no be able to stop the VI programmatically.

I would suggest a state machine architecture with a single loop containing a single event structure. Your "Door Closure" call occurs in three different places, however properly designed, you need only one instance.

Your state machine might have e.g. the following states:

  1. Calibration
  2. Door unlocked, door opening
  3. Door unlucke, door closing
  4. etc...

Check the example finder in LabVIEW for "state machine" for some ideas. Good luck!

Message 5 of 9
(3,432 Views)

Hi ,

First I want to convey my sincere thanks for your suggestions regarding my code.

Here are my explainations regarding my code.

1. The first while loop in sequence0 is to check continuously whether the door is closed or not.

    O/P from this subVI is a cluster of Boolean, Error code, and LabVIEW Error string.

    These Boolean and Error codes are user defined.             Boolean == TRUE    -->  success (here Door Closed)

                                                                                                                ==FALSE   --> failure  (Door opened)

   This boolean controls the while loop.  If door is closed, --> then only while loop terminates and execution proceeds further.

   I can delete this while loop. that is not a problem.

   In my actual code, there are two more other sequences are present in between these two sequences. Only to indicate that some process is happening, I've included this initial sequence.

2. The outer most While loop is to make the sequences to be executed continuously once if the door is opened and then it is   closed. Ik user clicks "Close" or "Panel close", execution terminates. If user clicks "Main Menu", execution flow will be transferred to the other window.  If user does not click any button or if he does not open and close the Door, execution continuously waits for the button events and the door open and close event.

 

My actual application consists of multiple UIs. From first UI, execution transfers to this window when I click some button.

Once the flow comes to this window, above all the steps will be executed continuously.

Till now I haven't used any of the state machine sequences. As i'm a beginner to this, I'm trying a lot to meet the project requirements and deadlines. I'm unable to redesign newly because I've to modify the code which is already existing.

As you've suggested, I'll start using the state machine sequences by finding some examples.

 

Again with sincere Thanks and Regards,

Krishna.

 

 

 

0 Kudos
Message 6 of 9
(3,418 Views)

Hi,

We've checked our code on the real hardware. All the sequences are working fine. But we got one problem.

As long as the door is closed and if any of the buttons are pressed, corresponding action is taking place. But the problem is that once we open the door, without clicking any button, buttons are getting triggered.

For eg., without clicking the close button, a dialog box is appearing which should only pop up when the close button event happens. According to my understading, button triggers for one case(door close)is being stored and when the control flows to other case(door open), these stored event triggers are getting executing without user intervention.

how can I clear all these event values  at the end of each case so that in the new case, events gets triggered freshly? Can I use the controls like CtrlRef, OldVal,NewVal,Source etc. which are available at the left side of the event structure for this purpose?

Any suggestions regarding these queries?

 

With sincere Regards and Thanks in advance,

Krishna.

0 Kudos
Message 7 of 9
(3,405 Views)

Hi,

As you 've suggested, this code was made unneccessarily so complex. Now I've completely changed it. Instead of using two event structures in two seperate cases, now I'm using the case structure inside each of the event. I'm reading the status of the other buttons in each sequence to control the while loops in each event case.

Now I want to read the status of Panel Close? event . I have to incude the status of Panel Close? event to control the while loops in all the event cases inside the event structure.

Please suggest me how to read the status of the Panel Close? event every time I click the panel close button on the Front Panel.

I want to read the Panel Close? inside the other event cases. I am attaching my code with this.

With sincere Thanks and regards,

Krishna.

 

 

0 Kudos
Message 8 of 9
(3,389 Views)

I think you are still misunderstanding events. An event case is only supposed to execute once when the event occurs.

You have the exact same code in all 3 cases, and you have a loop inside each case checking for the same things the event structure is checking. I made a quick modification just to show you what it should basically look like - If no registered event happened, the timeout event runs. If any other event happens, its code is executed. You really should read the help for the event structure and look at the examples before attempting to work with such features.

Regarding the Panel Close? event, it has nothing to do with your close button, but is triggered when you click the X button in the window title, as is stated quite clearly in the help.

To learn more about LabVIEW, I suggest you try searching this site and google for LabVIEW tutorials. Here and here are a couple you can start with. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide and the LabVIEW user manual (Help>>Search the LabVIEW Bookshelf).


___________________
Try to take over the world!
0 Kudos
Message 9 of 9
(3,359 Views)