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: 

Event structure not executing

Solved!
Go to solution

Hello, 

 

I have a linear stage that I am controlling with an open loop system using a stepper motor.  I want to run some tests to measure how far and how consistently the motor can move the stage.  The way my software works is that I give the motor a position (number of steps), then it runs until it reaches that position.  

 

The motor homes itself, and then I want to implement an event structure so that I can give different commands without having to rerun the program each time.  The three cases I would like to implement are: 
1) Giving the motor a new position to run to

2) Telling the motor to home itself again

3) Stopping the program at any time

 

I have watched tutorials on the event structure, and can't for the life of me figure out why it won't work.  The motor runs, homes itself, enters the while loop, and just stays there.  When I change the values, nothing happens.  Can anyone help me figure this out? 

Download All
0 Kudos
Message 1 of 15
(4,375 Views)

Is highlight execution on the whole time?  Turn it on, then run the VI.  I'm saying this because it is possible it never finishes the Home subVI and never enters the while loop.  If it does keep highlight execution on and change the value of the Position control, see what happens.

 

What you are describing just can't be happening.  The event structure works as you expect.  When the Position value changes then the case is entered.  If it is in a case and you change the value again, depending on the settings it will either pile up events like a queue, or will not allow more UI events to be queued up.

0 Kudos
Message 2 of 15
(4,367 Views)

You need to show us your code (incl. subVIs). We cannot debug pictures.

 

  • What's up with the flat sequence structure. serves no purpose.
  • How do you know the the loop inside the event structure ever completes?
  • It is typically better to do lenghty things (e.g. the inner while loop) outside the event structure in a parallel loop. Look at consumer/producer patterns and queues.
0 Kudos
Message 3 of 15
(4,337 Views)

Thank you for the replies. 

 

I have kept the highlight execution on the whole time, and it shows that home completes and the while loop is entered.  When I change the position, nothing happens; the event structure is never entered, for any of the cases I try.  I am as baffled as you are. 

 

I've included my code, and all the relevant subVIs should be there.  The piece of code I am having trouble with is testDistances.vi.  

 

altenbach: 

  • The flat sequence is laid out like that when a new myRIO project is opened.  I just left it there. 
  • I haven't even reached the loop inside the event structure.  If I were to reach it, the motor would be running, and it would exit once the motor has reached the desired position (input to the Position control).  My "Run" subVI returns false when the desired position is reached. 
  • Thank you for this piece of advice.  I did read that this is a standard practice, but I really just wanted to get the event structure to work and got caught up in that before changing it.

This wouldn't have to do with the fact that I'm running my software on a myRIO, and not my PC, would it? 

 

Thanks again, 

E

0 Kudos
Message 4 of 15
(4,270 Views)
Solution
Accepted by topic author Riche29

@Riche29 wrote:

Thank you for the replies. 

 

 

This wouldn't have to do with the fact that I'm running my software on a myRIO, and not my PC, would it? 


Yes, yes it would.

 

The myRIO is an embedded device and has no video output, and therefore doesn't have a concept of events based on user input.  I've never used a myRIO but I assumed it wouldn't even allow you to put the code on the myRIO if an event structure was being used, but I guess you can have user events so maybe that is why no error was thrown.

 

The code runs as expect on Windows where I tested it.  I had to disable parts of the Home, and Run routine because I don't have the myDAQ or myRIO software installed but the event structure worked as expected.

 

Also for the Position Value change the control should be in the event structure, not just in the while loop.  If it isn't then you'll be reading the last value not the new one.  You were probably just making changes to test things because in the images you posted it was in the event structure.

 

 

0 Kudos
Message 5 of 15
(4,263 Views)

Hooovahh wrote:

 

The myRIO is an embedded device and has no video output, and therefore doesn't have a concept of events based on user input.  I've never used a myRIO but I assumed it wouldn't even allow you to put the code on the myRIO if an event structure was being used, but I guess you can have user events so maybe that is why no error was thrown.


Actually LabVIEW RT will allow you to use the Event Structure.  But since there is no actual front panel, events coming from the UI just won't happen.  I'll have to test it, but I'm pretty sure User Events will work.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 15
(4,255 Views)

Okay, this is good to know.  So is it the case that I can't input new values into the front panel during run time and have them interact with the program?  It only uses the values I give it before I press run?  

 

Emma

0 Kudos
Message 7 of 15
(4,248 Views)

If you are running through the LabVIEW IDE, then you can still change the values.  It just won't generate the event.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 15
(4,241 Views)

Does this mean I would need to nix the event structure and poll for new data? 

 

0 Kudos
Message 9 of 15
(4,228 Views)

Yep


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 15
(4,212 Views)