LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to force case stucture to start from the first case after pressing stop and run again

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.v.png

 

I appreciate all your help.

 

Thanks

 

0 Kudos
Message 1 of 7
(2,570 Views)

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.

0 Kudos
Message 2 of 7
(2,565 Views)

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

Message 3 of 7
(2,516 Views)

@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?

 

 

0 Kudos
Message 4 of 7
(2,502 Views)

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.

VI.png

 

0 Kudos
Message 5 of 7
(2,491 Views)

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.

  • Event Structures are very good for timely responses to Front Panel "Events".  They are less-well-suited to timing -- the functions on the Timing Palette (such as "Wait (ms)") are often better-suited for Timing.
  • Running through an array of numeric values over and over suggests a data structure consisting of ... an Array of Numerics (Dbls in your case).
  • A While Loop contains an Index variable.  The Quotient/Remainder function allows you to turn a sequential series (0, 1, 2, ...) into a cyclic series (0, 1, 2, 0, 1, 2, 0, 1, ...)
  • If you have an Array (of numbers) and an Array Index, you can "extract" the corresponding Array Value.
  • Wiring a Stop Button to a While Loop Stop Indicator will Stop the loop.
  • The presence of a Wait and a Stop Button in the same Loop might produce "unexpected" results.  Do some experiments with, say, a 5-second Wait and a Stop Button, with an indicator wired to the While Loop Index, and be able to explain what you see.  What happens if you start the loop with the Stop Button pressed?
  • The simple example I'm describing here does not need an Enum (it turns the While Index into a cyclic index).  Your Enum code uses a Case Statement to increment the Enum cyclicly.  Do you know about the Increment function on the Numeric Palette?  See what it does to an Enum (simpler is usually better).
  • I discovered an Error in your Enum -- you appear to have a seventh (undefined) value (I didn't discover this until I tried to run the little Demo routine I made from your code ...).

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

 

0 Kudos
Message 6 of 7
(2,478 Views)

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…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 7
(2,477 Views)