LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Suspend and restart a While loop

Solved!
Go to solution

Hello all,

 

after some lurking this is my first post here.

 

I need to write a simple VI with three buttons on FP: "Send", "Don't Send" and "Stop".

 

"Stop" termintes execution. "Send" starts sending a single CAN frame on NI CAN USB every 5 seconds. "Don't Send" suspends CAN communication without terminating the VI.

 

I am not able to find a way to "suspend" the CAN loop and then to make it run again, I tried to use queues and event structure but I can't find the solution to this problem.

 

I browsed the net but without luck, e.g. this example is not suitable because "stop" doesn't work when "pause" is true.

 

Can someone of you please give me some suggestion / link?

 

I'm running LabView 2011 on Windows7 PC.

 

Thank you,

Andrea

0 Kudos
Message 1 of 12
(4,647 Views)

What do you have so far? It may make a difference on how you solve the problem. I would use an event structure and a state machine system to get where you need to go. If you look in the examples you can see examples of both of these ideas.

Tim
GHSP
Message 2 of 12
(4,644 Views)

Ciao Tim,

 

thank you for your quick answer.

 

I attach a "canvas" VI, for sure it doesn't work because I don't know the solution of my problem.

 

Please consider that even though I've been using LV for years I never had training apart myself, so feel free to correct me also in "stupid" errors.

 

Andrea

0 Kudos
Message 3 of 12
(4,641 Views)

First thing that I see is that you have a while loop inside of a while loop. This is bad practice. You need to remove this while loop and use a state machine to control exicution.

 

Example.png

You need to look into a state Machine for this loop. The rest of what you are doing seems to make since.

 

Tim
GHSP
Message 4 of 12
(4,629 Views)

I think I would try something like this with what you have already done.

 

Example.png

 

The queue is sent and processed but sending it to the shift register allows the bottom loop to remember the last command sent. Then it will keep that until the command changes. Try this code.

 

Do you know how to use a snippet?

Tim
GHSP
Message 5 of 12
(4,628 Views)

That Dequeue node would need a timeout on it (5 seconds I would guess, if you want to resend the data every 5 secs)

_____________________________
- Cheers, Ed
0 Kudos
Message 6 of 12
(4,621 Views)

I didn't know how to use snippets but this link  helped me 🙂

 

I tried the code you suggested, I wired an indicator expecting to see it incrementing when "send" is selected and see it still when "stop" is selected but it is not happening

 

Here it is the code:

 

original.png

0 Kudos
Message 7 of 12
(4,612 Views)

@yenknip wrote:

That Dequeue node would need a timeout on it (5 seconds I would guess, if you want to resend the data every 5 secs)



Wire the dequeue timeout terminal.

Also, I would suggest setting the boolean controls to latching rather than switching.

_____________________________
- Cheers, Ed
0 Kudos
Message 8 of 12
(4,599 Views)
Solution
Accepted by topic author AndreaAngeloni

Thank you Ed, it is now working as I'm expecting.

 

This is the code:

 

original.png

 

Do you think it is a good solution or there is some "clearer" or somehow better solution to do it?

 

Once more, thanks a lot to both of you

 

Andrea

 

0 Kudos
Message 9 of 12
(4,593 Views)

@AndreaAngeloni wrote:

I didn't know how to use snippets but this link  helped me 🙂

 

I tried the code you suggested, I wired an indicator expecting to see it incrementing when "send" is selected and see it still when "stop" is selected but it is not happening

 

Here it is the code:

 

original.png


It looks like to me that the events in the event structure are messed up. If you fix thoes it should work.

Tim
GHSP
0 Kudos
Message 10 of 12
(4,591 Views)