02-15-2019 10:16 AM
Hi guys,
I made a small program that display numerics in every case structure . I just want the program to display the numerics from the first structure if i clicked stop and they run the program again.
I appreciate all your help.
Thanks
02-15-2019 10:22 AM
The case executed by a case structure is whatever is wired to the input selector. In your attached code, case 1 will run every time since it's wired outside the shift register. Is that not what you want?
I would recommend *not* using the Stop and Run buttons to control program flow long-term. It's fine for some early debugging, but in general you don't want the users hitting those buttons. Consider how to make your program stop "gracefully" from a button on the front panel.
02-16-2019 01:04 PM
I think I see your problem -- your code does, in fact, start from the beginning, with the first changed value in Numeric being Case 1, namely "9". What you may be "forgetting" is a question of timing, or "ordering".
You have an Event Loop with a TimeOut in it. which means "Wait until you execute". Well, if you don't press Stop, it first Waits, then it changes Numeric from whatever it was to whatever you want it to be! Is there a Fix? You betcha! Does it involve a Shift Register? Again, you betcha. Does this involve some rethinking? [You fill in the answer ...].
Suppose you have your number-to-be-displayed on a Shift Register, and your Loop puts the Number on this Shift Register. Recall that the Event Structure puts stuff on the Shift Register after the TimeOut expires. Question -- suppose you put two indicators on the Shift Register, one before the Wire enters the Event Structure, and one when the Wire exits the Event Structure -- which Indicators do you label "Current", and which one "Next"?
So all you now need to add is a rethinking of your Event Logic to realize "The Last Shall be First" and to initialize the Numeric Shift Register with this First value.
Bob Schor
02-18-2019 03:36 AM
@Bob_Schor wrote:
I think I see your problem -- your code does, in fact, start from the beginning, with the first changed value in Numeric being Case 1, namely "9". What you may be "forgetting" is a question of timing, or "ordering".
You have an Event Loop with a TimeOut in it. which means "Wait until you execute". Well, if you don't press Stop, it first Waits, then it changes Numeric from whatever it was to whatever you want it to be! Is there a Fix? You betcha! Does it involve a Shift Register? Again, you betcha. Does this involve some rethinking? [You fill in the answer ...].
Suppose you have your number-to-be-displayed on a Shift Register, and your Loop puts the Number on this Shift Register. Recall that the Event Structure puts stuff on the Shift Register after the TimeOut expires. Question -- suppose you put two indicators on the Shift Register, one before the Wire enters the Event Structure, and one when the Wire exits the Event Structure -- which Indicators do you label "Current", and which one "Next"?
So all you now need to add is a rethinking of your Event Logic to realize "The Last Shall be First" and to initialize the Numeric Shift Register with this First value.
Bob Schor
Thanks a lot BertMcMahan and Bob Schor.
I exactly want to do what you wrote. I tried many proposed solutions but they did not work.
I appreciate it very much if you could elaporate more?
02-18-2019 09:08 AM - edited 02-18-2019 09:09 AM
Hi guys, i made a simple program (switching between different valves) but when i run the program, it takes long time(switching time as indicated in the picture) to run the program. I appreciate a lot your help to solve this problem
Thanks.
02-18-2019 09:10 AM
I hope you are trying to learn LabVIEW "on your own", without the benefit of an instructor or guidance (because there are several "wrong-headed" concepts and "the hard way of doing things" in your code).
Here are some thoughts/facts/suggestions that you might consider in doing what you seem to want to do with this routine.
As I noted just above, I build a little Demo from my re-write of your routine. My code uses a While Loop, a Case Statement (I would have used an Array of Numerics, as I suggested at the beginning, but I noted you may have had other "decisions" or "processing" to do inside each case, so I left the Case Statement intact). I used two Shift Registers, a Wait (ms) function, and an Increment function. I was going to attach an Executable so you could see if it fulfilled your requirements, but you are using LabVIEW 2014, and my code was built in LabVIEW 2016, which probably has a different Run Time Engine.
Anyway, you are learning LabVIEW, and the best (only?) way to learn Programming is to Write Programs. Give it a go, seeing if you can follow/understand the points I'm trying to make, above.
Bob Schor
02-18-2019 09:22 AM - edited 02-18-2019 09:26 AM
Hi Ahmed,
the "Timeout" event is executed once your "swsitching time" has elapsed.
Atleast that's how you created your VI.
When you need something else you need to adapt your VI to your requirements! (Don't rely on a TimeOut event when you code should execute earlier…)
Note: I merged your message #5 into this thread as you basically have the same problem as in your first message…