LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Single event inside a while loop?

Just starting out in LabView and I need to find a way to have a while loop and a single event work in harmony. Here's what I have.

Capture.JPG

0 Kudos
Message 1 of 21
(3,700 Views)

Hi R,

 

a way to have a while loop and a single event work in harmony. Here's what I have.

And what exactly is your problem?

Which errors do you encounter?

 

- What should we do with an image? Attach your VI!

- Where is the event? I don't see any event structure…

- Why do you AND a FALSE with another FALSE?

- Why are there so many coercion dots?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 21
(3,697 Views)

Ok, to start with there aren't any errors. My problem or task is to send SPI commands to an Arduino Uno. I want to send a list of commands and stop, send the same commands and loop or just send the top command. All without having to restart the program. I'm a newbie at this so I may have to rething the entire structure.

 

I don't know what a coercion dot is.

 

Thanks

Hutch

0 Kudos
Message 3 of 21
(3,686 Views)

You may want to look into a simple state machine architecture.  It would let you have an "initialize" state, a "shutdown" state and a "run" state.  You could then just change states if you wanted to start / stop, whatever.

 

As for the coercion dot, here is some reading

0 Kudos
Message 4 of 21
(3,674 Views)

Look at the design patterns in the File -> New...  dialog box.  These will give you a good starting point for what you want to do. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 21
(3,662 Views)

I managed to get it working just by changing the switch action to Latch when released. The description didn't make sense to me but the diagram showed a pulse and that's what I needed for my one shot command. I also cleared all the coercion dots, thank you, and got rid of the outer case. I don't know how to insert a VI.Capture.JPG

0 Kudos
Message 6 of 21
(3,631 Views)

@RHutchings wrote:

I managed to get it working just by changing the switch action to Latch when released. 


 

While it might be working the way you want... the code you displayed is, to be blunt, not very good.  I strongly recommend you try to redo it with proper architecture and follow the suggestions you were given in this thread. You will have a better program in the end, and will learn a lot in the process.  This is a simple enough application it shouldn't take long.

 

What you have done here is something called "programming by coincidence".  It works, you don't really understand why, but who cares right?  It works!  This is a very bad habit to get into and will cause you many, many headaches in the future.

 

 People in this forum will be happy to help you rearchitect as long as you give it an attempt first.  Try it. Show us what you've got and let us review your code and provide suggestions.  The more you show you are willing to try and learn the more help you are likely to get 🙂

0 Kudos
Message 7 of 21
(3,621 Views)

What is the advantage of having two buttons with this code (if I understand your code correctly).  I assume you want the buttons to control the number of times that the loop executes but your logic doesn't make sense.  If either of the buttons are pressed, the code still has to look at the number of commands.  

  • You could push the loop button with a value of 1 in the "number of commands" and only execute the loop once
  • You could also push the single button with a number greater than 1 in the "number of commands" and run the loop more than a single time.  
aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 8 of 21
(3,617 Views)

@aputman wrote:

What is the advantage of having two buttons with this code (if I understand your code correctly).  


I would assume Loop is a switcher and Single is a latcherSmiley Wink number of commands could likely be handled with autoindexing (had to tell without data)


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 21
(3,607 Views)

If I "push the loop button with a value of 1 in the "number of commands" and only execute the loop once" , that button stays in that position causing it to repeat inside the outer while loop until it's pressed again.

 

"You could also push the single button with a number greater than 1 in the "number of commands" and run the loop more than a single time.  " I don't want the iterations to be based on the length of time holding the button down.

0 Kudos
Message 10 of 21
(3,597 Views)