LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling the 2 while loop and one queue

Solved!
Go to solution

Hello sir

i need to handel the while loopps as they run in sequence. i can use sequence structure but issue is in my program i also have one already queue . please help me how can i handel this issue

thanks12.png

0 Kudos
Message 1 of 10
(4,901 Views)

You're listing off three loops but also three runs, so which is it? Do you have three parallel loops, or are you trying to handle three difference cases based on a single while loop iterating 3 times? It sounds like you have way too many loops when not necessary... 

Are you trying to start and end each loop in order? Then just create a data dependency from one loop to the next and they will operate that way. But that's not a good practice no matter what you're trying to do.

 

You should give us more information about what you're trying to do in the end for us to better help you with the best solution, not just the solution you think you want.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 10
(4,887 Views)

@IrfanRazzaq wrote:

Hello sir

i need to handel the while loopps as they run in sequence. i can use sequence structure but issue is in my program i also have one already queue . please help me how can i handel this issue

thanks12.png


You're using a queue and yet you don't know how to do this?  This is a recipe for disaster.  Please learn the LabVIEW basics before continuing!

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 10
(4,873 Views)

dear i know how to use the Queue . i think you could not got my point i need the Queue Part execute More then 2 time but the remainig part just once. if i use all in one queue then each part will run once

0 Kudos
Message 4 of 10
(4,830 Views)

Dear james thanks for your reply,

im working on cognitive radio networks in first loop my code search free Band

in 2nd loop it select the available band

third is queue in which it get the data from computer change it into packet, modulate the data using QAM then transmit it

i need the queue part to run more then 2 time to transmit complete data 

i need this work in sequence as>>>>  sensing >>channel Selection>> Transmission(but in sequence transmission part run for more time then the remaning)

Hope now you will got my point

 

 

0 Kudos
Message 5 of 10
(4,820 Views)

@IrfanRazzaq wrote:

i need this work in sequence as>>>>  sensing >>channel Selection>> Transmission(but in sequence transmission part run for more time then the remaning)

Hope now you will got my point


Sounds more like a State Machine is needed, not multiple loops.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 10
(4,809 Views)
Solution
Accepted by topic author IrfanRazzaq

You definitely want a State Machine. You can't do what you want using a sequence structure, as you've said. So you need an architecture that can operate multiple different cases in some order, but also repeat states when necessary.

 

The Simple State Machine template that ships with LabVIEW is really the best way for new developers to get familiar with LabVIEW while utilizing a semi-scalable architecture.

Here's a broad example of how a state machine works:

  • States: Init, Idle, Exit, DoThing1, DoThing2, DoThing3
  • Each state contains code that might take some time. Ideally, not too long because that's how long your code could be unresponsive.
  • The Idle state contains an event structure for all user interaction.
  • The front panel has a button that says "Do Thing 1".
  1. Loop Iteration 0: Application begins, first state is Init. The Init state does some initialization stuff and tells the application to go to the Idle state when finished.
  2. Loop Iteration 1: Application goes to Idle state. It sits there, waiting at the event structure.
  3. Time goes by, then user presses button "Do Thing 1". There is no code, or minimal code, within this event case. The output of this event state tells the application to go to the DoThing1 state.
  4. Loop Iteration 3: Application goes to DoThing1 state. There is code here that does some stuff. The output of DoThing1 state tells the application to go back to the Idle state.
  5. Loop Iteration 4: Application goes to Idle state where it waits at the event structure again.
  • Each of the states can tell the application to go to any state they want. Want to reinitialize? Go to the Init state again. Want to end the program? Go to the Exit state. Want each state to trigger another (like a sequence)? Have DoThing1 output DoThing2, which outputs DoThing3,  which outputs Idle.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 7 of 10
(4,785 Views)

Hello Sir,

Hope you are fine!

i create state machine, now i need to stop the loops. for this purpose i use the elapsed time it work correctly for the first time but for second time it start malfunctioning .  code is atteched. please help me to correct this problum.

Download All
0 Kudos
Message 8 of 10
(4,683 Views)

Hello IrfanRazzaq,

Is the malfunction that the VI is stopping early the second time you run it? If so, it's likely because the boolean you have wired to the larger while loop's stop terminal is being set "true" but not reset to "false" after you run the VI. Try running it once, then after stopping click on the boolean again before running the VI a second time. If this fixes your problem, then you should right click on that boolean and select "Mechanical Action" and one of the latching options (the second row of mechanical actions). Alternatively, you could replace that boolean with a Stop Button for the same effect.

While that may fix the malfunction you are seeing, the way you have it set up may not be ideal as a way to stop your state machine. In your code the boolean is only read once after each inner loop (or state) completes execution, which is likely not your intention. I would suggest you spend some time looking at the Project Template suggested by James or the State Machine example that ships with LabVIEW and seeing how they stop execution of a state machine. The State Machine Example can be found by found by opening LabVIEW and selecting "Help" -> "Find Examples..." and then selecting the "State Machine Fundamentals.vi" option from under the "Fundamentals" -> "Loops and Structures" folders.

If the boolean is not the issue, could you provide more information about what malfunction you are seeing in your code?


Charlie J.
National Instruments
Message 9 of 10
(4,623 Views)

Irfan, try what GatorBait suggested to solve your specific issue.

 

That being said your "state machine" that you attached isn't set up correctly. You just have everything in the timeout case with a timeout of 1ms and no other event cases. The traditional event based state machine (like the template shipped with LabVIEW) has the case structure outside the event structure, so you end up with: Event Structure inside of a Case Structure inside of a While Loop. The state machine should return to a case called "Idle" or "Wait for Event" or similar to handle the event structure. This Idle case handles if the user presses the Stop button and sends a True value to the stop terminal, or goes to an "Exit" case, etc.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 10 of 10
(4,618 Views)