04-20-2012 07:22 AM
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
Solved! Go to Solution.
04-20-2012 07:25 AM
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.
04-20-2012 07:44 AM - edited 04-20-2012 07:45 AM
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
04-20-2012 08:04 AM
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.
You need to look into a state Machine for this loop. The rest of what you are doing seems to make since.
04-20-2012 08:12 AM
I think I would try something like this with what you have already done.
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?
04-20-2012 08:31 AM
That Dequeue node would need a timeout on it (5 seconds I would guess, if you want to resend the data every 5 secs)
04-20-2012 08:42 AM
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:
04-20-2012 09:00 AM
@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.
04-20-2012 09:06 AM
Thank you Ed, it is now working as I'm expecting.
This is the code:
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
04-20-2012 09:06 AM
@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:
It looks like to me that the events in the event structure are messed up. If you fix thoes it should work.